In the Linux ecosystem, finding and managing files is made easy with the “Find” command. This utility helps you locate files and directories effortlessly. Let’s take a simple and clear look at how to use this utility command for various tasks on your Linux system.

The below command will search the file (named. conf) in the current directory and sub-directories. One more article on tech transit for command, you can also refer to that for finding files and folders.

What is the “Find” Command?

This utility is like a search process for your Linux system. It helps you search files based on specific conditions, making it a handy tool for file management.

Finding Files by Name:

If you’re looking for a particular file, say “named. conf,” you can use:

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

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

Finding Directories:

To locate directories instead of files, you can use:

find /path/to/search -type d

To search multiple ‘-exec’ options.

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

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 -a print option, instead of executing “/bin/echo{}” like below.

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

Move or copy files printed by the below command

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

OR

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

Executing Commands on Found Files:

It allows you to take action on the files it explores. To copy log files, the Below command is an example of search log files and copy into srv folder , you can use exec with copy, remove, and with other utilities.

find /path/to/search -name "*.log" -exec cp {}  /srv  \; 

This command filters and deletes files with the “.log” extension.

This utility command is a friendly assist for exploring your Linux files. Whether you’re a Linux pro or a beginner, the command makes searching and managing files a breeze.

Play around with these commands, customize your searches, and discover how the “find” command can be your trusty companion in Linux. It’s not just a command; it’s your ticket to efficient and stress-free file exploration.

By 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! Sachin G Follow me on LinkedIn and x formerly twitter