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.
I need to find out how to remove certain files base on file extension in Linux.
I've tried this from another website:
Quote:
find /scratch/yourdir -name 'core.*' > find.out then edit this new file. For example, remove the files you want to keep from 'find.out,' then put the remove command and a space ('rm ') at the beginning of each remaining line. To do this, while in the vi editor for example, enter:%s/^/rm /Write and quite the file, change its mode (chmod u+rwx find.out) and execute the file (./find.out). All files that remain in find.out will be deleted from your disk.
The result is: (let say i want to remove all .pif00 files listed in [find.out])
Quote:
rm: cannot lstat 'myfolder/file.doc': No such file or directory
Quote:
rm: cannot lstat '.pif': No such file or directory
OK, for above, i realize that because those files are with names like:
Quote:
filename.doc[ long spaces in between ].pif
That's why the method i used not really working. (How do i fix this?)
Guys, what's wrong? Or could anyone suggest me other ways to remove multiple files in multiple sub-directories base on file extensions?
Unless I don't understand your question, why can't you simply use a wildcard recursively? For example, if you wanted to remove all .txt files within the directories report, project, work, and documents in the directory structure, /home/heislyc/documents/work/project/report just run the following command: rm -rR /home/heislyc/*.txt
I managed to solve the problem by using mv command.
Initially, the rm -R /home/*.txt doesn't work, it gives me no such files error.
After that, i've tried using mv -R /home/*/*/*.txt dummy, then only i managed to move out all those files to dummy directory, then delete all files that moved into [dummy].
That basically means, you need to insert each wildcard for each level of directory tree. :S
Thanks guys for reply, as for find command, i'll try it out, but i think same rules applied.
I would use -ok instead of -exec when removing files as it will prompt you whether or not you want to run that command on that file, saves you from accidently deleting files when you typo the find command.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.