LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-22-2009, 09:32 AM   #1
lupe
Member
 
Registered: Dec 2008
Distribution: Slackware
Posts: 36

Rep: Reputation: 2
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
 
Old 06-22-2009, 10:18 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

This works:

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

Hope this helps.
 
Old 06-22-2009, 10:28 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
Old 06-22-2009, 11:19 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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 ..
 
Old 06-22-2009, 01:27 PM   #5
lupe
Member
 
Registered: Dec 2008
Distribution: Slackware
Posts: 36

Original Poster
Rep: Reputation: 2
The more I know, the more I like it!

Thanks for the answers!

Luis
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hidden Linux/GNU/Bash gems for the self learner? randomsel Linux - General 1 06-26-2008 06:34 PM
Bash scripting problem: Can't get a list of all files, including hidden ones oxi Programming 24 03-12-2007 06:19 AM
Hidden Files coold8 Linux - General 5 04-27-2005 11:26 PM
hidden files Alwyn Linux - Newbie 2 01-27-2005 12:20 AM
Hidden Files Alien18 Linux - Newbie 4 08-12-2004 09:38 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration