LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   typo in move command - files gone now? (https://www.linuxquestions.org/questions/linux-general-1/typo-in-move-command-files-gone-now-657459/)

Eusaphious 07-22-2008 11:37 AM

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??

pixellany 07-22-2008 01:18 PM

"*" 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......:confused::confused::confused:

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

Mr. C. 07-22-2008 01:27 PM

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

colucix 07-22-2008 01:29 PM

Quote:

Originally Posted by pixellany (Post 3222844)
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.

pixellany 07-22-2008 01:45 PM

Quote:

Originally Posted by colucix (Post 3222857)
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...

Mr. C. 07-22-2008 03:01 PM

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.

Eusaphious 07-23-2008 04:50 AM

Thanks for the explanations guys.

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


All times are GMT -5. The time now is 02:43 PM.