Книга: Fedora™ Unleashed, 2008 edition
Copying Files with cp
Copying Files with cp
Like mv
, which is covered later, cp
is a command that is easily used and mastered. However, two marvelous parameters rarely see much use (which is a shame!) despite their power. These are --parents
and -u
, the first of which copies the full path of the file into the new directory. The second copies only if the source file is newer than the destination.
Using --parents
requires a little explanation, so here is an example. You have a file, /home/paul/desktop/documents/work/notes.txt
, and want to copy it to your /home/paul/backup folder
. You could just do a normal cp
, but that would give you /home/paul/backup/notes.txt
, so how would you know where that came from later? If you use --parents
, the file is copied to /home/paul/backup/desktop/documents/work/notes.txt
.
The -u
parameter is perfect for synchronizing two directories because it enables you to run a command like cp -Ru myfiles myotherfiles
and have cp
recopy only files that have changed. The -R
parameter means recursive and enables you to copy directory contents.
- Printing the Contents of a File with cat
- Changing Directories with cd
- Changing File Access Permissions with chmod
- Copying Files with cp
- Printing Disk Use with du
- Finding Files by Searching with find
- Searches for a String in Input with grep
- Paging Through Output with less
- Creating Links Between Files with ln
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Reading Manual Pages with man
- Making Directories with mkdir
- Moving Files with mv
- Listing Processes with ps
- Deleting Files and Directories with rm
- Printing the Last Lines of a File with tail
- Printing Resource Usage with top
- Printing the Location of a Command with which
- 2. VERBATIM COPYING
- Copying Files
- Copying Files Using tar
- Using mc to Copy Files
- Using scp to Copy Individual Files Between Machines
- Using sftp to Copy Many Files Between Machines
- Files
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Moving Files with mv
- Printing the Location of a Command with which
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces