[SOLVED] shell script to search for files of specific extension and delete them all
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Spell your words out, and do some of your own research. Read the man pages, and check Google. There are LOTS of examples on how to pipe things, and write shell scripts.
Come on, people.. let's not joke with the remove command! You cannot pipe the result of find or any other command directly to the standard input of rm, since the files to remove have to be passed as arguments. The rm command reserves the standard input for user interaction. Instead, let's wait the OP follows the TB0ne's advice and elaborates something for which we could really give help!
Come on, people.. let's not joke with the remove command! You cannot pipe the result of find or any other command directly to the standard input of rm, since the files to remove have to be passed as arguments. The rm command reserves the standard input for user interaction. Instead, let's wait the OP follows the TB0ne's advice and elaborates something for which we could really give help!
I didn't know that.
If the file list didn't have spaces, he could pipe it into
Some notes on what options are for.
-type f (only list standard files, not directories, devices, pipes etc)
-print0 | xargs -0 (use null to seperate list of files to allow for spaces in file/directory names). Note character in flags is a numeric zero
-r don't call rm if input is empty (i.e. no files were found)
Some notes on what options are for.
-type f (only list standard files, not directories, devices, pipes etc)
-print0 | xargs -0 (use null to seperate list of files to allow for spaces in file/directory names). Note character in flags is a numeric zero
-r don't call rm if input is empty (i.e. no files were found)
Some notes on what options are for.
-type f (only list standard files, not directories, devices, pipes etc)
-print0 | xargs -0 (use null to seperate list of files to allow for spaces in file/directory names). Note character in flags is a numeric zero
-r don't call rm if input is empty (i.e. no files were found)
This command will search recursively starting at the directory given in /path/to/search/. Every file who's name ends in .jpg will be permanently and irrevocably erased. The deletion is done silently, so don't expect to be told what was deleted. Don't do this unless you are perfectly damn certain it is what you want.
Code:
find /path/to/search/ -type f -name '*.jpg' -delete
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.