Linux -- directory basic operation

cp copy files or directories Usage: cp [OPTION] SOURCE source file DIRECTORY target file. For details, see man cp Take common parameters for example [...

cp copy files or directories

Usage: cp [OPTION] SOURCE source file DIRECTORY target file. For details, see man cp

Take common parameters for example

[root@hs-192-168-33-206 tom]# ll --full-time //Total dosage 24 -rwxr-xr-x 1 root root 0 2019-02-11 16:45:14.784189569 +0800 atext01 -rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 Beauty drwxr-xr-x 5 root root 4096 2019-02-12 20:16:38.924928332 +0800 demo -rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 Hare -rwxr-xr-x 1 tom home 118 2019-02-11 10:37:10.169390846 +0800 html -rwxr-xr-x 1 tom home 136 2019-02-11 10:39:36.761673506 +0800 lesson

1. Simply copy the Beauty file

[root@hs-192-168-33-206 tom]# cp Beauty Beauty-20190214 [root@hs-192-168-33-206 tom]# ll --full-time -rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 Beauty -rwxr-xr-x 1 root root 4164 2019-02-14 15:31:35.141561785 +0800 Beauty-20190214

2. Add - A to copy the Beauty file completely, and the - a parameter is equivalent to the combination of - dpr

[root@hs-192-168-33-206 tom]# cp -a Beauty Beautybak [root@hs-192-168-33-206 tom]# ll --full-time //Total dosage 32 -rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 Beauty -rwxr-xr-x 1 tom root 4164 2019-02-11 10:50:32.965743579 +0800 Beautybak

3. Add the - i parameter. There is already a atext01 file in the demo directory. Add the - i parameter. When copying again, you will be asked first and then operated

[root@hs-192-168-33-206 tom]# cp -i atext01 ./demo/ cp: Is it covered?"./demo/atext01"?

4. Add the - p parameter and copy it together with the file attribute

[root@hs-192-168-33-206 tom]# cp -p Hare Hare.bak [root@hs-192-168-33-206 tom]# ll --full-time //Total dosage 28 -rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 Hare -rwxr-xr-x 1 tom home 632 2019-02-11 10:47:48.732248707 +0800 Hare.bak

5. Copy directory and add - r parameter

[root@hs-192-168-33-206 tom]# cp -r demo demobak [root@hs-192-168-33-206 tom]# ll --full-time //Total dosage 32 drwxr-xr-x 5 root root 4096 2019-02-14 15:37:08.866084027 +0800 demo drwxr-xr-x 5 root root 4096 2019-02-14 15:51:24.815033641 +0800 demobak #By comparing the files in the directory before and after copying, it can be found that the file attributes have changed after copying #Under the demo Directory: [root@hs-192-168-33-206 tom]# cd demo [root@hs-192-168-33-206 demo]# ll --full-time //Total dosage 12 -rwxr-xr-x 1 root root 0 2019-02-14 15:40:27.083164877 +0800 atext01 drwxrwxrwx 2 root root 4096 2019-02-12 20:15:15.318993626 +0800 test drwxr-xr-x 3 root root 4096 2019-02-12 20:16:38.924928332 +0800 test1 drwxr-xr-x 2 root root 4096 2019-02-12 20:09:58.473644928 +0800 work #demobak Directory: [root@hs-192-168-33-206 tom]# cd demobak/ [root@hs-192-168-33-206 demobak]# ll --full-time //Total dosage 12 -rwxr-xr-x 1 root root 0 2019-02-14 15:51:24.814033621 +0800 atext01 drwxr-xr-x 2 root root 4096 2019-02-14 15:51:24.815033641 +0800 test drwxr-xr-x 3 root root 4096 2019-02-14 15:51:24.815033641 +0800 test1 drwxr-xr-x 2 root root 4096 2019-02-14 15:51:24.814033621 +0800 work

rm delete file or directory

Usage: rm [OPTION] FILE view man rm

-f: force deletion -r: recursive delete, used to delete directory -i: ask before deleting. It is required by default

1. Delete files

[root@hs-192-168-33-206 tom]# rm lesson01 rm: Delete normal file or not "lesson01"?

2. Delete directory

#Delete the directory. If you don't want to ask, you can use rm -rf file name [root@hs-192-168-33-206 tom]# rm -r demobak/ rm: Enter directory or not"demobak"? y rm: Delete normal empty file "demobak/atext01"?y rm: Delete directory or not "demobak/work"?y rm: Delete directory or not "demobak/test"?y rm: Enter directory or not"demobak/test1"? y rm: Enter directory or not"demobak/test1/test2"? y rm: Delete directory or not "demobak/test1/test2/test3"?y rm: Delete directory or not "demobak/test1/test2"?y rm: Delete directory or not "demobak/test1"?y rm: Delete directory or not "demobak"?y

mv move or rename files / directories

Usage: mv [OPTION] SOURCE DIRECTORY

-f: force deletion -r: recursive delete, used to delete directory -u: if the target file is older than the source file, the target file will be updated

1. Rename file

[root@hs-192-168-33-206 tom]# ll //Total dosage 24 -rwxr-xr-x 1 root root 0 2 Month 1116:45 atext01 [root@hs-192-168-33-206 tom]# mv atext01 atext02 [root@hs-192-168-33-206 tom]# ll //Total dosage 24 -rwxr-xr-x 1 root root 0 2 Month 1116:45 atext02

2. Move folder

[root@hs-192-168-33-206 tom]# mv -f demo ./test/demomv [root@hs-192-168-33-206 test]# ls demomv

3 December 2019, 09:11 | Views: 6400

Add new comment

For adding a comment, please log in
or create account

0 comments