LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2008, 05:17 AM   #16
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17

can i put the shell script in one line...
something like this

Quote:
for f in `ls -tr /projects/ilinterf/john/expect/backupdir/testtest/*.txt`;do mv $f /projects/ilinterf/john/expect/backupdir done

 
Old 07-19-2008, 02:08 AM   #17
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
Sure you can. But there is no semicolon (';') before 'done' keyword in your script.
And, as I've mentioned before, you need to qualify the full path before the variable $f in mv command.
So, exact one-line command is:
Code:
for f in `ls -tr /projects/ilinterf/john/expect/backupdir/testtest/*.txt`;do mv /projects/ilinterf/john/expect/backupdir/testtest/$f /projects/ilinterf/john/expect/backupdir; done
 
Old 07-19-2008, 02:15 AM   #18
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You don't need to run ls in the for loop. You can just do

Code:
for file in directory/*.txt
do
  mv $file other directory
done
where directory and other directory are to be replaced with the relevant directories.

Last edited by Nylex; 07-19-2008 at 02:16 AM.
 
Old 07-20-2008, 12:35 PM   #19
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
Nylex, the final result is the same. But john83reuben has asked about moving files in the creation order (post #4 in this thread). This is the only reason for using ls command.
I have no idea why John needs exactly this way, whereas this quesion was asked already.
 
Old 07-20-2008, 01:02 PM   #20
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
I think the OP is interested in how they look when he is all done moveing them to the backup directory.
If after moving the files to the destination the OP does
Code:
ls -lrt
he will be looking at a list of files in date sorted order.
 
Old 07-20-2008, 01:20 PM   #21
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I don't get the point of trying to move the files in
a given order in the first place ... what's the rationale
behind this? If you `mv' files they keep their original
time-stamp, so will be "sorted" in that way anyway if
you so wish.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
My error in mkisofs command to make a command line iso mg92865 Linux - Newbie 1 06-20-2008 11:43 AM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM


All times are GMT -5. The time now is 10:11 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration