Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this folder that contains many folders, each containing many files with the name structure

I'd like to rename them (using bash) to (i.e. un-hide them).

I've seen a question attempting to do a similar thing,

alias deannoy='for annoyingbak in *.bak;do mv "$annoyingbak" ."$annoyingbak";done'>> ~/.bashrc && . .bashrc

but I've not been able to manage to change so it's done recursively for all folders down from the current folder.

share|improve this question
up vote 2 down vote accepted

The for ... in *.bak command searches only the current directory.

You want instead to use the find command, which searches recursively. This command will locate all zip files starting with a dot at any depth in the current directory (.).

find . -iname '.*.zip'

Removing the leading dot is a bit trickier though. The following seems to work (but may have edge cases, caveat emptor).

for f in $(find -iname '.*.zip'); do f2=$(echo $f | sed -re 's/(.*)\/\.(.*)/\1\/\2/'); echo $f $f2; done

This will print all the operations it would perform (echo $f $f2), if this list looks right change it to mv $f $f2 and it will do the renames.

share|improve this answer
this is my personal favorite (but i can't try it now, the computer on which the files reside is busy....): simplest [also good that it we can do a dry run] – user2413 Oct 19 '12 at 13:26

There is a good answer on sister-site stackoverflow: It says:

recurse() {
 for i in "$1"/*;do
    if [ -d "$i" ];then
        echo "dir: $i"
        recurse "$i"
    elif [ -f "$i" ]; then
        echo "file: $i"

recurse /path

OR if you have bash 4.0

shopt -s globstar
for file in /path/**
    echo $file

Say thank you over at stackexchange to ghostdog74 if this works for you. The askubuntu account will work there too.

share|improve this answer

You can use this command:

$ find foobar/ -type f -iname ".*" -exec rename -n 's/^(.+)\/\.(.+)$/$1\/$2/' '{}' \;

foobar/sub_dir/moresubdir/.foo renamed as foobar/sub_dir/moresubdir/foo
foobar/sub_dir/moresubdir/ renamed as foobar/sub_dir/moresubdir/
foobar/sub_dir/moresubdir/ renamed as foobar/sub_dir/moresubdir/
foobar/sub_dir/ renamed as foobar/sub_dir/
foobar/sub_dir/ renamed as foobar/sub_dir/
foobar/.foo renamed as foobar/foo
foobar/ renamed as foobar/
foobar/ renamed as foobar/

find will recursively search for all hidden files then pass them to rename. The -n param causes rename to dry-run the substitution rule to show you what those files would be renamed to. If you're happy with the results, remove the param so it renames the files for real

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.