Solved

Find command

Posted on 2011-09-22
8
271 Views
Last Modified: 2012-05-12
find /tmp/mydirectory -type f –iname -mtime +30 -exec rm -f {} \;

I want to find  and remove specific files with extensions .dat,.txt,.TXT,.csv,.XLS from /tmp/mydirectory which are 30days old.
Can some body tell me how to pass the combination of file extensions so that only files with these extensions are picked and deleted?(Any files other than these set of extensions should not be removed.I'm using redhat Red Hat Enterprise Linux).Thanks in advance
0
Comment
Question by:prashubk
  • 4
  • 2
  • 2
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 36584809
-iname '*.dat' -o -iname '*.txt' -o -iname '*.csv' -o -iname '*.xls'
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36584841
find /tmp/mydirectory -type f –iname '*.dat' -o -iname '*.txt' -o -iname '*.csv' -o -iname '*.xls' -mtime +30 | xargs rm -f

Open in new window


If you have -o's and an exec, then you will need an exec for each -o.  xargs is more efficient as well, in some cases at least.
0
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 36584852
you can use
\( -iname '*.dat' -o -iname '*.txt' -o -iname '*.csv' -o -iname '*.xls' \) -mtime +30 -exec
but xargs is generally more efficient
0
 

Author Comment

by:prashubk
ID: 36584870
thanks for the answers.  Why do we say xargs is more efficient over exec?. What is the advantages of using xargs over exec in this context?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 21

Assisted Solution

by:Papertrip
Papertrip earned 250 total points
ID: 36584884
exec will spawn a new process (rm -f) for each match.  xargs contructs a list and will spawn the process once it hits the limit defined by the system.

[root@broken etc]# xargs --show-limits
Your environment variables take up 1699 bytes
POSIX upper limit on argument length (this system): 2617693
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2615994
Size of command buffer we are actually using: 131072

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36584913
Thanks for the assist, and no offense to ozo of course, but why was http:#36584852 chosen as Accepted Solution?

Are you not going to use xargs like we both suggest?  If you are then technically http:#36584841 is exactly what you want and should have been the Accepted Solution.
0
 

Author Comment

by:prashubk
ID: 36584925
sorry ,oh yes i should have accepted 36584841 as this is what i'm intended to use.Well Ozo contributed with the idea  to pick files with desired extension
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36584948
All good, just wondering, thanks for replying.

Good luck!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now