how to list all the files for today in the dir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to list all the files for today in the dir
# 1  
Old 12-02-2011
how to list all the files for today in the dir

I am trying following ...
Code:
ls -ltrh | grep 'Dec  2'

but it is displaying files for last year also ..as this dir is full of files from last 3-5 yrs
I only want to files for today.

e.g .
Code:
ls -ltrh | grep 'Dec  2'
-rw-r-----   1 ajay    ajay          0 Dec  2  2010 text23.txt
-rw-r-----   1 ajay    ajay          0 Dec  2  2010 text22.txt
-rw-r-----   1 ajay    ajay          0 Dec  2  2010 text21.txt
-rw-r-----   1 ajay    ajay          0 Dec  2  2010 text20.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:32 test.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:32 test1.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:32 text3.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:32 text4.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:37 test11.txt
-rw-r-----   1 ajay    ajay          0 Dec  2 20:37 text12.txt


Last edited by Franklin52; 12-03-2011 at 11:46 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 12-02-2011
Try
Code:
ls -ltrh | grep "Dec 2 .*:"

# 3  
Old 12-02-2011
thanks but it is not working...no o/p.

Quote:
Originally Posted by CarloM
Try
Code:
ls -ltrh | grep "Dec 2 .*:"

# 4  
Old 12-02-2011
Code:
ls -l | perl -ne '/Dec\s+2 [0-9]{2}:[0-9]{2}/ && print $_'

# 5  
Old 12-02-2011
Quote:
Originally Posted by ajaypatil_am
thanks but it is not working...no o/p.
Depending on your OS you might need to use egrep rather than grep. Also, check if your input is
Code:
Dec 2

or
Code:
Dec  2

EDIT: Hmm, [icode] tags compress spaces!
# 6  
Old 12-02-2011
hi in /ksh korn shell there is no command as ls -h Smilie So please tell which shell u are using to run this command
# 7  
Old 12-02-2011
I want to search for all the files for today ...

ls -l | perl -ne '/Dec\s+2 [0-9]{2}:[0-9]{2}/ && print $_'

works but I can not hard code Dec\s+2 everyday ...ideally it should take the date dynamically and show me files only for today.

---------- Post updated at 05:54 AM ---------- Previous update was at 05:52 AM ----------

FYI i am using SunOS
uname -v
Generic_122300-60
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files in dir and grep accordingly

bash or c-shell On Solaris 10 I need a command that will list the files of a directory, and grep each of those filenames out of a static text file, and then only echo field 2 of the static text file. Something like this: #> ls -1 /home/dir/ | each filename grep $filename static.txt |awk... (4 Replies)
Discussion started by: ajp7701
4 Replies

2. Linux

List all files created today exclude last one

Hi, ALL thanks in advance, i listed all files using this command ls -ltr $(date +%Y%m%d)*.xmlbut i would like to exclude the last one created ; Best regard MEROUAN Use code tags, thanks. (4 Replies)
Discussion started by: merouan
4 Replies

3. Shell Programming and Scripting

Copy files to a dir using from a list

Hi all, I'd very grateful for some help with the following: I have a directory with several subdirectories with files in them. All files are named different, even between different subdirectories. I also have a list with some of those file names in a txt file (without the path, just the file... (5 Replies)
Discussion started by: foracoffee
5 Replies

4. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

5. Shell Programming and Scripting

How to get a list of files in a dir w/o sub-directories?

Hi I am looking for the correct syntax to find all files in the current directory without listing sub-directoris. I was using the following command, but it still returns subdirectoris and files inside them: $ ls -laR | grep -v ^./ Any idea? Thanks PS I am in ksh88 (4 Replies)
Discussion started by: aoussenko
4 Replies

6. Shell Programming and Scripting

Generate a change list of files/dir

Is there a tool that can diff a directory and generate a change list of files in that directory based on a previous snapshot on the directory? For example /etc/a.txt:changed /etc/b.txt:removed /etc/c.txt:added Thanks! (1 Reply)
Discussion started by: overmindxp
1 Replies

7. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

8. UNIX for Dummies Questions & Answers

To list all the files created today with directory path

Hi, Can any one tell the command to list all the files that are created as of today from all the directories? The Command "ls -ltR" is listing all the files. But I want the list of files that has been created as of today along with the directory path:) Thank you in advance.:) Regards,... (4 Replies)
Discussion started by: meetusha.b
4 Replies

9. UNIX for Dummies Questions & Answers

How to list all the files which are not generated today

How to list all the files which are not generated today, and move all the above files to backup dir. (2 Replies)
Discussion started by: redlotus72
2 Replies

10. Shell Programming and Scripting

How to list today's files

Hi, I am trying to list names of only today's files OR say, files which are not older than 1 hour and copy them in 'list.txt' file. I know, :ls > list.txt will list all the files. But, how to list today's files? Any help will be appriciated. (4 Replies)
Discussion started by: berlin_germany
4 Replies
Login or Register to Ask a Question