Linux files and folders copy, move and delete
File copy
cp test.log aaa
Copy test.log in the current directory to the aaa folder in
cp test.log ../bbb
the current directory (relative path) Copy test.log in the current directory to the bbb folder in the upper directory (relative path)
cp test.log /usr/aaa
to the current directory Copy the test.log to the aaa folder under usr (absolute path)
Folder copy
cp dd aaa
Copy the dd folder in the current directory to the aaa folder in
cp dd ../bbb
the current directory (relative path) Copy the dd folder in the current directory to the bbb folder in the upper directory (relative path)
cp dd /usr/aaa
to the current directory Copy the dd folder to the aaa folder under usr (absolute path)
File copy and rename
cp test.log aaa/a.txt
Copy test.log in the current directory to the aaa folder in the current directory and rename it to a.txt (relative path)
cp test.log ../bbb/a.txt
Copy test.log in the current directory to the bbb folder in the upper level directory and rename it to a .txt (relative path)
cp test.log /usr/ccc/a.txt
copy test.log in the current directory to the ccc folder under usr in the root directory and rename it to a.txt (absolute path)
Folder copy and rename
cp dd aaa/ff
Copy the dd folder in the current directory to the aaa folder in the current directory and rename it to ff (relative path)
cp dd ../bbb/ff
Copy the dd folder in the current directory to the bbb folder in the upper level directory and rename it to ff (relative path) Path)
cp dd /usr/ccc/ff
Copy the dd folder in the current directory to the ccc folder under usr in the root directory and rename it to ff (absolute path)
File move
mv test.log aa
Move test.log in the current directory to the aa folder in
mv test.log ../bb
the current directory (relative path) Move test.log in the current directory to the bb folder in the upper directory (relative path)
mv test.log /usr/aa
to the current directory Move the test.log to the absolute path /usr/aa (absolute path)
Folder move
mv cc aa
Move the cc folder in the current directory to the aa folder in
mv cc ../bb
the current directory (relative path) Move the cc folder in the current directory to the bb folder in the upper directory (relative path)
mv cc /usr/aa
to the current directory Move the cc folder to the absolute path /usr/aa (absolute path)
File move and rename
mv test.log aa/test1.log
Move test.log in the current directory to the aa folder in the current directory and rename it to test1.log (relative path)
mv test.log ../bb/test1.log
Move test.log in the current directory to the bb folder in the upper directory and rename it is test1.log (relative path)
mv test.log /usr/aa/test1.log
to move and rename test.log the absolute path of the current directory / usr / aa is below test1.log (absolute path)
Folder move and rename
mv cc aa/dd
Move the cc folder in the current directory to the aa folder in the current directory and rename it to dd (relative path)
mv cc ../bb/dd
Move the cc folder in the current directory to the bb folder in the upper directory and rename it to dd (Relative path)
mv cc /usr/aa/dd
Move the cc folder in the current directory to the absolute path /usr/aa and rename it to dd (absolute path)
File deletion
rm test.log
To delete a file, there will be a question "rm: remove regular file'test.log'?", type y and press enter to delete n press enter and do not delete
rm -f test.log
.
Folder deletion
rm -r aa
Delete the files in the directory and below one by one. You will be asked if you want to delete the folder, enter y and press Enter to delete n and press Enter to not delete (rm aa this way of deleting will report an error "cannot remove aa: is a directory") to
rm -rf aa
force the directory and the following files to be deleted one by one (don’t ask)