List files based on dates
I like to list the files only today's or a particular days files in a directory.
You should be able to do a ls -l and then pipe it to a grep for the date you want.
And a chronological listing is quite helpful:
Print files with certain dates
How can I print a file with a date timestamp to a file?
ls -al |grep "Oct 18 200X" >filename.txt
This would put all file names with the date
of Oct 18 2001 into the file "filename.txt".
ls -al *.txt|grep "Oct 18 200X" >filename.txt
This would put only those files with that date and that file extention
If you add more to the file later use >> where I put the > . > overwrites/ >> appends
Change date format using shell
I am trying to change the date format from MM/DD/YYYY to MMDDYYYY in the fixed width file using shell. Dates are in fields 19-28 and 29-38.
I guess you want to format the date in your required format using the
You need to use
date '+%m' - Month
date '+%d' - Day
Parse the date '+%c' and get the year. you can use the 'cut' command and get the reqd. field.
I'm trying to write a simple backup script using rsync, tar and crontab .. but I want to be able to rename a newly created archive with the current date.
I sometimes use dates in file naming, but I prefer sequential numbering
since that is unique, and I still have the date stamp of the file to show
me when it was created. When using dates, consider including hour and min,
and maybe even sec. Following example uses only ymd. The nested command
in back apostrophes is replaced by its output:
/etc/fbackup -f $outfile ...
If the utility does not let you name the output, but instead always outputs to some default file name, you can rename it after creation:
mv backup.out $outfile
Do you have a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips