Advanced File Operations
grep
Text matching is traditionally done with grep
. On your personal or work laptop, you may want to install ag
or rg
, which are more programmer-friendly and faster versions of this idea, but on production systems, you’ll always have grep
.
Search for the pattern “search_pattern” in the file path/to/file
:
grep "search_pattern" path/to/file
You can, of course, search for string literals like this, but grep
is so powerful because it allows you to use regular expressions (“regexes”) to search for patterns. The following command will return lines that start with startswith
:
grep ^startswith /some/file
And this command will return lines that end with endswith
:
grep endswith$ /some/file
Regular expressions are tremendously useful, and every developer and Linux user should be familiar with the basics.
find
find
can help you find files and directories by name, modification time, or other attributes. It’s essentially...