Linux - GeneralThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.