Create, copy, cut, rename, clear, and delete folders in linux. rename a folder in linux.
There is the wwwroot directory under the home directory, and the sinozzz directory under the wwwroot directory, that is,/home/wwwroot/sinozzz
I. Create a directory
Create a folder named sinozzz123 in the/home/wwwroot directory.
Mkdir/home/wwwroot/sinozzz123
Ii. Directory Replication
1. Copy files and folders in/home/wwwroot/sinozzz to the home/wwwroot/sinozzz123 directory.
Cp-rf/home/wwwroot/sinozzz/*/home/wwwroot/sinozzz123
2. Copy the folders and files under/home/wwwroot/sinozzz123/abc/to the home/wwwroot/sinozzz123 directory.
Cp-rf/home/wwwroot/sinozzz123/abc/*/home/wwwroot/sinozzz123
3. Copy the/home/wwwroot/sinozzz directory to the/home/wwwroot/sinozzz123 directory, that is, copy sinozzz to the sinozzz123 subdirectory and change it to the/home/wwwroot/sinozzz123/sinozzz
Cp-rf/home/wwwroot/sinozzz/home/wwwroot/sinozzz123
Iii. Directory Cutting
1. Run the mv command to cut the file.
To cut the 1.mp3 file in the/home/wwwroot/sinozzz123/music/directory to the/home/wwwroot/sinozzz123/abc directory, run the following command:
# Mv/home/wwwroot/sinozzz123/music/1.mp3/home/wwwroot/sinozzz123/abc
2. Run the mv command to cut the folder.
Cut the/home/wwwroot/sinozzz123/soft folder to the/home/wwwroot/sinozzz123/abc directory.
# Mv/home/wwwroot/sinozzz123/soft/home/wwwroot/sinozzz123/abc
3. Use the mv command to cut folders and files
Cut the folders and files under/home/wwwroot/sinozzz123/photo/to the/home/wwwroot/sinozzz123/abc directory.
# Mv/home/wwwroot/sinozzz123/photo/*/home/wwwroot/sinozzz123/abc
Iv. Directory rename
In linux, both the mobile file and rename are the same command, mv (meaning move)
Command: target file name of the mv source file
1. Rename/home/wwwroot/sinozzz123/index.htm to/home/wwwroot/sinozzz123/index.html
# Mv/home/wwwroot/sinozzz123/index.htm/home/wwwroot/sinozzz123/index.html
2. Rename the/home/wwwroot/sinozzz123 directory to/home/wwwroot/sinozzz456.
# Mv/home/wwwroot/sinozzz123/home/wwwroot/sinozzz456
V. Directory Deletion
Deleting a directory in linux is very simple. Many people are still used to using rmdir. However, once the directory is not empty, it is deeply worried. Now we can use the rm-rf command.
You can simply use rm, but you need to add two parameters-rf
That is, the rm-rf directory name.
-R is recursive down. No matter how many levels of directories are there, delete them together.
-F means to delete the file directly without any prompts.
1. Delete the File Usage instance:
Rm-f/home/wwwroot/sinozzz456/index.html
The/home/wwwroot/sinozzz456/index.html file will be forcibly deleted.
2. Clear the folder instance:
Rm-rf/home/wwwroot/sinozzz456/abc /*
All files and folders under the/home/wwwroot/sinozzz456/abc directory will be forcibly deleted, and the/home/wwwroot/sinozzz456/abc directory will be kept
3. delete a folder instance:
Rm-rf/home/wwwroot/sinozzz456
The/home/wwwroot/sinozzz456 directory and all files and folders under it will be forcibly deleted.
Note that you must be extremely careful when using this rm-rf. linux has no recycle bin.
Of course, rm has more parameters and usage, and man rm can be viewed.
If you are operating in the/home/wwwroot/directory, you can save the/home/wwwroot/part of each command