Delete file and folder directory commands under Linux

  

How do I delete files and folders under Linux? In fact, most users of the Linux system are accustomed to using commands to perform various operations. The command to delete files and folder directories is rm.

Users can delete unwanted files with the rm command. The function of this command is to delete one or more files or directories in a directory. It can also delete a directory and all files and subdirectories under it. For linked files, just the link is broken and the original file remains unchanged.

The general form of the rm command is:

rm [options] File …

If the -r option is not used, rm does not delete the directory.

The options for this command have the following meanings:

- f Ignore files that do not exist and never give a prompt.

- r Instructs rm to recursively delete all directories and subdirectories listed in the parameter.

- i Perform an interactive delete.

Be careful with the rm command. Because once the file is deleted, it cannot be recovered. To prevent this from happening, you can use the i option to confirm the files you want to delete one by one. If the user enters y, the file will be deleted. If you enter anything else, the file will not be deleted.

Be careful when using rm -rf to delete files. Linux does not have a recycle bin.

Direct rm is fine, but add a parameter -f ie: rm -f file path

-f is to forcefully delete, do not make any hints

Delete file usage example:

rm -f /var/log/httpd/access.log

will force the deletion of /var/log/httpd/access.log file

Delete directory use instance:

rm -rf /var/log/httpd/access

will delete the /var/log/httpd/access directory and all files and folders under it

Need to be reminded: Be careful when using this rm -rf, Linux does not have a recycle bin

Of course, rm has more other parameters and usage, man rm Can view




Copyright © Windows knowledge All Rights Reserved