Get the essential Mac Terminal Commands for use as a web developer.
Coming from a Graphic Designer background has meant that most of my professional life I have used the mouse to get around and complete tasks.
Using the mouse as a coder comes at the cost. It is the time cost of task switching between the keyboard and the mouse. Each switch costs only microseconds but over the course of a career that can add up to months of wasted times.
The revelation of using the terminal to complete tasks and even to do a bit of light programming in the command line has saved me hundreds of hours that I can better use to balance the other elements in my life.
Using the GUI (Graphic User interface) is fast but the terminal is faster.
What follows is not meant to be a comprehensive list of terminal commands and there is a lot that I have left out on purpose purely so that you can just get rolling in the terminal.
Without further ado, here is my list of essential mac terminal commands.
Finding the terminal
To find the terminal hold down the ‘Command’ button and quickly press the ‘spacebar’. This will open the system wide search. A life saver in opening other applications and not just the terminal.
Terminal and hit enter.
You now have your terminal open.
Now lets start with the basics of moving around.
Where are You Or Print Working Directory
pwd and it will display your current working directory as something like
What is in your directory or list
ls to list all the visible files and folders in the current directory.
ls -l to list all the visible files and folders in the current directory in a long format showing the file permissions.
ls -la to list all the files and folders including the hidden ones in the current directory in a long format showing the file permissions.
Changing locations or Change Directory.
cd directoryname to change to the folder/directory named in the current directory.
cd ../ to change to the parent folder/directory to your current location.
cd /users/youruser/ to change to another folder/directory using the full location.
Creating Empty Files
touch file.html to create an empty file with the ‘html’ file extension in the current working directory.
You can write what ever file extension you like. If you’re developing, you should already be familar with file type extensions.
This can be really helpful when you are trying to setup the file structure of what you are developing but you are not yet ready to put the content into the files.
Creating Empty Files within New Directories
In the Current Directory
touch foldername/file.html to create a new folder with a file inside it in one command.
Anywhere in the system Type
touch /user/youruser/desktop/demo/file.htmlto create a new folder and file inside it anywhere in your system in one command.
Renaming and Moving Files
Changing a File Name Type
mv originalname.html newname.html to change the file name from one name to another.
mv originalname.html /newfolder/originalname.html to move the file from one location to another.
Deleting Files and Folders
Deleting a Single File Type
rm filename.html to remove a single file named in command.
Deleting all files by type Type
rm *.html to remove all the .html files in the current directory.
Deleting all files starting with the same name Type
rm samename*.* to remove all the file names that start with same name what ever the file type.
Deleting all the files starting with the same name by file type Type
rm samename*.html to remove all the file names that start with the same name that are html files.
Deleting an Empty Folder Type
rmdir foldername to remove an empty folder. If you have contents in that folder this command will fail, which leads to -
Deleting A Folder Containing Files Type
rm -r foldername to remove a folder containing files.
Deleting Folders Containing Files Type
rm -r foldernameone foldernametwoto remove the named folders and their containing files.
Programming in the Terminal
Creating files with Content Type
echo ‘your html code’>myfile.html to create a file with code you specify in the terminal command line.
Version 1.0 — Wed 26th of July 2017 — Initial creation