LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 09-23-2008, 02:36 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
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
 
Old 09-23-2008, 02:49 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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
 
Old 09-23-2008, 02:55 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
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
 
Old 09-23-2008, 03:03 AM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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.
 
Old 09-23-2008, 03:45 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
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
 
Old 09-23-2008, 04:04 AM   #6
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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.
 
Old 09-23-2008, 04:06 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 09-23-2008, 04:15 AM   #8
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Icon set Needed, Can't find them shocktrooper Linux - Desktop 2 03-10-2007 11:02 AM
can't find needed rpm matt kramer Linux - Newbie 3 07-23-2006 07:50 PM
How to find needed library files sporty Linux - Software 9 04-12-2006 03:23 PM
how to find modules containing needed symbols? redss Linux - Hardware 1 01-04-2005 01:55 PM
Where to find needed Dependencies? l0f33t Linux - Software 13 08-13-2003 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration