Home  >  Article  >  Operation and Maintenance  >  How to clear files in a directory in Linux

How to clear files in a directory in Linux

藏色散人
藏色散人Original
2020-10-26 13:45:3724404browse

Linux method to clear files in a directory: 1. Use the "rm -f *" command to delete all files in the current directory; 2. Use the find command to find ordinary files and delete them; 3. Use "rm- f `find . -type f`" command deletes all ordinary files; 4. Use a for loop statement to delete files.

How to clear files in a directory in Linux

Recommended: "linux tutorial"

Linux delete the directory 10 ways to use files

After reading the article, I suddenly thought of ways to delete all files in a directory in Linux. I have sorted out a few. If there are any deficiencies, I hope readers will give me some advice. !

Delete files in the current directory

1.rm -f *

#The most classic method, delete All types of files in the current directory

2.find . -type f -delete or find . -type f -exec rm -f {} \;

#Use the find command to find ordinary files and delete them or use the processing action of the find command to delete them

3.find . -type f | xargs rm -f

#Use Because the parameter list is too long; there are too many files to be deleted

4.rm-f `find . -type f`

#Delete all ordinary files

5.for delete in `ls -l`;do rm -f * ;done

#Use a for loop statement to delete all types of files in the current directory

Delete files in the specified directory

1.rm -f Specify the directory*

#The most classic method, delete the specified directory All types of files under

2.find the specified directory-type f -delete or find the specified directory-type f -exec rm -f {} \;

#Use the find command to find all ordinary files in the specified directory and delete them or use the processing action of the find command to delete them

3.find specified directory -type f | xargs rm -f

# Used when the parameter list is too long; there are too many files to be deleted

4.rm-f `find specified directory-type f`

# Delete all ordinary files in the specified directory

5.for delete in `ls –l specified directory path`;do rm -f *;done

#Use for Loop statement to delete all types of files in the specified directory

The above is the detailed content of How to clear files in a directory in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn