LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, FreeBSD, NetBSD, Haiku
Posts: 64

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: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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, FreeBSD, NetBSD, Haiku
Posts: 64

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

Thanks for the answers!

Luis
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration