LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2008, 12:34 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
moving the the oldest file


Quote:

#!/projects/ilinterf/bin/expect

set f "ls -lrta /projects/ilinterf/john/expect/backupdir/*.txt"
spawn /bin/ksh



expect "h>"
send "cd /projects/ilinterf/john/expect/backupdir;mv $f /projects/ilinterf/john/expect/backupdir/testtest\n"
expect "h>"
Hi guys, above is my code. I want to move only the oldest file (when i do ls -lrta, and i can find the oldest file from a list). I did the above code...how to do tat...

above code gives error of

Quote:

mv: cannot access ls
mv: cannot access -lrta
mv: cannot access /projects/ilinterf/john/expect/backupdir/*.txt
pls help

thanks
 
Old 07-21-2008, 07:39 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Deleted: I was wrong about something.

Last edited by David the H.; 07-21-2008 at 07:45 AM.
 
Old 07-21-2008, 07:45 AM   #3
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
Check file permissions.
 
Old 07-21-2008, 08:25 AM   #4
comm2k
LQ Newbie
 
Registered: Jul 2008
Posts: 28

Rep: Reputation: 16
Code:
ls -t -1 | tail --lines 1 | xargs -i mv {} targetfolder/
ls -t -1, ls and sort by time, output 1 item per line
tail, pick the last line
xargs, take output of tail (=filename) and run mv on it.

I would make a test directory with test files and extensively test it before using
 
Old 07-21-2008, 07:24 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
ls -rt|head -1
to get oldest file
 
  


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
delete oldest file in dir. by c program hitesh.sharma84 Linux - Kernel 1 05-02-2007 10:18 AM
Oldest distro .... mediolanum Linux - General 2 06-16-2005 04:29 PM
Help moving a file rajvirnijjar Linux - General 3 02-15-2005 09:21 AM
How OLD is your OLDEST Computer that you have right now? Nukem General 83 07-11-2004 02:34 PM
Oldest Configuration Bole General 15 07-24-2003 02:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:19 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