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
# 15  
Old 12-02-2011
It's basically the same as my original suggestion, it's just generating the 'Dec 2' part of the pattern automatically - date | cut -c5-10 gives characters 5-10 from the date command's response. .*: is a regular expression for 'any number of any character, followed by a colon'.

EDIT:
Code:
ls -ltrh | egrep "`date | cut -c5-10`.*:" || echo "No files"

# 16  
Old 12-02-2011
Thanks balajesuri; this is also working ...can u please explain this...
Quote:
Originally Posted by balajesuri
Code:
ls -l | perl -ne '$x=substr localtime, 4, 6; /$x\s+[0-9]{2}:[0-9]{2}/ && print $_'

---------- Post updated at 06:54 AM ---------- Previous update was at 06:22 AM ----------

Thanks CarloM

if there is no file found for today then I would like to display
"No files for today" ...how to check that condition...?

Quote:
Originally Posted by CarloM
It's basically the same as my original suggestion, it's just generating the 'Dec 2' part of the pattern automatically - date | cut -c5-10 gives characters 5-10 from the date command's response. .*: is a regular expression for 'any number of any character, followed by a colon'.

EDIT:
Code:
ls -ltrh | egrep "`date | cut -c5-10`.*:" || echo "No files"

# 17  
Old 12-02-2011
As per find:
Code:
find . -maxdepth 1 -daystart -mtime 0 -print

This will find all files modified "today"
# 18  
Old 12-02-2011
Perl's function localtime gives the following output:
Fri Dec 2 17:31:17 2011

Substr from 4 to a length of 6 would cut out "Dec 2". And hold this in variable $x.

"/$x\s+[0-9]{2}:[0-9]{2}/" -> Regex which will search strictly for "Dec 2 XX:XX" where XX:XX is the time. If it were "Dec 2 2010" then this regex wouldn't match.
# 19  
Old 12-02-2011
Quote:
Originally Posted by m.d.ludwig
As per find
Wrong find Smilie. SunOS doesn't support -daystart or -maxdepth.
# 20  
Old 12-02-2011
So:
Quote:
Originally Posted by m.d.ludwig
As per find:
Code:
find . -maxdepth 1 -daystart -mtime 0 -print

This will find all files modified "today"
won't work, you don't have "maxdepth", and I doubt you have "daystart".
Then I would:
Code:
MARK=$(mktemp)
touch -t $(date +%Y%m%d0000) ${MARK}
find . -type f -newer ${MARK} -print | grep -v '^.\/[^/]*/'
rm ${MARK}

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