Skip to content

Instantly share code, notes, and snippets.

@NateWeiler
Created February 22, 2021 16:30
Show Gist options
  • Save NateWeiler/a0c1a32d74987d685227e2d9eb395122 to your computer and use it in GitHub Desktop.
Save NateWeiler/a0c1a32d74987d685227e2d9eb395122 to your computer and use it in GitHub Desktop.
10 Need to Know Mac Terminal Commands

10 Need to Know Mac Terminal Commands

When navigating the computer's file/folder system, there are a handful of commands that will be used the most. We are going to go over some of the most key, essential ones:


1. pwd

The command, pwd, stands for "Print Working Directory." Essentially, you type in that command, and it will spit out the exact file path for the file or folder you are in.


2. cd

This stands for "change directory" or, in simpler terms, change which folder we are in.

When using the command, cd, we can tell it which way to move by adding more to the command.

  • cd or cd ~ - Takes us to the home directory.
  • cd <folder name> - Takes us forward one step to the folder that is typed in.
  • cd .. - Moves us back one level to the parent folder.
  • cd ../.. - Moves us back two levels. Add more /.. for each level we want to navigate up.

When typing in a folder or file name and it's only one step ahead, you can hit "Tab" and it will autofill in the folder/filename.


3. ls

Now that we are in a folder, we might want to see what is in that folder. When running the command, ls, it will show us everything in that folder.

If we wanted to see all files, even the hidden ones, we could run ls -a.


4. clear

This command does exactly what it sounds like; it "clears" your terminal out. Sometimes a clean slate is easier when trying to focus.


5. mkdir

If we were to right-click directly onto our Desktop view, that little menu would pop up, we could click on "New Folder", and then a brand new folder would pop up for us to name. This command does that same functionality.

mkdir stands for "Make Directory" or simply, make a new folder.

Wherever this command is ran from, it will create the new folder in that spot. So navigate to the desired location using cd commands, and then type in mkdir <folder name>.

To get into that new folder, we would run the command: cd <folder name>.

Opposite of mkdir? If we want to remove a directory, simply run rmdir . The folder must be empty for this to work.


6. touch

Now that we know how to create a folder let's create some files within that folder. If we followed the commands above:

  1. mkdir new-folder
  2. cd new-folder

We should now be in the "new-folder" directory/folder. Let's create a file within that folder. By running the following command, that would create a file:

touch new-file - this has no extension, so we would want to add .html, .txt, or whichever extension needed.

Opposite of touch? The command to remove a file is rm .


7. open

Open a file or folder by typing in the command:

open <folder/file name>


8. history

Want to know all the commands that have been ran in the current terminal session? Run the command, history to see them.

Another trick! Use the "up" and "down" arrows to navigate through previous commands.

Want to limit the number of commands it shows? Add a number to the command: history 10 would show the last 10 commands typed.


9. cat

This command allows us to see the contents of a particular file. We would need to declare the particular file for this command to work.

If we know the path of to the file, we could run:

cat /Desktop/new-folder/new-file

Or we could navigate from our home folder to new-folder and then run the command.

  1. cd Desktop
  2. cd new-folder
  3. cat new-file

This command is different from open because it shows the contents of the file inside of the Terminal rather than opening it up externally outside of the Terminal.


10. say

This one is a fun one. Not necessary for navigation, but it makes your computer SPEAK to you!

Type in: say "anything here" and your computer will say that. Don't forget the quotes in this command!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment