Home > linux, programming > How to use ‘find’ in file

How to use ‘find’ in file

January 7th, 2010

Linux has many usefull command.

I always use this command to find a single file

find . | grep filename

But it’s not a really good implementation to how to use the syntax. For search file name, use this command instead.

find -name filename
find -name "you can event use a wildcard *"

For directory you can write like this

find -type d

For find only file

find -type f

Together joined will be

find -type f -name "rick*"

And the most useful syntax, you can run a command on every file it found. Here’s how to delete every jpg it found.

find -type f -name "*.jpg" -exec rm {} \;

Or upgrade all bzr in every directory

find -type d -maxdepth 1 -exec bzr update {} \;

Hope it helps


linux, programming

  1. No comments yet.
  1. No trackbacks yet.

Switch to our mobile site