Quote:
Originally Posted by
ak835
what if in a folder we have thousands of files ,lets say for past 2 years...
how can i search files of 2009 and just move them to a separate folder ?
date format being : 2009-03-25....
can 'xargs' be used here? if yes,how ?
Since this is presumably a one time job. I would use something like:
ls -ltr >filelist
Then edit filelist and remove all the file names that you do not want to move.
Then write a script to read the edited file and move the files.
---------- Post updated at 11:20 AM ---------- Previous update was at 11:01 AM ----------
Quote:
Originally Posted by
urandom
I like above solutions much better than mine, but I want to show my solution anyway, just to show that we have many solutions.
PHP Code:
#!/usr/bin/ksh
input_dir="/home/temp/in"
output_dir="/home/temp/out"
amount_files_input=`ls -1 $input_dir | wc -l`
if [ "$amount_files_input" -ge 100000 ] ; then
for i in {1..10000}
do
file_to_move=`ls -1 $input_dir | tail -1`
mv $input_dir/$file_to_move $output_dir
done
fi
and of course I'm a newbie still
Yes it will work with less than 250 entries in the directory, but....
With thousands of entries in the directory, ls, might well take significant time to execute.
I tried the "ls -1 $input_dir |tail -1" line on a directory with 168000 files.
Real time was 0.50 seconds*. You execute this command 10000 times
*on a dual processor quad core system with serial SCSI RAID10