LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 01:18 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Rep: Reputation: 17
mv command


how to move files from a directory to another directory in sequence order. Any ideas??

John
 
Old 07-18-2008, 01:41 AM   #2
nawuza
Member
 
Registered: Jan 2007
Location: High Castle
Distribution: FC8
Posts: 66

Rep: Reputation: 15
Wink

example

mv /var/www/html/mysite/index.php /home/user/Desktop
 
Old 07-18-2008, 01:54 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
You need to define 'sequence order'.
 
Old 07-18-2008, 02:03 AM   #4
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
yea...i mean. i will copy certain files into a directory, and then that files should be moved into a backup directory according to the date of creation.. the oldest 1st..pls help
 
Old 07-18-2008, 02:18 AM   #5
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
If you mean just sorting files and moving exactly in that order, try this:
Code:
for f in `ls /your/dir/*.mp3 | sort -n`
do
  mv $f /new/dir/
done
This moves all your mp3 files from /your/dir to /new/dir in numerically sorted sequence.
Is it sort of what you need?
 
Old 07-18-2008, 02:22 AM   #6
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
something like that, but the files moved to the backup dir should be moved according to the date creation..it means the oldest files will be moved 1st into the backup directory
 
Old 07-18-2008, 02:58 AM   #7
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
Try this:
Code:
for f in `ls -tr`
do
  mv $f /new/dir/
done
 
Old 07-18-2008, 03:10 AM   #8
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
i did this,

Quote:

#!/bin/ksh

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

it gives this error

mv: cannot access ls
mv: cannot access -tr
mv: cannot access /projects/ilinterf/john/expect/backupdir/*.txt


y is that ??
 
Old 07-18-2008, 03:17 AM   #9
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
You should use back quota marks - `` not '' (the same key as '~')
 
Old 07-18-2008, 03:19 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
Alternatively

for f in $(ls -tr /projects/ilinterf/john/expect/backupdir/*.txt)
 
Old 07-18-2008, 03:20 AM   #11
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
In your case actually, you need to add a path before the var $f:

mv /projects/ilinterf/john/expect/backupdir/$f /projects/ilinterf/john/expect/backupdir/testtest
 
Old 07-18-2008, 03:31 AM   #12
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
so wil this move the files in sequence order. But it looks like its just moving files, but not in date sequence..am i right
 
Old 07-18-2008, 03:42 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Indeed, it is not really clear what you are trying to do. Moving a bunch of files to another directory in a certain sequence is a non-sense (once you've moved all of them the result is the same, despite the order they have been moved), unless you want to process each of them before moving the next one. Maybe you are trying to move the files and have them stored in a certain order, or better... you want to list them based on the modification time, right?

The aforementioned -t option, in conjunction with -r, can list them in time order. But if you want them sorted both in time and alphabetical order you have to rename them inserting the date.
 
Old 07-18-2008, 03:59 AM   #14
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 132

Original Poster
Rep: Reputation: 17
Quote:

#!/bin/ksh

for f in `ls -tr /projects/ilinterf/john/expect/backupdir/testtest/*.txt`
do
mv $f /projects/ilinterf/john/expect/backupdir
done
in this code, for f in means is it

Quote:

while {$f = `ls -tr /projects/ilinterf/john/expect/backupdir/testtest/*.txt`}

{
mv $f /projects/ilinterf/john/expect/backupdir

}
tis is in tcl, ist something like tat
 
Old 07-18-2008, 04:15 AM   #15
Vit77
Member
 
Registered: Jun 2008
Location: Toronto, Canada
Distribution: SuSE, RHEL, Mageia
Posts: 132

Rep: Reputation: 17
I can't say about tcl, but in bash terms it means:

Sort all the files by the date. Then assign the first filename to the variable f and to do the loop's body (perform moving for chosen file).
Then take the next filename, and so on for each file in the list.

The script moves all the files one-by-one in date order. Isn't it what you asked for?
If no, please explain your purpose.
 
  


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 01:19 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