LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-07-2009, 02:50 AM   #1
scofiled83
Member
 
Registered: Nov 2008
Posts: 70

Rep: Reputation: 15
how to move files in a loop?


Hi


How can I move more than one files to new location?

Assume:

ls -lrt |more

-rw-rw---- 1 oracle dba 21906432 Feb 14 19:00 ab_0000001458_1.arc
-rw-rw---- 1 oracle dba 32099328 Feb 15 07:00 ab_0000001459_1.arc
-rw-rw---- 1 oracle dba 8423424 Feb 15 19:00 ab_0000001460_1.arc
...
...
...
-rw-rw---- 1 oracle dba 8423424 Feb 15 19:00 ab_0000001500_1.arc
...



I want to move the files between 1458 and 1500 to new location.
I tried this but didnt work.

for file in *{1458..1500}_*;
do
mv "$file" /ora/archives
done

Last edited by scofiled83; 05-07-2009 at 04:55 AM.
 
Old 05-07-2009, 03:37 AM   #2
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
Basically like this
Code:
for num in `seq 1458 1500`
do
    mv ab_*${num}.arc /ora/archives
done
 
Old 05-07-2009, 03:43 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
mv ab_*{1458..1460}*arc /destination
 
Old 05-07-2009, 03:58 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by scofiled83 View Post
Code:
for file in *{1458..1500}_*; 
do
  mv "$file" /ora/archives
done
This does not work because you put an extra underscore that does not appears in the file name (not in that position). The ghostdog's solution is more straightforward, anyway.
 
Old 05-07-2009, 04:02 AM   #5
scofiled83
Member
 
Registered: Nov 2008
Posts: 70

Original Poster
Rep: Reputation: 15
Hi
I tried it in current directory but error returned

mv ab_*{1450..1512}*arc /ora/archives

ab_*{1450..1512}*arc: cannot access: No such file or directory
 
Old 05-07-2009, 04:05 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by colucix View Post
The ghostdog's
sed 's/The//'
 
Old 05-07-2009, 04:06 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
@OP, then in those sequences, some of them is missing in your file names. (my guess)
 
Old 05-07-2009, 04:10 AM   #8
scofiled83
Member
 
Registered: Nov 2008
Posts: 70

Original Poster
Rep: Reputation: 15
no
I just checked them,
I even tried for two file, still same error message.
Hp Unix

Last edited by scofiled83; 05-07-2009 at 04:14 AM.
 
Old 05-07-2009, 04:18 AM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Quote:
Originally Posted by scofiled83 View Post
Hi
I tried it in current directory but error returned

mv ab_*{1450..1512}*arc /ora/archives

ab_*{1450..1512}*arc: cannot access: No such file or directory
You can't use the wildcard at the beginning like that as it won't know where to stop matching characters Try something along the lines of

Code:
mv ab_000000{1450..1512}.arc /ora/archives
 
Old 05-07-2009, 04:26 AM   #10
scofiled83
Member
 
Registered: Nov 2008
Posts: 70

Original Poster
Rep: Reputation: 15
Again the same:

ab_*{1450..1452}*arc: cannot access: No such file or directory.

By the way:

ls -lrt

-rw-rw---- 1 oracle dba 1564672 Feb 12 20:42 ab_0000001451_1.arc
-rw-rw---- 1 oracle dba 1675264 Feb 12 23:24 ab_0000001452_1.arc
-rw-rw---- 1 oracle dba 28751872 Feb 13 07:00 ab_0000001453_1.arc
-rw-rw---- 1 oracle dba 75577344 Feb 13 19:01 ab_0000001454_1.arc
..
..
..
..
..
..

Last edited by scofiled83; 05-07-2009 at 04:28 AM.
 
Old 05-07-2009, 05:01 AM   #11
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Are you using bash? And is brace expansion enabled as well as pathname expansion? What do you see when you do:

Code:
echo ab_000000????*.arc
?
 
Old 05-07-2009, 05:13 AM   #12
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
Silently editing your original post to change the filenames you listed is a little on the disingenuous side. You've effectively made everyones responses to you look wrong, when based on the information you originally provided, they weren't. Making people who take the time to try and help you look stupid is bad form.
 
Old 05-07-2009, 05:28 AM   #13
scofiled83
Member
 
Registered: Nov 2008
Posts: 70

Original Poster
Rep: Reputation: 15
You are right Gazl
I appreciate your help.
I made a mistake.
then I correct it, I am truly sorry,
and
even it doesnt help, I appreciate your help
 
Old 05-07-2009, 05:43 AM   #14
amysaraantony
Member
 
Registered: Apr 2009
Posts: 42

Rep: Reputation: 16
I believe using SED is the need of the hour!


Debian

Last edited by amysaraantony; 05-15-2009 at 08:16 PM.
 
Old 05-07-2009, 07:25 AM   #15
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by konsolebox View Post
Are you using bash? And is brace expansion enabled as well as pathname expansion?
@konsolebox, you hit the nail on the head.

@scofiled83, what is the output of
Code:
echo $-
this will tell you which options are set in the current shell. Also the "extended brace expansion" is a feature introduced in bash version 3. It does not work in older versions.
 
  


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
loop through directories and move files ratcateme Programming 7 11-18-2008 02:33 AM
moving files from a location to other, preventing to move incomplete files pogo123 Programming 8 11-14-2008 06:21 AM
moving files from a location to other, preventing to move incomplete files pogo123 Linux - Newbie 2 11-13-2008 01:57 PM
loop move files up one directory level Melsync Programming 8 12-19-2005 10:51 PM

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

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