[Bash] cp command

cp

Copy file content from beep.txt to message.txt, create message.txt if not exists.

cp beep.txt message.txt

Copy file to a different directory

cp beep.txt ../

# the same as
cp beep.txt ../beep.txt

cp (multiple files)

You can copy multi files at once to a new places:

mkdir cool
cp beep.txt boop.txt cool

cp command checks that if the last arguement is a directoy, then it will copy multi files into that directory.

cp -r

If you have a directory full of files and directoires you want to copy to a new place, you can use cp -r to recursively copy a directory and all its subdirectories to a new location:

# copy all content source directoy to target directory
cp -r source target

Likewise, there is a -R for the ls command that recursively lists subdirectories:

ls -R newsyz

newxyz:
123  a.txt  b.txt

newxyz/123:
a.txt
posted @ 2024-05-14 02:56  Zhentiw  阅读(3)  评论(0编辑  收藏  举报