Friday, October 30, 2009

Using the find command

  • In one case, I need to rename a bunch of files from upper case to title case (only the first letter of the file name is capitalized). For exmaple, AAA.C --> Aaa.c and ABC.C --> Abc.c

    This can be done with find and perl in the following manner:
    find . -maxdepth 1 -type f -execdir perl -e 'rename substr($_,2),ucfirst(lc(substr($_,2))) for @ARGV' '{}' \;

    Useful reference: How to rename to lowercase every file in a directory and its subdirectories?
  • How to check whether the contents of a directory is newer than 10-day old: I used the following command
    find /home/user -maxdepth 2 -mtime -10 -print -quit
    It will search the path /home/user and one level below that for anything that's newer than 10-day old and quit after a match is found.

No comments: