Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-18-2008, 06:17 AM   #16
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

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, 03:08 AM   #17
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:
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, 03:15 AM   #18
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

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

Last edited by Nylex; 07-19-2008 at 03:16 AM.
Old 07-20-2008, 01:35 PM   #19
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, 02:02 PM   #20
john test
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
ls -lrt
he will be looking at a list of files in date sorted order.
Old 07-20-2008, 02:20 PM   #21
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.


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 08:19 PM
My error in mkisofs command to make a command line iso mg92865 Linux - Newbie 1 06-20-2008 12:43 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 07:02 AM
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-04-2008 12:18 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM > Forums > Linux Forums > Linux - Newbie

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

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