You can use the following commands:
[a] rm command - Delete one or more files or directories.
[b] find command - Find and delete all files from a specific directory.
Linux Empty Directory Using the rm Command
Consider the following directory structure:/tmp/To delete all files from /tmp/foo/ directory (i.e. empty /tmp/foo/ directory), enter:
|
|------foo/
|---file1
|---file2
|---file3
$ cd /tmp/foo/
$ rm *
OR
$ rm /tmp/foo/*
Delete All Files Using the Find Command
Consider the following directory structure:/tmp/To delete all files from /tmp/bar/ directory (including all files from subdirectories such as /tmp/bar/dir1), enter:
|
|------bar/
|
|---file1.txt
|---file2.txt
|
|---subdir1/
| |---file1.doc
| |---file2.doc
|
|---subdir2/
|---image1.jpg
|---image2.png
$ cd /tmp/bar/
$ find . -type f -delete
OR
$ find /tmp/bar/ -type f -delete
The above find command will delete all files from /tmp/bar/ directory. It will not delete any sub-directories.
No comments:
Post a Comment