suppose in a directory there are over 20 files.
I need to move the first 10 files(first in first out basis, which ever files comes first) into a separate directory.
i have an idea but not sure how far this is correct, can anyone guide me on this?
find /opt/logs -name "cor*" -mtime 2 -type f -exec ls -ltr {} \; |mv <directory>
Thanks in advance...
mk1216
2
for i in `ls -trc |tail -10`
do
mv $i <new_dir>
done
ls -1t | grep ^- | head | xargs mv <directory>
worth trying above line
when i tried the above command, giving the below error:
Usage: mv [-f] [-i] f1 f2
mv [-f] [-i] f1 ... fn d1
mv [-f] [-i] d1 d2
can you throw light on this issue, please?
for i in `ls -trc |tail -10`
do
mv $i tmp/
done
here the contents will be moved to tmp/ directory. Make sure the directory exists
Thanks a lot for your help.
I've created a Test directory wherein i need to move the first 10 files. There are old files for 2003 year.
with the above code, it is getting executed successfully with no errors, none of them moved.
ls -trc -- in this 'c' is for when the file last modified.
if i use ls -ltr, showing the results starting from 2003.
there are files for 2003 year. I need to move the very first 10 files(starts from 2003) to Test dir.
I tried the below code:
for i in `ls -ltr | grep ^- | head -10 | awk '{print $9}'`
do
mv $i Test/
done
This works wonderfully. Appreciate your co-operation, that leads to get a solution.
If you want to add any comments on the above code, welcome...
Thanks again...