Hi Guys,
I am trying to print all the filenames whose created/modified date is not today.
ts $ ls -lt
total 256
-rw-r--r-- 1 fcfmetl fastcar 116686 Sep 25 06:06 Output_execTVGen.txt
drwxr-xr-x 2 fcfmetl fastcar 256 Sep 25 05:04 log
-rwxr-xr-x 1 fcfmetl fastcar 2629 Sep 25 03:03 compass.sh
drwxr-xr-x 2 fcfmetl fastcar 256 Sep 25 03:00 ftp
-rwxrwxrwx 1 fcfmetl fastcar 3810 Sep 25 02:48 trigger_execTVGen.ksh
-rw-r--r-- 1 fcfmetl fastcar 88 Sep 24 09:57 email_body.txt
drwxr-xr-x 2 fcfmetl fastcar 256 Sep 24 09:37 bckup
I am using the below command for it
ls -tl | awk -v f=`date '+%d'` '{if ("$7" -ne "$f" ){print $9}}'
But it is giving all the file name.
Can you let me know where i am going wrong.
Magesh
danmero
September 25, 2009, 7:12am
2
Try this solution
ls -lt | awk -v f=`date '+%d'` '$7 != f && $9{print $9}'
ls -l | grep "$(date +"%b %d")" | awk '{ print $9 }'
danmero
September 25, 2009, 7:47am
4
Did you check the OP requirement ?
aigles
September 25, 2009, 8:01am
5
ls -tl | awk -v d=$(date +%d) -v m=$(date +%b) '$6 != d || $7 != m || $8!~/:/'
Jean-Pierre.
ripat
September 25, 2009, 8:06am
6
You can also use find for that.
find . * -maxdepth 0 -atime +1
aigles
September 25, 2009, 8:21am
7
This commands doesn't give the required result.
-atime n
File was last accessed n*24 hours ago. When find figures out how many
24-hour periods ago the file was last accessed, any fractional part is
ignored, so to match -atime +1, a file has to have been accessed at least
two days ago.
Replacing -atime +1 by -atime +0 will not give the right result, because find works with hours*24.
A file created yesterday but less than 24 hours ago will not be selected.
Jean-Pierre.
Danmaro, Your solution worked fine expect that i have to replace awk wiht nawk..
Aigles, your solution is still giving me everything in the folder including the file created today..
log>ls -tl | nawk -v d=$(date +%d) -v m=$(date +%b) '$6 != d || $7 != m || $8!~/:/'
total 4
-rw-r----- 1 dsdev dstage 0 Sep 25 08:23 b.txt
-rw-r----- 1 dsdev dstage 0 Sep 25 08:23 a.txt
-rw-r----- 1 dsdev dstage 584 Sep 15 06:06 pra.txt
-rw-r----- 1 dsdev dstage 42 Sep 15 05:57 name.txyt
Thanks for your help..
Can you guys, point out what went wrong in my code?
aigles
September 25, 2009, 8:32am
9
mac4rfree:
Danmaro, Your solution worked fine expect that i have to replace awk wiht nawk..
Aigles, your solution is still giving me everything in the folder including the file created today..
log>ls -tl | nawk -v d=$(date +%d) -v m=$(date +%b) '$6 != d || $7 != m || $8!~/:/'
total 4
-rw-r----- 1 dsdev dstage 0 Sep 25 08:23 b.txt
-rw-r----- 1 dsdev dstage 0 Sep 25 08:23 a.txt
-rw-r----- 1 dsdev dstage 584 Sep 15 06:06 pra.txt
-rw-r----- 1 dsdev dstage 42 Sep 15 05:57 name.txyt
Thanks for your help..
Can you guys, point out what went wrong in my code?
On my system, the language is set to french, so the format of the date in the output is different (day and month are inverted).
Try:
ls -tl | awk -v d=$(date +%d) -v m=$(date +%b) '$7 != d || $6 != m || $8!~/:/'
Jean-Pierre.
Ohh.. my language is english (en). My OS is SunOs.. so, i dont know whether that is also causing a problem..
Can you point out the error in my code
Thanks
danmero
September 25, 2009, 9:24am
11
ls -lt | nawk 'd!=$6$7||$8!~/:/' d=$(date +%b%d)