You are not logged in.

#1 2010-05-25 15:49:42

webofunni
Member
From: India
Registered: 2009-05-25
Posts: 53
Website

bash mv command question

Hi,

Can anybody explain what happens when we execute :

mv *

In a directory ?

I have tried that and found that it will move all files/directory to a sub directory. The target sub directory selection is seems to be based on the ascii order of the directory names. Not sure, if that it is. Tell me more, if know :-)

Offline

#2 2010-05-25 16:19:58

benob
Member
Registered: 2008-11-11
Posts: 187

Re: bash mv command question

Assuming bash uses glob() for converting * to a list of files, this function returns a sorted list from which mv uses the last element as target.

man 3 glob

Offline

#3 2010-05-25 16:24:52

lotuskip
Member
From: Finland
Registered: 2010-04-10
Posts: 22

Re: bash mv command question

You can test what mv actually sees:

echo *

Offline

#4 2010-05-25 16:38:05

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: bash mv command question

Look at the bash man page (search for 'Pathname Expansion') but I think (hope) that this is not the all things about bash globbing (because its so limited...).

If you can, look at zsh globbing (zshexpn man page), its really cool (you can set the order, insensitive globing, date ordered, custom true|false for each match using a external program, only match dir or sym links or files, files from only a certain user|groups, boolean glob (match all files but dont_rm_me) ) I dont know what bash can do... but the basic is in the bash man page.

Offline

#5 2010-05-25 17:31:21

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: bash mv command question

This experiment should show you how it works:

mkdir testdir
cd testdir
mkdir a b c d e
ls
echo *
mv *
ls
ls e
rmdir e/* e
touch a b c d e
ls
echo *
mv *

You can find more information in man 3 glob and man 1 mv.

Offline

Board footer

Powered by FluxBB