LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command MV */* (https://www.linuxquestions.org/questions/linux-newbie-8/command-mv-%2A-%2A-865976/)

numlock01 03-02-2011 09:31 AM

Command MV */*
 
What will command MV */* do exactly.

MV is for move, but the asterisk in this case does what?

Thanks

AlucardZero 03-02-2011 10:21 AM

http://tldp.org/LDP/abs/html/globbingref.html

but "mv */*" is not a valid command: there are too few arguments.

MensaWater 03-02-2011 11:06 AM

* = match all characters
? = match a single character

So */* implies you are moving all files in all directories below the one you were sitting in when you executed the command.

However the "mv" command requires a target not just a source - typing "mv */*" ideally would do nothing - worse it might try to expand so that the first file it finds is moved to the second one (thereby overwriting it).

Also it is NOT "MV" it is "mv". Linux is case sensitive which means MV, mV, Mv, and mv are all different. By default Linux will have "mv" for (move which is also used to rename) but not MV, mV, or Mv - however if you happened to have something by the name MV in your PATH it would execute that instead of the "mv" command you intended.

To mv multiple files it is best to do something like:

mv $(*/*) <newdir>
That would move all the files in subdirectories of the current directory into whatever directory you specified. (The new directory would need to extist first.)
e.g.
mv $(*/*) /testdir
Would move the files into /testdir (assuming it existed - otherwise it might try to rename each file to "/testdir" so that only the last file in your list actually was there - since it is mv your originals would all be gone.

Using "*" in commands like mv and rm should be done carefully because you can end up blowing away lots of files without meaning to do so. For example since "*" doesn't match dot files (e.g. .bashrc, .bash_profile, .mozilla) many a user has made the mistake of doing something like "rm .*" to try to remove those files. This is a problem because every UNIX/Linux directory should have an entry called ".." which is a link the parent directory. Since ".." would be matched by ".*" the rm command would actually remove the parent directory's files rather than the just the dot files in the current directory.

numlock01 03-10-2011 04:28 AM

Thanks guys


All times are GMT -5. The time now is 08:39 PM.