Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Is there any command in Linux (SuSE) that can delete some specific files in many directories, say 100 ? There are a number of files in these directories on my hard disk which all have same names (or same starting name), and they are useless and have taken much of the disk capacity, so I need to delete them but it is impossible to go into each of them one by one. If you know such a command, I would appreciate it if you could let me know.
This will work for as many files as it finds. I'd suggest running it first without the '|xargs rm -f' so you can see what it finds before deleting. This can be very destructive if you make a mistake with the file pattern.
Never tried anything like that, but you might want to look at the man pages for 'find'. Its got an exec part. I wonder if you'll be able to use 'rm in that part.
Not sure if a normal pipe would work, so I guess a little script could do it if you can't find a soluition with 'find'
Mons
EDIT: crabboy pressed send first, and with a more full answer.
Use the find command with the -exec option to remove the resulting files. For example, suppose you have some files whose name start with "test", all under the /home directory:
the echo command is for testing purpose. It will just print the actual command to execute. Check carefully if the listed files are all those you want to remove, then run the command again without echo to actually remove them. Alternatively you can do
Code:
find /home -type f -name test\* -ok rm {} \;
using -ok in place of -exec force it to ask for confirmation before removing a file.
Using -exec would work, but it will execute rm for each file that it finds. xargs collects a bunch of filenames and then calls rm with the filenames as the parameter. For a hundred files or so the difference will be small, but for thousands of files you'll notice a difference in the speed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.