Unix command to find a file in a directory and subdirectory

Unix command to find a file in a directory and subdirectory

To find a file in a directory and its subdirectories in Unix, you can use the find command.

For example, to find a file called myfile.txt in the /home/user directory and its subdirectories, you can use the following command:

re‮ot ref‬:lautturi.com
find /home/user -name myfile.txt

This will search the /home/user directory and all its subdirectories for a file called myfile.txt and print the full path to any files that are found.

You can use the -type option to specify the type of file you are looking for. For example, to find only regular files (not directories or other special types of files), you can use the following command:

find /home/user -type f -name myfile.txt

You can also use the -exec option to execute a command on the files that are found. For example, to delete all files called myfile.txt that are found, you can use the following command:

find /home/user -name myfile.txt -exec rm {} \;

The find command is a powerful and versatile tool for finding files in Unix.

Created Time:2017-10-30 14:27:30  Author:lautturi