UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 13th, 2006, 05:48 PM
sarunda sarunda is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 13 sarunda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 14 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 13th, 2006, 06:51 PM
jaffy jaffy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 3 jaffy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 2 sec
Reputation Power: 0
you need to use something like:

ls -t | sed -e "1,600"

to give your list of file to move.



Quote:
Originally Posted by sarunda
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

Reply With Quote
  #3  
Old September 14th, 2006, 03:24 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 767 SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 23 h 25 m 34 sec
Reputation Power: 336
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.

Reply With Quote
  #4  
Old September 15th, 2006, 04:16 PM
sarunda sarunda is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 13 sarunda User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 14 sec
Reputation Power: 0
Thanks everyone! Got it!

Stacy

Reply With Quote
  #5  
Old September 15th, 2006, 05:36 PM
vlsimpson vlsimpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: The grassy knoll
Posts: 115 vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 1 m 30 sec
Reputation Power: 41
Here's another just for the hell of it:
Code:
mv $(ls -t|head -n 600) destination/

Reply With Quote
  #6  
Old September 15th, 2006, 07:09 PM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Why not one more?

Code:
ls -t | head -n 600 | xargs -i mv {} destination/

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Move 600 oldest files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT