Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of emptying files in a directory by linux

Shulou Source: shulou.com Published: 2022-06-02 00:36:05 09月22日 Update

How does linux empty the files in a directory? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

Linux: 1. Use the "rm-f *" command to delete all files in the current directory. 2. Use the find command to find and delete ordinary files. 3. Delete all ordinary files through the "rm-f `find.-type f`" command. 4. Delete files with for loop statement.

10 methods of deleting files in directory by Linux

After reading the article, I suddenly remembered the method of deleting all the files in the directory in Linux, and sorted out a few, if there are any deficiencies, I hope readers will not hesitate to comment!

Delete files in the current directory

1.rm-f *

# the classic method is to delete all types of files in the current directory

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

# find a normal file and delete it with the find command and delete it with the processing action of the find command or

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

# too long parameter list; too many files to delete

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

# Delete all ordinary files

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

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

Delete files in the specified directory

1.rm-f specifies the directory *

# the most classic way to delete all types of files in the specified directory

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

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

3.find specifies the directory-type f | xargs rm-f

# too long parameter list; too many files to delete

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

# Delete all ordinary files in the specified directory

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

# use for loop statement to delete all types of files in the specified directory

Thank you for reading! After reading the above, do you have a general idea of linux's method of emptying files in a directory? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Tags: Files directories methods ordinary commands content types articles statements loops actions parameters classics problems processing teaching whims instructions more see Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Apple Shulou Tech Info Xiaomi