Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Find command

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
prashubk
Asked:
prashubk
  • 4
  • 2
  • 2
2 Solutions
 
ozoCommented:
-iname '*.dat' -o -iname '*.txt' -o -iname '*.csv' -o -iname '*.xls'
0
 
PapertripCommented:
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
 
ozoCommented:
you can use
\( -iname '*.dat' -o -iname '*.txt' -o -iname '*.csv' -o -iname '*.xls' \) -mtime +30 -exec
but xargs is generally more efficient
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
prashubkAuthor Commented:
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
 
PapertripCommented:
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
 
PapertripCommented:
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
 
prashubkAuthor Commented:
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
 
PapertripCommented:
All good, just wondering, thanks for replying.

Good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now