Shell script to sort & mv file based on date

July 19, 2011 at 03:30:47
Specs: HP-UX
Im new to unix, I have search a lot of info but still don not how to make it in a bash script.

What i know is used this command ls -tr|xargs -i ksh -c "mv {} ../tmp/" to move file by file.

Now I need to make a script that sorts all of these files by date and
moves them into a directory, (The first 1000 oldest files being to be moved.)

Example files r like these



alwsys sort the files base on <SEQUENCE1>

Anyone can gv me hand ?.im rushing this

See More: Shell script to sort & mv file based on date

Report •

July 19, 2011 at 09:38:14
Assume you are in the directory where the files reside, this script performs an ls -1 one object per line, and then uses the sort command where as the field seperator is a period, the sequence1 number is the third field; -n forces a numeric sort.

Pipe that to a while loop where each file object is operated on up to 1000 objects:


# untested
ls -1|sort -t . -n -k 3,3|while read file
   while [ $x -lt 1000 ]
      # add your move command here

Report •
Related Solutions

Ask Question