How to grep folder name in linux

The previous article described how to search all files with specific content under Linux system.

But in the actual development, we often encounter the situation of searching specific folders.

How to grep folder name in Linux?

Use the find and grep commands

Search for a folder named “folder” in the blog directory.

➜ find . -type d | grep 'folder'

Use the ls and grep commands

➜ ls -lR | grep '/folder'
  • -R list subdirectories recursively
  • -l use a long listing format

You can also use the following method, but this method will not display the relative path, only the folder information searched.

➜ ls -Rl | grep '^d' | grep 'folder'

drwxrwxr-x 2 root     ylspirit 4096 Dec  9 06:02 folder

Add a Comment

Your email address will not be published.