ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hi,
I want to write a script that will detect all the unwanted files in a particular directory and delete them in one fly..
Can anyone guide me for this ???
Hi,
I want to write a script that will detect all the unwanted files in a particular directory and delete them in one fly..
Can anyone guide me for this ???
You should learn to use descriptive titles for your threads. That way you will receive targeted responses.
What have you done to find a solution to the problem? Other than to post here.
We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist.
You haven't provided enough information for us to aid so;
Quote:
FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query.
Just a few links to aid you to gaining some understanding. I would start at 4,5 &6 since your query requirements are aligned to these. While the other links will enhance your Gnu/Linux experience;
Hi,
I want to write a script that will detect all the unwanted files in a particular directory and delete them in one fly..
Can anyone guide me for this ???
Note the date posted. Maybe it was an April Fool's Day joke (I hope ).
Why? It does exactly what the OP specified, if you defined 'unwanted files' as the file named 'unwanted' or the set of all files in the directory tree named 'unwanted'. If no such file or directory exists, it does nothing.
Why? It does exactly what the OP specified, if you defined 'unwanted files' as the file named 'unwanted' or the set of all files in the directory tree named 'unwanted'. If no such file or directory exists, it does nothing.
--- rod.
I was referring to the original post, not Cpare's reply.
I'll explain with an example...
I have a folder named TEMP.. This folder contains files a.c, b.c, b_bak.c
So in this I want to delete only b_bak.c.. So I tried :-
find ./TEMP ! -name a.c ! -name b.c | xargs -r rm
Now after executing this script it deletes the file but it says cannot delete ./TEMP as it is a directory...
So now I modified above since I do not want to delete the Folder itself:-
Wouldn't it be a better idea to delete everything ending with _bak.c instead of entering the files that shouldn't be deleted? Seems like it would be both easier and less risky.
Code:
find TEMP -name '*_bak.c' -exec rm '{}' ';'
You should also use find's -exec oftion instead of xargs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.