LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash: mv hidden and not hidden files (http://www.linuxquestions.org/questions/linux-general-1/bash-mv-hidden-and-not-hidden-files-734777/)

lupe 06-22-2009 10:32 AM

bash: mv hidden and not hidden files
 
Hi,

I have these files:
$ ls -a
. .. a.zip b.zip .c.zip .d.zip e.zip

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
. .. a.zip a.zip.a b.zip b.zip.a .c.zip .d.zip e.zip e.zip.a

Only the not hidden files were renamed.


With:
$ for f in .*.zip; do cp $f $f.a; done
$ ls -a
. .. a.zip b.zip .c.zip .c.zip.a .d.zip .d.zip.a e.zip

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?


Luis

druuna 06-22-2009 11:18 AM

Hi,

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:
Code:

$ shopt -s dotglob
$ ls *
a.zip  b.zip  .c.zip  .d.zip  e.zip
$ shopt -u dotglob
$ ls *
a.zip  b.zip  e.zip

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!

Luis


All times are GMT -5. The time now is 07:04 AM.