PDA

View Full Version : Rename multiple hidden files




ampires
Nov 13, 2010, 01:36 PM
I was given a folder with around a thousand files in it to work on from someone on windows. When I open the folder there are no files. I figured out that the windows program named them all beginning with a period, which makes them hidden in mac. I am trying to use a shell script to add a letter at the beginning of all of them so I can see them.

I've been using this code with the directory with the hidden files as cd:
for i in .*; do mv "$i" "x$i"; done;

i'm trying to add an x to the beginning, but its not working.

If anyone has experience with hidden files it would be appreciated



chown33
Nov 13, 2010, 02:43 PM
Remember that the directories "." and ".." match the pattern. You will not be able to rename these.

Personally, I'd use the 'find' command, because it has tests like "is a file", and logical predicates. It would be perfectly capable of execing a 'mv' command.

And you should probably look into why the filenames all start with ".", unless you know for certain it's just a quirk of the programmer. Dotted filenames suggest something unexpected, which might be something like an archival format, a source-code control system, etc.

balamw
Nov 13, 2010, 02:49 PM
I was given a folder with around a thousand files in it to work on from someone on windows. When I open the folder there are no files. I figured out that the windows program named them all beginning with a period, which makes them hidden in mac. I am trying to use a shell script to add a letter at the beginning of all of them so I can see them.

I've been using this code with the directory with the hidden files as cd:
for i in .*; do mv "$i" "x$i"; done;

i'm trying to add an x to the beginning, but its not working.

If anyone has experience with hidden files it would be appreciated

ls -a within terminal will show hidden files to see if that is really your problem.

You might also want to look at the man page for find. (EDIT:chown33 beat me to it)

B