|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Move 600 oldest files
In a kshell script, I need to move the 600 oldest files to another directory.
I can't seem to come up with a way to do this... is there a way to identify the number of files using ls? Should I ls to a file and then somehow use the line number inside the file to move the files? Ideas about how to do that? Thanks for any input. Stacy |
|
#2
|
|||
|
|||
|
you need to use something like:
ls -t | sed -e "1,600" to give your list of file to move. Quote:
|
|
#3
|
|||
|
|||
|
Something like:
Code:
for file in $(ls -logtr | tail -600 | awk '{print $7}')
do
mv $file /dest/$file
done
But with more error checking (and ensuring that field 7 is the file name) will do it one file at a time. Or you could do something similar and send output to a file and then parse the file. |
|
#4
|
|||
|
|||
|
Thanks everyone! Got it!
Stacy |
|
#5
|
|||
|
|||
|
Here's another just for the hell of it:
Code:
mv $(ls -t|head -n 600) destination/ |
|
#6
|
||||
|
||||
|
Why not one more?
Code:
ls -t | head -n 600 | xargs -i mv {} destination/
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Move 600 oldest files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|