How to Find Human-Readable Files in Linux: A Pragmatic Approach
Finding human-readable files in Linux might seem like a trivial task at first glance, but the sheer variety of file types and the depth of Linux filesystems can quickly turn it into a rabbit hole. The most straightforward approach involves combining the powerful **find** command with file type identification and text-based filtering.
Here’s the consolidated command structure you can use to achieve this:
find /path/to/search -type f ( -iname "*.txt" -o -iname "*.log" -o -iname "*.csv" -o -iname "*.md" -o -iname "*.sh" -o -iname "*.py" -o -iname "*.html" -o -iname "*.css" -o -iname "*.js" ) -print0 xargs -0 file
Let’s break down this command:
**find /path/to/search**: This initiates the find command, specifying the directory where you want to begin your search. Replace/path/to/searchwith the actual path, such as/home/user/documentsor even/for a system-wide search (use with caution!).**-type f**: This option restricts the search to regular files only, excluding directories, symbolic links, and other special file types.**( ... )**: Parentheses are used to group multiple conditions. The backslashesescape the parentheses, preventing the shell from interpreting them before passing them to thefindcommand.**-iname "*.txt" -o -iname "*.log" -o ...**: This is the heart of the human-readable filter.-inameperforms a case-insensitive name match. The-ooperator signifies “or.” This section specifies a list of common file extensions associated with text files. You can customize this list to include any file types you consider human-readable, such as.xml,.json,.conf,.properties, etc. Remember to use the backslashto escape the asterisk*in the filename.**-print0**: This crucial option outputs the file names separated by null characters (