If you’re developing on Linux, you probably are either familiar with, or getting familiar with, Bash. If you are developing on a Mac, however, you may be less familiar.
If you have never or rarely opened up your Terminal app, you are missing out on a giant world of productivity. Here I’m assembling what I think the best Bash commands for a newbie in the world of Bash to familiarize themselves with. This isn’t even close to everything. But, my goal is to give you not too much that you can’t memorize, but enough to convince you of the value.
ls– Let’s you see what’s in your current directory.
cd– change directory.
tail– You can use tail to look at logs. For example, if you want to view a WordPress log, type
tail -f <path>/wp-content/debug.log
The outcome? You’ll have a stream of new log data show up in real-time.
grep– This is an indispensable command to help you find things within files. Type
grep '<search>' <search_file_path>
You can also use an asterisk to search every file within a folder. Here are some applications:
grep -nr '<search>' <folder>/*:
searches (-r) recursively and includes a (-n) line number.
grep -l '<search>' *
Finds any (-l) file in the current directory that contains your search word. Returns the file name one time. Sometimes it’s a little easier to just see the files, rather than see line information or how many times the search shows up.
find– I use this all the time instead of the Finder search. The easiest way to use this is to change directories (cd) until you get to a folder you want to search within. Then, type:
find -name "<search_file>"
find . -name "*.js"
Note that you frequently do not need the quotation marks. I include them because some versions/searches require it. The period after find specifies the file path, and is not required in Linux but is required on Mac terminals. To search a specific path that you are not currently on, you can replace the dot with a path.
man– This is the last command I’m going to leave you with, and it’s also the most important. I am barely scratching the surface with many of these commands.
manallows you to learn what a command is capable of on your own. This includes several options and expected syntax. While Google can be very useful,
manshould probably be your first stop to learn what a command is capable of. Try typing the following to see what other options you can pass along in a search:
- Pro Tip:
<tab>– This isn’t a command, but it’s a really useful key. It will autocomplete a directory path or command for you. If there’s ambiguity, double tapping tab will list options for you.
Feeling overwhelmed? That’s all right. You don’t need to capture all of these commands at once. Ultimately, mastering one or two commands at a time will drastically improve your productivity as a web developer. The best part is, these tools will also make it much easier for you to use programs like VVV, which jumpstarts your WordPress development by installing a virtual Ubuntu linux machine on your Mac.
Keep tuned in, while I offer more tips. Do you have a favorite command that helped you when you were just starting out? Feel free to share!