[LINUX] How to use the grep command to recursively search directories and files to a specified depth

Preface

If you are familiar with Unix-like OS on a regular basis, you probably know it, but some people may not know it, so I will post it. I hope it helps people who are new to the CLI of Linux, WSL, and mac and have trouble finding files.

Main subject

If you want to search the file name hogehoge in the range of up to 5 directories, follow the steps below.

$ find . -maxdepth 5 | grep hogehoge

After -maxdepth, specify the depth of the directory in the range you want to search. The explanation of -max depth is excerpted from the Japanese version of man.

-maxdepth levels Searches from the path specified as the command line argument to the directory up to levels down (levels is a non-negative integer). -maxdepth 0 means that only command line arguments are targeted for discriminants and actions.

Furthermore, if the file name is ambiguous, you can add the -i option to the grep command. An example is as follows.

$ find . -maxdepth 5 | grep -i hogehoge

Recommended Posts

How to use the grep command to recursively search directories and files to a specified depth
How to use the grep command and frequent samples
How to use the Linux grep command
How to list files under the specified directory in a list (multiple conditions / subdirectory search)
[Linux] How to use the echo command
Recursively search the specified directory to see the file
How to write a GUI using the maya command
How to delete the specified string with the sed command! !! !!
Linux user addition, how to use the useradd command
How to use argparse and the difference between optparse
Recursively search for files and directories in Python and output
(Remember quickly) How to use the LINUX command line
How to use search sorted
How to use the decorator
How to use the __call__ method in a Python class
How to display a specified column of files in Linux (awk)
How to use the zip function
[sh] How to store the command execution result in a variable
How to use the optparse module
[EC2] How to install chrome and the contents of each command
How to make a command to read the configuration file with pyramid
How to use functions in separate files Perl and Python versions
How to use MBDyn (command setting)
[Python] What is pip? Explain the command list and how to use it with actual examples
[Introduction to Python] How to use the in operator in a for statement?
[EC2] How to install and download chromedriver from the command line
How to output the output result of the Linux man command to a file
How to use .bash_profile and .bashrc
How to install and use Graphviz
How to use bing search api
Learn the flow of Bayesian estimation and how to use Pystan through a simple regression model
How to use the ConfigParser module
How to use Python with Jw_cad (Part 2 Command explanation and operation)
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
[Python] Explains how to use the range function with a concrete example
[Python] How to use the enumerate function (extract the index number and element)
[Linux] How to subdivide files and folders
How to use the Spark ML pipeline
How to split and save a DataFrame
How to install and use pandas_datareader [Python]
Search for files with the specified extension
[python] How to use __command__, function explanation
How to calculate Use% of df command
[linux] Split files to the specified size
python: How to use locals () and globals ()
How to use CUT command (with sample)
How to use Python zip and enumerate
Don't use rm command to delete files
How to use the IPython debugger (ipdb)
How to use is and == in Python
How to use pandas Timestamp and date_range
3 best ways to use the less command
Create a command to search for similar compounds from the target database with RDKit and check the processing time
How to save the feature point information of an image in a file and use it for matching
How to pass the execution result of a shell command in a list in Python
How to count the number of elements in Django and output to a template
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
Zip-compress any file with the [shell] command to create a file and delete the original file.
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
How to make a Raspberry Pi that speaks the tweets of the specified user
How to get a list of files in the same directory with python