10 Need to Know Mac Terminal Commands

Publikováno: 24.7.2019

If you want to get into web development, knowing what the Terminal is and how to use it is very beneficial. But there are some essential commands that we’ll go over so we feel comfortable using it....

Celý článek

If you want to get into web development, knowing what the Terminal is and how to use it is very beneficial. But there are some essential commands that we’ll go over so we feel comfortable using it.

In today’s article, we will be going over the 10 need to know Mac Terminal commands - #10 is a fun one! ????

What is the Terminal?

The Terminal. So what is it?

The most basic use of the Terminal is being able to navigate throughout your computer’s folders and files.

There are commands that you can run inside the Terminal that can create a new ReactJS application, install a new npm package, and so on, but we are not going to discuss those in this article.

Let’s focus on the basic commands when navigating your computer using the Terminal.

Using the Terminal

Want to follow allow? Go ahead and open up the Terminal. The quickest way on a Mac is to hit "command + space bar" and you’ll get the computer’s "Search" bar. Once that pops up, type in "Terminal" and hit "Enter". A little white box will pop up and we will see the name of the computer.

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.

2. cd

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

When using the command, cd, we need 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/file name.

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 and we could click on "New Folder" and 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!

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! ????

Practice, Practice, Practice!

The Terminal is something that just takes time and practice.

Definitely go play around with it and navigate through folders, create new ones, open newly created files up. Or just make your computer say funny things! ????

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace