-   Linux - General (
-   -   bash: mv hidden and not hidden files (

lupe 06-22-2009 10:32 AM

bash: mv hidden and not hidden files

I have these files:
$ ls -a
. ..

Two hidden and three not hidden files.
I want to rename all of them whith an extension '.a' for example.

if I do:
$ for f in *.zip; do cp $f $f.a; done
$ ls -a
. ..

Only the not hidden files were renamed.

$ for f in .*.zip; do cp $f $f.a; done
$ ls -a
. ..

Only the hidden files were renamed.

I tried to issue:
$ for f in .?*.zip; do cp $f $f.a; done and some derivations of the ? as in regular expressions, but couldn't achieve what I want.
How can I do it?


druuna 06-22-2009 11:18 AM


This works:

for f in .*zip *zip; do .....

Hope this helps.

pixellany 06-22-2009 11:28 AM

don't rename "." and ".." !! These are the shorthand for "here" and "one up". I don't know what happens if they are re-named...or even if you can.

colucix 06-22-2009 12:19 PM

The solution suggested by druuna is the answer to the question. FYI, dotglob is a shell option that controls the behavior of globbing, allowing the expansion of hidden files. You can toggle it using the shopt built-in:

$ shopt -s dotglob
$ ls *
$ shopt -u dotglob
$ ls *

Furthermore, as you can see, it does not expand . and ..

lupe 06-22-2009 02:27 PM

The more I know, the more I like it!

Thanks for the answers!


All times are GMT -5. The time now is 07:46 PM.