Searching for a file can sometimes be a tedious task when you don't have the right tools at hand. But with this command, you can quickly find an existing folder or sub-folder from a root folder, on which you're going to launch your search:
find ~/current -type d -name '*work*' 2>/dev/null | GREP_COLOR='1;31' grep --color=always 'work'
This command is a combination of find
and grep
, used in Unix-like operating systems to search for directories with specific characteristics.
Let's break down what each part does:
find ~/current -type d -name '*work*'
:
- find is a command-line utility that searches for files in a directory hierarchy.
- ~/current specifies the directory in which to search.
- -type d restricts the search to directories only.
- -name
'*work*'
filters directories by name, looking for those that include the substring "work".
2>/dev/null
:
- This redirects standard error to /dev/null, essentially silencing any error messages that might occur during the execution of the find command.
|
:
- The pipe symbol (|) takes the output from the find command and uses it as the input for the next command.
GREP_COLOR='1;31'
:
- Sets the color for matches found by grep. The color code 1;31 corresponds to bright red.
grep --color=always 'work'
:
- grep searches for the specified pattern in the input provided.
- --color=always forces grep to use colored output, highlighting matches with the color specified in GREP_COLOR.
- 'work' is the pattern grep is looking for in the directory names output by the find command.
This command combination efficiently finds and highlights directories containing the word "work" within the specified path, presenting results with enhanced visibility through color coding.
🔍. Similar posts
A Linux Script to Delete All the .git Folders Hidden in Your Repo Folders
18 Nov 2024
How to Add a Binary Folder to the PATH environment variable on MacOS
18 Oct 2024
How to Beautifully Print the PATH environment variables on Linux
18 Oct 2024