How to list todays and yesterdays .rej files from a directory?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to list todays and yesterdays .rej files from a directory?
# 1  
Old 08-13-2012
How to list todays and yesterdays .rej files from a directory?

I am trying to display todays and yesterdays .rej files from a directory.
Code:
 ls -lrt *.rej | grep 'Aug 12' ; ls -lrt *.rej | grep 'Aug 13'

Which is working as above.
But i want take 'Aug 12' and 'Aug 13' from a variable and the command should work everyday.

I am able to get todays files by using belows pseudo code.
psuedo code:
Code:
d=$ `date '+%b %d'` 
yest=$(`date -d '1 day ago' +'%d %d'`)
ls -lrt *.rej | grep 'd' ; ls -lrt *.rej | grep 'yest'

but i am facing problem while printing yesterdays date files.
Code:
Error is date: Not a recognized flag: d
Usage: date [-u] [+"Field Descriptors"]

Could anyone help where i am doing wrong?

Last edited by Scott; 08-13-2012 at 09:31 AM.. Reason: Please use code tags
# 2  
Old 08-13-2012
-d is a GNU extension. how about using find -mtime -2 ?
# 3  
Old 08-13-2012
try this.....

Code:
var_today=$(date "+%b %d")
var_yest=$(date --date="yesterday" "+%b %d")
ls -lrt *.rej | grep "$var_yest" ; ls -lrt *.rej | grep "$var_today"

# 4  
Old 08-13-2012
---------- Post updated at 07:50 AM ---------- Previous update was at 07:47 AM ----------

Quote:
Originally Posted by pamu
Code:
var_today=$(date "+%b %d")
var_yest=$(date --date="yesterday" "+%b %d")
ls -lrt *.rej | grep "$var_yest" ; ls -lrt *.rej | grep "$var_today"


Thanks for the info.
But i am getting below error message:

Code:
$ sh sample.sh
date: Not a recognized flag: -
Usage: date [-u] [+"Field Descriptors"]
ls: 0653-341 The file *.rej does not exist.
ls: 0653-341 The file *.rej does not exist.
$


Last edited by Franklin52; 08-13-2012 at 09:51 AM.. Reason: Please use code tags for data and code samples
# 5  
Old 08-13-2012
Quote:
Originally Posted by GopalKrishnaP
---------- Post updated at 07:50 AM ---------- Previous update was at 07:47 AM ----------




Thanks for the info.
But i am getting below error message:

Code:
$ sh sample.sh
date: Not a recognized flag: -
Usage: date [-u] [+"Field Descriptors"]
ls: 0653-341 The file *.rej does not exist.
ls: 0653-341 The file *.rej does not exist.
$

Check if your bash supports date or not..
enter below commands in bash..

Code:
date
date "+%b %d"   
date --date="yesterday" "+%b %d"

# 6  
Old 08-13-2012
Quote:
Originally Posted by pamu
Check if your bash supports date or not..
enter below commands in bash..
uhm... did you miss his first post where his date command did not take any options?

Please try:
Code:
find . -name '*.rej' -mtime -2

This User Gave Thanks to neutronscott For This Post:
# 7  
Old 08-13-2012
Quote:
Originally Posted by pamu
Check if your bash supports date or not..
enter below commands in bash..

Code:
date
date "+%b %d"   
date --date="yesterday" "+%b %d"

Code:
$ date
Mon Aug 13 08:57:39 EDT 2012
$ date "+%b %d"
Aug 13
$ date --date="yesterday" "+%b %d"
date: Not a recognized flag: -
Usage: date [-u] [+"Field Descriptors"]
$

These are the outputs which i am getting.

---------- Post updated at 08:04 AM ---------- Previous update was at 07:59 AM ----------

Quote:
Originally Posted by neutronscott
uhm... did you miss his first post where his date command did not take any options?

Please try:
Code:
find . -name '*.rej' -mtime -2

Thank you so much.. it was working.. Could you briefly explain the command?

Last edited by Scott; 08-13-2012 at 10:02 AM.. Reason: PLEASE use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Logrotate and Compressing only yesterdays files

Hello, I have a syslog server at home and am currently experiencing an issue where my logs will rotate and compress however it will rotate and compress yesterdays file and the newly created log file for the current day. When it does this however it will also create another new file for today... (9 Replies)
Discussion started by: MyUserName7000
9 Replies

2. UNIX for Beginners Questions & Answers

How to list todays file in perticular folder?

How to list todays file in perticular folder Moved thread to appropriate forum (9 Replies)
Discussion started by: pspriyanka
9 Replies

3. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

4. UNIX for Dummies Questions & Answers

Make directory with todays date format

Not sure why this is not working. Please advice: #!/bin/sh DIR=`date +"%m-%d-%y"` echo $DIR ] && mkdir $DIR (2 Replies)
Discussion started by: iaav
2 Replies

5. Shell Programming and Scripting

List/Range Todays Log.

Hi All, I am mediator Shell programmer, Just have an hands on experice :-), i am writing a shell scirpt to list logs of todays date from /var/log/messages. I need to ur kind help where if i run this script from cron. the script should filter todays logs only from /var/log/messages. Below... (4 Replies)
Discussion started by: anand.kulkarni
4 Replies

6. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

7. Shell Programming and Scripting

How to list todays file

Hi Friends, How to list todays file from a directory listing of files for amny dates. I tried with the following options but not working : find . -name "esi01v*" -mtime 1 -ls find . -name "esi01v*" -ctime 1 -ls find . -name "esi01v*" -mtime 1 Please advise (19 Replies)
Discussion started by: unx100
19 Replies

8. Shell Programming and Scripting

using find to get all of yesterdays files

i tried to use "find" to get all of yesterdays files but missed something in the 24 hours logic. can anybody help me with this one? i thought that -daystart -atime 1 was enough but i got more files (2 Replies)
Discussion started by: progressdll
2 Replies

9. UNIX for Dummies Questions & Answers

Get yesterdays date given todays date

Hi Guys. I am very new to UNIX. I need to get yesterdays and tommorows date given todays date. Which command and syntax do i use in basic UNIX shell. Thanks. (2 Replies)
Discussion started by: magikminox
2 Replies

10. UNIX for Dummies Questions & Answers

yesterdays files

I am new to UNIX and I am trying to write a shell script. I want to be able to list all files that were created with yesterdays dates (APR 29 as an example) that are not 0 file size.Then in those files I want to look for the string 'Process Complete' and list all files that DONT have that string.... (8 Replies)
Discussion started by: tonydsam
8 Replies
Login or Register to Ask a Question