CLI
top 10 commands to know

Commonly Used 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
  2. cd
  3. ls
  4. clear
  5. mkdir
  6. touch
  7. open
  8. history
  9. cat
  10. say

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.

BEGINNERTAILWIND.COMLearn Tailwind CSS from Scratch

img

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.

img

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.

img

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.

img

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>.

img

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.

img

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>

img

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.

img

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.

img

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!

Bonus Tip!

Want to change the Terminal to look like the Matrix? Black background, green letters?

  1. In the upper left-hand corner of the screen, click where it says, "Terminal".
  2. Click "Preferences…"
  3. Click "Profiles"
  4. In that list on the left-hand side, click on "Homebrew Default"
  5. Click on "Default" at the bottom.

Exit the Terminal and reopen it to see those changes. Now we can code and look cool when our friends look over our shoulder to see what in the world we’re doing. Uh, we’re just making folders and deleting them, but they don’t know that! 🙂

Scroll to Top