Linux / Unix: Bash Find Matching All Dot Files

Linux / Unix: Bash Find Matching All Dot Files

To find all dot files (files with names that start with a dot) in a directory using Bash, you can use the find command with the -name option.

For example, to find all dot files in the current directory and its subdirectories, you can use the following command:

find . -name ".*"
Sou‮l.www:ecr‬autturi.com

This will search for all files in the current directory and its subdirectories that have names that start with a dot.

To search for dot files in a specific directory, you can specify the path to the directory as the argument to the find command. For example, to search for dot files in the /etc directory, you can use the following command:

find /etc -name ".*"

You can also use the -type option to search for only certain types of files. For example, to search for only directories that have names that start with a dot, you can use the following command:

find . -name ".*" -type d

This will search for all directories in the current directory and its subdirectories that have names that start with a dot.

You can use the -print option to print the names of the files that are found, or use the -exec option to execute a command on the found files.

For example, to delete all dot files in the current directory and its subdirectories, you can use the following command:

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

This will delete all files that have names that start with a dot in the current directory and its subdirectories.

Keep in mind that the find command is powerful but can be slow when searching through large directories. You can use the -maxdepth option to limit the depth of the search, or use the -prune option to exclude certain directories from the search.

Created Time:2017-10-29 22:08:58  Author:lautturi