Using your mac’s terminal allows you more power and quicker access to handling operating system preferences and managing your file directory compared to that of GUI ( Graphical User Interface). Down below are 8 essential commands to get started using your Mac terminal.
The pwd command is used to find the path of the directory (or folder) you’re currently working in. This returns a full ( or absolute) file path. A file path is just a path of all the directories that starts with a forward slash (/). An example of a full path is /home/username.
You use the cd command to switch between Mac files and directories. It requires either the full path or the name of the directory, depending on which directory you’re currently in.
To illustrate, if you’re in /home/username/Documents and you want to go to Photos, a subdirectory of Documents. You would just type the following command: cd Photos.
Another scenario is if you want to switch to a completely new directory, for example, /home/username/Music. In this case, you have to type cd followed by the directory’s absolute path: cd /home/username/Music.
Here are some shortcuts for quicker navigation:
- cd .. (with two dots) to move up one directory
- cd to go straight to the home folder
- cd- (with a hyphen) to move to your previous directory
One thing to note is that Mac’s terminal is case sensitive. So, you have to type the name’s directory exactly as it is.
The ls command is used to view the contents of a directory. By default, this command will display the contents of your current working directory.
If you want to see the content of other directories, type ls and then the directory’s path. For example, enter ls /home/username/Downloads to view the content of Downloads.
There are various flags you can use with the ls command:
- ls -R lists all the files in the sub-directories as well
- ls -a shows the hidden files
- ls -al lists the files and directories with detailed information like the permissions, size, owner, etc.
The mv command is primarily used to moves files to different folders, but it can also be used to rename files.
To use mv you need to type mv, the file’s name, and the destination’s directory. For example: mv file.txt /home/username/Documents.
To rename files, the shell command is mv oldfilename newfilename
Use mkdir to make a new directory — if you type mkdir Movies it will create a directory called Movies.
There are extra mkdir shortcuts as well:
- To generate a new directory inside another directory, use this Mac basic command mkdir Music/Newfolder
- use the p (parents) option to create a directory in between two existing directories. For example, mkdir -p Music/Country/Newfolder will create the new “Country” file.
If you need to delete a directory, use the rmdir command. However, rmdir only allows you to delete empty directories.
The rm command is used to delete directories and the contents within them. If you only want to delete the directory — as an alternative to rmdir — use rm -r.
The touch command allows you to create a new file. As an example, enter touch /home/username/Documents/Index.html to create an HTML file entitled Index under the Documents directory.
For a list of more terminal commands you can make use of, please check out this blog for additional info.
And there you have it, I hope these commands come in handy.