Moving files on first in first out basis


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving files on first in first out basis
# 1  
Old 12-19-2008
Moving files on first in first out basis

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...
# 2  
Old 12-19-2008
for i in `ls -trc |tail -10`
do
mv $i <new_dir>
done
# 3  
Old 12-19-2008
ls -1t | grep ^- | head | xargs mv <directory>

worth trying above line
# 4  
Old 12-23-2008
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?
# 5  
Old 12-23-2008
Code:
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
# 6  
Old 12-23-2008
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.
# 7  
Old 12-24-2008
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split large file into 24 small files on one hour basis

I Have a large file with 24hrs log in the below format.i need to split the large file in to 24 small files on one hour based.i.e ex:from 09:55 to 10:55,10:55-11:55 can any one help me on this.! ... (20 Replies)
Discussion started by: Raghuram717
20 Replies

2. Shell Programming and Scripting

Script to count files on daily basis

Hi all I need to count files on a daily basis and send the output via email, what I am currently doing its simply running the following:ls -lrt *.cdr | awk '{if(($6 == "Jul") && ($7 == "13")) print $0}' | wc -l, which in this case it will count all files with extension "cdr" from the month of... (13 Replies)
Discussion started by: fretagi
13 Replies

3. Shell Programming and Scripting

Merge Two files on the basis of 2 columns at diffrent position

Hello, I am trying to merge two files with multiple records having a common columns but on first file its on 7th column and on 2nd file it on 6th column. First file(file1.txt) - 7th Column is unique H|123|Alex|Ren|W|9856746|2345789|20152202| H|97654|Ray|John||9855678|2345790|20152201|... (6 Replies)
Discussion started by: Mannu2525
6 Replies

4. Shell Programming and Scripting

Comparing two huge files on field basis.

Hi all, I have two large files and i want a field by field comparison for each record in it. All fields are tab seperated. file1: Email SELVAKUMAR RAMACHANDRAN Email SHILPA SAHU Web NIYATI SONI Web NIYATI SONI Email VIINII DOSHI Web RAJNISH KUMAR Web ... (4 Replies)
Discussion started by: Suman Singh
4 Replies

5. Shell Programming and Scripting

sftp - get newly created files on incremental basis

Hi, We have a sftp server which creates files daily and keeps 6 months of files on the server. We are creating a daily job to get the files and load into database. My problem is "how to get ONLY those files which got created after my last get". Let me provide some more details to it. Below... (15 Replies)
Discussion started by: ravi.videla
15 Replies

6. Shell Programming and Scripting

how to grep string from hourly basis files

dear all, pls help on this script.. i have many files which will be created every mins in particular directory. i want to grep a particular string from only for unique hour files. from the below code i want to grep a string from only 9th hour files . Ex files: -rw-r--r-- 1 root ... (5 Replies)
Discussion started by: steve2216
5 Replies

7. Shell Programming and Scripting

sorting of files on the basis of timestamp

Hi, With the help of below script im able to get the count of all the .xml files but that count is not specific to a day ie its the total count of all .xml files what i want is specific to 1 day and that of every half an hr ie from 23 feb 2009 7 am till 23rd feb 2009 2300 am and from 07:00 to... (1 Reply)
Discussion started by: ss_ss
1 Replies

8. Shell Programming and Scripting

Zip all the files within a directory on a daily basis

I need to zip all the files within a directory on a daily basis and store them as a zip file within that directory with the date in its naming convention I have file extentions .log .lst and .out's within that directory How do i do this task zip -mqj mydir/allzip$YYMMDDDD.zip mydir/*.* ... (5 Replies)
Discussion started by: ramky79
5 Replies

9. Shell Programming and Scripting

Find files on minutes basis

Hello, I was trying to find files which are created in last five minutes . I tried to use command find with ntime and mtime but was not successfull then i read from this forum that we can not have a find option on minutes or seconds or hours...... Can somebody Pls expalin how can i search... (3 Replies)
Discussion started by: er_aparna
3 Replies
Login or Register to Ask a Question