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 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 Code:
find /zamo/direct/test/ -name myfile* -mtime -25 |xargs ls -lht 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 :) |
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 |
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 :) |
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 |
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 thanks :) |
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 |
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 If you want to include directories in the find results, then include the -d option for "ls" to prevent recursively listing the directory contents. |
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 Will share with you , if get something hard or useful. Thanks for you time and help :) |
All times are GMT -5. The time now is 08:03 PM. |