[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6118: [Expert] Bug in mv?

From: Anthony
Subject: bug#6118: [Expert] Bug in mv?
Date: Thu, 06 May 2010 00:20:47 +0100
User-agent: Thunderbird (Windows/20100228)

I tried to "mv amanda* /home/amanda/*" as root and which which I
recall I have done successfully several times before.
The shell expand * _before_ passing the args to mv. So mv saw all files starting with 'amanda' and all files (besides . hidden ones)
in /home/amanda/ as arg.  It then picked the last one listed
(probably /home/amanda/tmp/) as destination.

Hi Gene,

As the others say, the behaviour you describe is exactly what one would expect mv to do with the arguments passed to it.

I had two files whose names started with amanda in that directory.  I
would have assumed it would expand the src pattern of "amanda*" to
match only those two files.  And the rest of the files in /home/me,
weren't bothered.  No damages to the src directory at all other than
removing the files.

The shell would have expanded two filenames as the first two arguments (separated by a space) to the mv command.

If it expanded that * to include the whole thing, it should have
moved the whole thing.  It didn't.  In past experience, the target
path spec's /* has always served as just a place holder for the
filenames actually selected by the amanda* in the src spec.  That is
not what it did this time.  This time it created a tmp/ directory in
/home/amanda, moved the whole amanda tree to the tmp directory,
including the two files I actually asked it to move from /home/me/Download. No loss, but a very surprised veteran linux user.

As other posters pointed out /home/amanda/* expands to a listing of every non-hidden (name doesn't start with a dot) file in /home/amanda. mv doesn't treat the results of the two wildcard expansions any differently. It simply always treats the very last argument as the destination directory. In this case /home/amanda/tmp had already been created by some other process and just happened to be the last filename to be expanded by the shell. (Had the last filename been an ordinary file and not a directory, mv would have given you an error.)

Just to note: /home/amanda/* will expand very differently to /home/amanda* Most likely /home/amanda* would simply expand to /home/amanda - unless you have other directories such as /home/amanda.1 or /home/amanda.bak

For my own part when I'm not exactly sure how wildcards will be expanded in a certain context, I'll substitute "echo" instead of the command name. e.g. echo amanda* /home/amanda/* would show you what arguments are being passed to the command.

I also sometimes use the -i option for mv and rm commands so that I'm prompted yes or no for each file action and I almost always use the -v option so that I can see what the command is doing as it operates.

Best regards,
Anthony G

reply via email to

[Prev in Thread] Current Thread [Next in Thread]