Created
February 27, 2010 10:15
-
-
Save mjgaylord/316619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/ | |
Linux or UNIX - Find and remove file syntax | |
To remove multiple files such as *.jpg or *.sh with one command find, use | |
find . -name "FILE-TO-FIND"-exec rm -rf {} \; | |
OR | |
find . -type f -name "FILE-TO-FIND" -exec rm -f {} \; | |
The only difference between above two syntax is that first command can remove directories as well where second command only removes files. | |
More Examples of find command | |
(a) Find all files having .bak (*.bak) extension in current directory and remove them: | |
$ find . -type f -name "*.bak" -exec rm -f {} \; | |
(b) Find all core files and remove them: | |
# find / -name core -exec rm -f {} \; | |
(c) Find all *.bak files in current directory and removes them with confirmation from user: | |
$ find . -type f -name "*.bak" -exec rm -i {} \; | |
Output: | |
rm: remove regular empty file `./data0002.bak'? y | |
rm: remove regular empty file `./d234234234fsdf.bak'? y | |
rm: remove regular empty file `./backup-20-10-2005.bak'? n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment