for example I type
ls -altr | grep "23 Dec"
so it will show files for 23 Dec only and I want to use grep for them, like
ls -altr | grep "23 Dec" | xargs grep -l "some_string"
but this doesn't work)
How to do that?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityfor example I type
ls -altr | grep "23 Dec"
so it will show files for 23 Dec only and I want to use grep for them, like
ls -altr | grep "23 Dec" | xargs grep -l "some_string"
but this doesn't work)
How to do that?
If you want to use your way, try maybe:
ls -altr | grep "23 Dec" | awk '{print $9}' | xargs -i grep -l "some_string" {}
or with find
I would do:
find . -type f -newermt 2012-12-23 ! -newermt 2012-12-24 -exec grep -l "some_string" {} \;
In the find command, don't forget the escaped semicolon. Also note that find works much the same way as xargs
when used with the -exec option.
grep: invalid option -- - Usage: grep [OPTION]... PATTERN [FILE]... Try
grep --help' for more information.`
find -version
). in my case, i'm using find (GNU findutils) 4.4.2
Dec 25, 2012 at 7:40
If you were trying to find some files, that was modified on a specific date,
there would be no need for pipe, (ls uses modify time by default)
find . -type f -newermt 2012-12-23 ! -newermt 2012-12-24 -iname '*some_string*'
find . -type f -newermt 2012-12-24 ! -newermt 2012-12-25 -iname '*50424876*' find: invalid predicate
-newermt'`