LinuxQuestions.org
Latest LQ Deal: Linux Power User 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 10-02-2008, 12:03 PM   #1
looklikewolf
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
Hello; where do I post my quesiton?


Hello, I am a nOOb here. Whew! With that said, I'd like enter my first post here.

My question is about where to post. I have a question about the usage of the mv command. Should I post it here or should I post it in "Linux-General"?

Thanks for the help.
looklikewolf
 
Old 10-02-2008, 12:07 PM   #2
GazL
Senior Member
 
Registered: May 2008
Posts: 4,087
Blog Entries: 1

Rep: Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535
Welcome to LQ.

Well, as you've made this thread already, why not ask your question here. (in this case, I think either forum would have been a valid choice)
 
Old 10-02-2008, 12:31 PM   #3
looklikewolf
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
My qustion about the mv command:

I would like to know if there is a way to move multiple files to multiple directories in one step.

i.e.
I have
hw2_1.java
hw2_1.class
hw2_2.java
hw2_2.class
hw2_3.java
hw2_2.class
hw2_4.java
hw2_4.class
Circle_4.java
Circle_4.class
~/part1
~/part2
~/part3
~/part4

I would like to move *_1.* into dir part1
and *_2.* into dir part2
and *_3.* into dir part3
and *_4.* into dir part4

is there a one step command to complete this task?

I know if I use
mv *_2.* part2

this will move these files into dir part2. Is there a way to pipe or chain these commands together? How about a way to character match? Say all files that are *_x.* are to be put into partx, 'x' being the arbirtary character.

Thanks
looklikewolf
 
Old 10-02-2008, 12:36 PM   #4
mrrangerman
Member
 
Registered: Oct 2007
Location: MI
Distribution: Debian Slackware
Posts: 528

Rep: Reputation: 50
Open a terminal and type man mv and you will get the manual page for the mv command. You can also check out all the other commands this way.
 
Old 10-02-2008, 12:47 PM   #5
looklikewolf
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by mrrangerman View Post
Open a terminal and type man mv and you will get the manual page for the mv command. You can also check out all the other commands this way.
This is what I found in the man page for the 'mv' command. I don't see a switch for multiple files into multiple directories. Maybe I don't know how to read the man page? Please help.

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options
too.

--backup[=CONTROL]
make a backup of each existing destination file

-b like --backup but does not accept an argument

-f, --force
do not prompt before overwriting

-i, --interactive
prompt before overwrite

--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument

-S, --suffix=SUFFIX
override the usual backup suffix

-t, --target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY

-T, --no-target-directory
treat DEST as a normal file

-u, --update
move only when the SOURCE file is newer than the destination
file or when the destination file is missing

-v, --verbose
explain what is being done

--help display this help and exit

--version
output version information and exit

The backup suffix is `~', unless set with --suffix or SIM-
PLE_BACKUP_SUFFIX. The version control method may be selected via the
--backup option or through the VERSION_CONTROL environment variable.
Here are the values:

none, off
never make backups (even if --backup is given)

numbered, t
make numbered backups

existing, nil
numbered if numbered backups exist, simple otherwise

simple, never
always make simple backups
 
Old 10-02-2008, 02:30 PM   #6
GazL
Senior Member
 
Registered: May 2008
Posts: 4,087
Blog Entries: 1

Rep: Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535Reputation: 1535
mv will only move multiple things to a single location so no, there's no single command you can run to do what you want.

You could script it though with a for loop. something like:

Code:
for number in 1 2 3 4
  do 
    mv "*_${number}.*" ~/part${number}
  done
Be careful with the wildcards though as those above are quite loose and could possibly get false matches depending on what your file names look like. (note: I added the . after the number to tighten them a little)

If its something you'll be running often you could put this into a function definition in your .bashrc and then you could just call it by name as if it was a single command.

If you've only got a few numbers though its probably best just to use command history to pull up the last command, edit it and move them number by number.


When you get a chance, I'd recommend a good read of the man on bash or google for some bash programming tutorials. A good working knowledge of bash will stand you in good stead for years to come.

Hope that was of some help. Have fun...

G.
 
Old 10-02-2008, 02:37 PM   #7
looklikewolf
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you G for the answer. It is great. I will put some time into 'man bash' and do some google searches on bash. This points me in the right direction. Thanks.

l_l_w

QUESTION IS ANSWERED AND THREAD CAN BE CLOSED
THNX
 
Old 10-02-2008, 07:45 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
You may find these links worth bookmarking:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
Old 10-02-2008, 09:53 PM   #9
muasif80
Member
 
Registered: Oct 2008
Posts: 54

Rep: Reputation: 15
You can also put the 4 commands in a file and then execute that file as below

shell> vi movefiles

The above command will open the vi editor. Use i command to enter the insert mode of vi editor and put the commands in the following format on separate lines. Then use :wq to save and quit from vi editor. You will get back to the shell prompt like below

mv file1 dir1
mv file2 dir2
mv file3 dir3
mv file4 dir4

shell>

On shell you should use the following command to make the file movefiles as executeable

shell> chmod +x

Now you just have to write

shell> ./movefiles

This will execute the four lines of code in the movefiles file and your task will be done.

Thanks
Asif
 
Old 10-03-2008, 12:44 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Quote:
Then use :wq to save and quit from vi
of course using write and quit cmds is shorter if you just use
:x

x =save+exit in one cmd
 
Old 10-04-2008, 04:39 AM   #11
muasif80
Member
 
Registered: Oct 2008
Posts: 54

Rep: Reputation: 15
Thanks to you. I did not know this.
 
Old 10-05-2008, 09:33 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Seems to be a 'cargo-cult' thing. I don't know how it got started though...
 
  


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
locale quesiton satimis Ubuntu 0 08-28-2007 08:55 AM
Hi, one quesiton! malc Linux - Newbie 7 12-01-2005 03:20 AM
KUDZU quesiton waelaltaqi Linux - General 1 10-05-2005 04:15 PM
Shells Quesiton lamar_air Linux - Newbie 15 01-28-2005 08:07 PM
Quesiton regarding Xinetd Ghost of War Linux - Security 1 04-20-2004 06:57 PM


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