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
The -u parameter is perfect for synchronizing two directories because it allows 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 allows you to copy directory contents.
Was this article helpful?