Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Maybe some one have tool script (perl or shell script) that rename files names or directory names?

For example

The tool needs to read from the file as the following:

   more file

   /var         Local      exportlocal
   /etc        data         Data
  1. The first field $1 – directory name to search under this directory

  2. Second field – the name of the file/dir that need to search

  3. Third field – the name of the new file/dir that need to rename

Real example (before running the tool)


Real example (after we run the tool)

share|improve this question
up vote 0 down vote accepted

Assuming that the file is whitespace-delimited (tabs and/or spaces between the fields and newlines ending each record) and that the file and directory names don't contain those characters:

while read -r branch oldname newname
    find "$branch" -depth -name "$oldname" -exec sh -c 'mv "$1" "${1%/*}/$2"' _  {} "$newname" \;
done < file-with-names


Change the find command as follows to output a message for each file that is renamed:

    find "$branch" -depth -name "$oldname" -exec sh -c 'mv "$1" "${1%/*}/$2"; echo "$1 was renamed to $2 under $3"' _  {} "$newname" "$branch" \;
share|improve this answer
hi Dennis thanks for your great support , I wander if it possible to add message to the user each time that file/dir was update (example - by echo "$oldname was update under directory: /dir1/dir2/dir3...) – klod Jan 24 '11 at 16:02
@klod: Please see my edited answer. – Dennis Williamson Jan 24 '11 at 16:28

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.