LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-02-2005, 06:56 PM   #1
backnine_99
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Rep: Reputation: 0
Question find and move most recent files in dir


1. What I'd like to be able to do is to look thought a directory containing files like:

foo.123
foo.124
foo.125
...
foo.150


2. using the name of the file, be able to move files one at a time, starting with the oldest (foo.123), and working it's way through all the files until all are processed.

So, this is what I have so far which is moving the first file fine. I'd like to know how to make it run until it has processed all the files in the directory...

#! /bin/csh
set lastfile = NULL
foreach i (`ls -t foo*`)
if ($lastfile == NULL) then
set datafile = $i
endif
set lastfile = $i
if ($lastfile != $datafile) then
mv $lastfile testdir
endif
end


any help is much appreciated.

thanks!

- GD
 
Old 06-02-2005, 07:19 PM   #2
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
you can look into using the find command with the options -mtime -atime and -ctime. Here are the descriptions for each as stated in Sams Teach Yourself Shell Programming in 24 Hours.

-mtime - fines files last modified more than, exactly, or fewer than n days ago

-atime - find files last accessed more than, exactly, or fewer than n days ago.

-ctime - find files that were last changed more than, exctly, or fewer thatn n days ago.

you could probably do something like find -{c/m/a}time expression -exec mv foo new destination in a loop to accomplish this. You could also look into xarg to execute the command after you get the list of file names to move. something like find (options and parameters) | xarg mv (options and parameters) check out man for find and xarg for more info. And by the way you should have posted this in the programming section and might have gotten more reponses; however don't double post. If a moderator sees this they will probably move it to programming forum anyways.
 
Old 06-14-2005, 12:03 PM   #3
backnine_99
LQ Newbie
 
Registered: Jun 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you for your help. I ended up doing the following:
foreach i (`ls abc*`)
set datafile = $i
echo $datafile
mv $datafile ../post
break
end

foreach i (`ls xyz*`)
set datafile = $i
echo $datafile
mv $datafile ../post
break
end
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 12:01 PM
Script to find all picture files on a HDD and move them scoops98 Linux - General 8 02-27-2007 02:40 AM
deleting recent files Santas Linux - General 2 01-19-2004 06:26 AM
recent debian distro/base files/ net install ? mvbv-linux Debian 1 01-08-2004 10:15 AM
When I try to move a file to a dir it says No Space Left on Device. Help KrazyKid Linux - Software 1 06-16-2002 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration