Linux issues with cp: -r not specified; omitting directory
Matthew Martinez
Can someone help me understand what that means?
cp: -r not specified; omitting directoryI am trying to use this command
sudo cp /home/$USER/Documents/myfile.10 /homeError:
cp: -r not specified; omitting directory '/home/administrator/Documents/myfile.10'What does it mean? Why did it happen? What can I do about it?
21 Answer
cp: -r not specified; omitting directory '/home/administrator/Documents/myfile.10'
This means myfile.10 is a directory. cp won't copy it, unless you explicitly use -r (or equivalent) flag.
For cp in my Debian these are equivalent: -r, -R, --recursive. POSIX, however defines -R only (-r is mentioned as obsolescent). It says:
If source_file is of type directory, the following steps shall be taken:
- If the
-Roption was not specified,cpshall write a diagnostic message to standard error, do nothing more with source_file, and go on to any remaining files.[...]
The conclusion is your cp does exactly what it's supposed to do. If you want to copy the whole directory, use -R. If you expected myfile.10 to be a non-directory then you need to investigate why the discrepancy.