LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-22-2008, 11:37 AM   #1
Eusaphious
LQ Newbie
 
Registered: Jul 2008
Location: DFW / Texas
Distribution: Gentoo
Posts: 3

Rep: Reputation: 0
typo in move command - files gone now?


So I was moving some files from one drive to another and made a small typo.

Code:
zero@MythBox ~ $mv -v /media/Software/* /media/Documents/Software/*
I didn't mean to type the extra * after the destination directory but didnt notice it till after the move completed. What happened to those files as there not in the destination directory or source directory??
 
Old 07-22-2008, 01:18 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
"*" is a wildcard which essentially matches whatever it can find. I just did a test: I sent some files to dir1/dir2/* (dir2 was empty). The mv command reported (correctly) that dir1/dir2/* did not exist.
I then created a new directory ("new") in dir2. After issuing the mv command as before, the files appeared in dir1/dir2/new.

What happens when the target directory has more than 1 sub-dir? I tried the same thing with TWO directories and it moved the files into one, and then moved the other directory in there also. I will have to think about why......

Meanwhile, what all this tells me is that your files are in a subdirectory in /media/Documents/Software/
 
Old 07-22-2008, 01:27 PM   #3
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
All the expansion is done by the shell before it starts mv. Therefore, if the target directory has more than one subdirectory, mv will see:

mv x y z dir/sub1 dir/sub2 targ/dir1 targ/dir2

and it will happily move everything but the last argument into targ/dir2 if it is a directory, and present an error if it is not.

What is the output of:

ls -Fl /media/Documents/Software
 
Old 07-22-2008, 01:29 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by pixellany View Post
What happens when the target directory has more than 1 sub-dir? I tried the same thing with TWO directories and it moved the files into one, and then moved the other directory in there also. I will have to think about why......
The point is not the target directory having more than 1 sub-dir. The points is: when multiple files or directories are passed to the move command, only the last one is considered the destination directory. The other ones are sources, e.g. file or directories that are going to be moved.

The OP's command line expanded the wildcards and only the last argument is the destination. If it was a directory, all sources were moved to that directory, if it was a file the shell would have spit out an error message like: "mv: target `something' is not a directory.

Quote:
Meanwhile, what all this tells me is that your files are in a subdirectory in /media/Documents/Software/
Correct.

Last edited by colucix; 07-22-2008 at 01:31 PM.
 
Old 07-22-2008, 01:45 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by colucix View Post
The point is not the target directory having more than 1 sub-dir. The points is: when multiple files or directories are passed to the move command, only the last one is considered the destination directory. The other ones are sources, e.g. file or directories that are going to be moved.
Exactly---I realized this after typing the last message. I can imagine some real mind-bending puzzles using several wildcards...

Here's what is non-obvious: Suppose I have the following:

Code:
$HOME
    file1
    file2
    dir1
        dir2
            dir3
            dir4

Issue command:  mv fil* dir1/dir2/*

This gets expanded to:  mv file1 file2 dir1/dir2/dir3 dir1/dir2/dir4
As you said, the first 3 all wind up in the fourth...
 
Old 07-22-2008, 03:01 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Where it gets really confusing for new users is if the source or target directories contains whitespace

mv x y z dir/* targ/*

where targ contains "a dir" and there is a ./dir in the current working directory of the mv command.
 
Old 07-23-2008, 04:50 AM   #7
Eusaphious
LQ Newbie
 
Registered: Jul 2008
Location: DFW / Texas
Distribution: Gentoo
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the explanations guys.

I did manage to find the files in a subdirectory inside software/.
 
  


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 On
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
How do I move files without overwrite exitng files? nadavvin Linux - General 10 11-03-2006 02:49 PM
Lost access to windows partition, due to typo in command anubis26 Linux - General 24 08-10-2006 07:51 PM
Typo in the LQ rules Nylex LQ Suggestions & Feedback 1 07-18-2006 07:33 AM
Command to select and move mutiple files from list in text file steve.paris Linux - Newbie 11 11-27-2005 12:44 PM


All times are GMT -5. The time now is 09:04 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration