The copy command works similar to the move command, the word copy is shortened down to 2 letters cp and then we type in the source and the destination

cp errorfile.txt Newdirectory

To copy to the same directory you would type cp the filename then the copy-filename

cp errorfile.txt errorfile-copy.txt

We can add options -f for force (overwrite if file exists), -n for no-clobber (Do not overwrite file if it exits), -v for verbose, and -i for interactive (Ask before overwriting the file) to the copy command

cp -vi errorfile.txt Newdirectory

We add some files to the Newdirectory2 directory with the command:
Touch Newdirectory/Newdirectory2/file{a,b,c}.txt

This will create three files filea.txt, fileb.txt, and filec.txt

When copying a directory, we must use the -r option to recursively copy everything in that directory
cp -r Newdirectory/Newdirectory2/ .

If you use the -i for interactive when copying a directory, it will ask to confirm copy file for every file in that directory (control+c with cancel you out of that)

Using the -u option will only copy files that have been updated


Xem thêm bài viết khác:

Leave a Reply