Linux “Find” Command And Its Usage

Search the file with the find command. Below command will search the file (named. conf) in the current directory and sub-directories.One more article on tech transit  for find command, you can also refer that for finding files and fodlers.

# find . -name "named.conf" -print

Note: -print option will print out the path of any file that meets the find criteria.

Find multiple ‘-exec’ options.

find / -name *.php" -exec echo {} \; -exec grep techtransit {} \;

find with -exec {} and a way to count the total files.

# find / -name "*.php" -exec chmod 755 {} \; -exec /bin/echo {} \; | wc -l

OR

We can add -print option to find, instead of executing “/bin/echo{}” like below.

# find / -name "*.php" -print -exec chmod 755 {} \; | wc -l

Move or copy files printed by ‘find’ command

find /path -type f -name "filename" | xargs cp -t /target_path

OR

find /path -name "filename"  -exec cp -rfp {} /destination_path  \;

About Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks!

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *