Linux - General This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-23-2008, 02:36 AM
|
#1
|
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565
Rep:
|
Help needed for find command
Hi all,
Am using the following find command to list the files and got my desired output.
Code:
find /zamo/direct/test/ -name myfile* -mtime -25 |xargs ls -lht|grep -v total
The output must be as following, since I need to do awk,sed &cut from this
Code:
-rw-rw-r-- 1 zamo zamo 21M Jul 14 03:02 myfile_2008.07.14
It was working fine. I have my question here . If my search did not find a output for the 25 days using
Code:
find /zamo/direct/test/ -name myfile* -mtime -25
It is returning no output. But the
Code:
find /zamo/direct/test/ -name myfile* -mtime -25 |xargs ls -lht
is making an undesired output of listing all the files in the current directory from which the script is executed.
Is there any command or choice to avoid this kind of errors. I need the output if the "find" results an output of file with 25 days old. But "xargs ls -lht " is also must , as i need to do long listing.
Any alternate for this? any Suggestion.
Thanks 
|
|
|
|
09-23-2008, 02:49 AM
|
#2
|
|
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,560
Rep: 
|
If I understand the question, to prevent myfile* from being expanded by the shell, you need to quote it:
Code:
find /zamo/direct/test/ -name "myfile*" -mtime -25 |xargs ls -lht
|
|
|
|
09-23-2008, 02:55 AM
|
#3
|
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565
Original Poster
Rep:
|
Sorry Berhanie,
Its not working . Am getting the same output. I hope you understand my issue and if you have time, have a sample try on your box.
Thanks 
|
|
|
|
09-23-2008, 03:03 AM
|
#4
|
|
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,560
Rep: 
|
I think I understand the question: ls -lht lists files in the current directory. So, here's something:
Code:
find /zamo/direct/test/ -name 'myfile*' -mtime -25 -exec ls -lht '{}' \; | grep -v
You should look up the exact syntax for -exec, but I think that's correct.
|
|
|
|
09-23-2008, 03:45 AM
|
#5
|
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565
Original Poster
Rep:
|
Berhanie,
Yes the "exec" works. But the "find" has to search for files within a thousands of files , as it will send out a lot of errors even though i get the desired output.
Code:
find: ls terminated by signal 13
Am using the same "find " about 40 times within the script. IS there anyway to use "xargs " to get my desired outoput and without the errors.
thanks 
|
|
|
|
09-23-2008, 04:04 AM
|
#6
|
|
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,560
Rep: 
|
I just glanced through the man page of xargs. It looke like there's an "xargs -r", which will come in handy if find doesn't produce output. So, it looks like
Code:
find /zamo/direct/test/ -name 'myfile*' -mtime -25 |xargs -r ls -lht|grep -v total
is our candidate. By the way, you know about redirecting standard error, right?
Last edited by Berhanie; 09-23-2008 at 04:06 AM.
|
|
|
|
09-23-2008, 04:06 AM
|
#7
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
There are two things you want to do. First, the find command will also return directories as well as find, so "ls" will return all files in the directory. Add "-type f". Also, if a file might contain white space, you want to use the NULL character as an argument delimiter when using xargs. Simply add -print0 to the find command and the "-0" argument to xargs. If you have thousands of files matching the criteria, then use one of the limiting option to xargs.
Code:
find /zamo/direct/test/ -type f -name "myfile*" -mtime -25 -print0 | xargs -0 ls -lht
Since all of the arguments are files, you don't have an -v line to get rid of.
If you want to include directories in the find results, then include the -d option for "ls" to prevent recursively listing the directory contents.
|
|
|
|
09-23-2008, 04:15 AM
|
#8
|
|
Member
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 565
Original Poster
Rep:
|
Thank you both for the suggestions,
Currently am moving with
Code:
find /zamo/direct/test/ -name 'myfile*' -mtime -25 |xargs -r ls -lht|grep -v total
as it works.
Will share with you , if get something hard or useful.
Thanks for you time and help 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:56 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|