find magic: recursive delete and chmod

You can do a lot of cool things with find combined with the -exec parameter:

  • recursive chmod of only directories
    find . -type d -exec chmod 755 {} \;
  • recursive chmod of only files
    find . -type f -exec chmod 644 {} \;
  • recursive delete of all txt files
    find . -name '*.txt' -exec rm {} \;

(edited due to popular demand.)

  • email
  • PDF
  • Google Bookmarks
  • Yahoo! Bookmarks
  • del.icio.us
  • Twitter
  • Reddit
  • Digg
  • Ping.fm
  • Slashdot
  • Facebook
  • MySpace
  • Technorati
  • NewsVine
  • Tumblr
  • StumbleUpon

2 Responses to “find magic: recursive delete and chmod”

  1. hell writes:

    *.txt escapen nicht vergessen.

    Also entweder:

    find . -name \*.txt -exec rm {} \;

    oder:

    find . -name ‘*.txt’ -exec rm {} \;

  2. raoul writes:

    sorry that i must now correct you…

    we build se directory lik thiz:

    $ find
    .
    ./mysql.txt
    ./la
    ./la/mysql1.txt

    now me make tha find:
    $ find . -iname mysql*
    ./mysql.txt

    ups … now we know, that bash makes:
    $ find . -iname mysql*
    to
    $ find . -iname mysql.txt

    ok, got it mate? :) of course, if there is no file/directory matching your expression in $PWD, it operates as “expected”.

    cheers,

    ps: GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu); debian etch

Leave a Reply