####### Happy weekend! #######
### Search and clear files and folders from the sea. For the column spaces, refer to Haha, ^_^ ###
####### Gold coins are not required, even though they are still poor, \ (^ o ^ )/~ ######
I. Three Methods for clearing files
1 echo ""> test.txt
2> test.txt
3 CAT/dev/null> test.txt
Ii. Linux folder clearing command
Rm-RF directory name.
######## By the way, the usage of CP, RM, and MV commands ##########
CP command
The function of this command is to copy the given file or directory to another file or directory, just like the Copy command in DOS, which is very powerful.
Syntax: CP [Option] source file or directory target file or directory
Note: This Command copies the specified source file to the target file or multiple source files to the target directory.
The options of this command are as follows:
-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of DPR options.
-D: the link is retained during copy.
-F delete an existing target file without prompting.
-I and F options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is Y, the target file will be overwritten, which is an interactive copy.
-P in addition to copying the source file content, CP also copies the modification time and access permissions to the new file.
-If the source file provided by R is a directory file, CP will recursively copy all subdirectories and files in the directory. The target file must be a directory name.
-L do not copy, but only link files.
It should be noted that, in order to prevent users from using the CP command to destroy another file inadvertently, for example, if the target file name specified by the user is an existing file name, after copying the file with the CP command, this file will be overwritten by the newly copied source file. Therefore, we recommend that you use the I option when copying the file using the CP command.
$ CP-I exam1.c/usr/Wang/shiyan1.c
Copy the file exam1.c to the/usr/Wang directory and change it to shiyan1.c. If you do not want to rename a file, run the following command:
$ CP exam1.c/usr/Wang/
$ CP-r/usr/Xu/usr/Liu/copy all the files and Their subdirectories in the/usr/Xu directory to the/usr/Liu directory.
MV mobile command
You can use the MV command to rename a file or directory or move the file from one directory to another. This command is like a combination of Ren and move in DOS.
Syntax: MV [Option] source file or directory target file or directory
Note: depending on the type of the second parameter in the MV command (whether it is the target file or the target directory), the MV command renames the file or moves it to a new directory. When the second parameter type is file, the MV command renames the file. At this time, only one source file (or the source directory name) can be used ), it renames the given source file or directory to the given target file name. When the second parameter is an existing directory name, there may be multiple source files or directory parameters. The MV command moves the source files specified by each parameter to the target directory. When a file is moved across file systems, the MV copies the file first, and then deletes the original file. The link to the file will also be lost.
The meaning of each option in the command is:
-I interactive operation. If the MV operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer Y or N. This will avoid overwrite the file by mistake.
-F prohibit interactive operations. When an MV operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work.
If the target file (not a directory) already exists, the content of the file will be overwritten by the new file. To prevent users from inadvertently using the MV command to destroy another file, we recommend that you use the I option when using the MV command to move the file.
Note that the MV and CP results are different. Mv is like a file "moving". The number of files increases at the end, while CP copies the files, and the number of files increases.
Example 1: Move all the files in/usr/Xu to the current directory (represented:
$ MV/usr/Xu /*.
Example 2: Rename wch.txt as wjz.doc
$ MV wch.txt wjz.doc
Rm command
It is easy to create files in Linux, and files may become obsolete and useless at any time in the system. You can use the RM command to delete it. This command is used to delete one or more files or directories in a directory. It can also delete a directory and all its files and subdirectories. For linked files, only the links are deleted, and the original files remain unchanged.
The common format of the RM command is:
Rm [Option] file...
If the-r option is not used, RM will not delete the directory.
The options of this command are as follows:
-F ignores non-existing files and never gives a prompt.
-R indicates that Rm recursively deletes all directories and subdirectories listed in the parameter.
-I.
Be careful when using the RM command. Because once an object is deleted, it cannot be recovered. For example, when you enter the CP, MV, or other commands, you accidentally mistakenly enter the RM command. It is too late when you press the Enter key and recognize your error, the file does not exist. To prevent this, you can use the I option in the RM command to confirm each file to be deleted. If you enter y, the file will be deleted. If you enter anything else, the file will be retained. In the next example, You need to delete the files test and example. Then, each file is required to be confirmed. The user finally decided to delete the example file and keep the test file.
PS: It's not original. Transfer others' posts and learn together! O (∩) O Haha ~