In the Linux environment, the command to delete files is rm. Use this command to free up disk space by removing files that are no longer needed from the file system.
The basic syntax of the rm command is:
rm [option] file or directory
Among them, the commonly used options are:
-r, -R: recursively delete directories and their Content;
-f: Forced deletion, no confirmation required;
-i: Interactive deletion, ask for confirmation before deletion;
-v: Display the name of each deleted file.
The following are some commonly used sample code instructions:
Delete a file:
rm file1.txt
The above code will delete the file named "file1 in the current directory .txt" file.
Delete multiple files:
rm file1.txt file2.txt file3.txt
The above code will delete "file1.txt", "file2.txt" and "file3.txt" in the current directory files.
Delete a directory and all its contents:
rm -r dir1
The above code will delete the directory named "dir1" and all its contents in the current directory. When there are subdirectories or files in the directory, you will be asked to confirm whether to delete them. If you want to force the directory to be deleted, you can add the -f option.
Delete all files in the directory (retaining the directory itself):
rm -v dir1/*
The above code will delete all files in the "dir1" directory, retaining the directory itself. The -v option can be used to display the name of each deleted file.
Delete a directory and all its contents (no confirmation required):
rm -rf dir1
The above code will delete the directory named "dir1" and all its contents under the current directory, And no confirmation is required. The -f option is used to force deletion, and the -r option is used to recursively delete subdirectories and files.
Summary:
In Linux systems, use the rm command to delete files and directories. When deleting a file, you only need to specify the file name; when deleting a directory, you need to add the -r option, and choose whether to add -f, -i, -v and other options as needed. When performing a deletion operation, please confirm whether the operation object is correct and ensure that important files have been backed up.
The above is the detailed content of What is the command to delete files in linux. For more information, please follow other related articles on the PHP Chinese website!