Skip to main content

Command Palette

Search for a command to run...

The Guide to the Terminal: Command Lines

By: Namish

Updated
5 min read

Have you ever opened that black box on your computer and wondered what it was? The sideways carrot arrow with the underscore just waiting to be opened. The terminal can look mysterious. It feels like opening it will open a hacker terminal. The terminal is just another way to talk to your computer. Instead of using your mouse you type certain words to tell the computer what to do. What Actually is the Terminal? Normally, you interact with your computer using a Graphical User Interface. The terminal takes all the graphics away, however. Why would anyone want to do this? It is incredibly fast. Once you learn a few basic commands, you can move files, create folders, and organize your computer much faster than you could by dragging and dropping windows with a mouse. The Big Five You can do thousands of things in the terminal. You only need to know about five of them to get started.

  1. Where am I right now? (pwd) When you open the terminal, you are placed inside a specific folder on your computer. To find out which folder you are currently sitting in, type this command and press Enter: pwd This stands for "Print Working Directory." A directory is just the technical word for a folder. Your computer will spit out a line of text showing your current location, like /Users/YourName.

  2. What is inside this folder? (ls) Now that you know where you are, you probably want to see what is around you. Type this and hit Enter: ls This stands for "list." It will list out all the files and folders inside your current directory. It is the exact same thing as opening a folder on your desktop and looking at all the icons inside.

  3. How do I move to another folder? (cd) You will not want to stay in one folder forever. To move around, you use the change directory command. Type cd followed by a space, and then the name of the folder you want to go into. For example, if you see a folder named "Documents" when you type ls, you can move into it by typing: cd Documents Press Enter. It will look like nothing happened, but you have moved. Type pwd again to prove it to yourself. Your location will now show that you are inside the Documents folder. What if you want to go backward? You just type this: cd .. Those two little dots tell the computer to step back out into the previous folder.

  4. How do I make a new folder? (mkdir) Let us say you want to organize your files. You need a new folder. Instead of right-clicking your mouse and selecting "New Folder", you type: mkdir VacationPhotos This stands for "make directory." The computer will instantly create a folder called VacationPhotos in your current location. If you type ls right after, you will see your brand new folder sitting there.

  5. How do I create an empty file? (touch) Sometimes you just need a blank text file to start writing notes or code. On Mac and Linux, you use a command called touch. touch notes.txt Hit Enter, and a blank file named notes.txt will appear. If you are on Windows using the standard Command Prompt, this specific command might not work, but you can usually type type nul > notes.txt to do the same thing. Putting It All Together Let us walk through a quick practice run. Try reading this sequence and imagine what is happening on the computer. pwd (Checking where we are starting.) mkdir SecretProject (Creating a new folder for our work.) cd SecretProject (Going inside that new folder.) touch ideas.txt (Making a blank text file to hold our thoughts.) ls (Looking around to make sure the file was created.) In five short lines of text, you just created a workspace and a file to work in. Doing that with a mouse would take a lot of clicking, dragging, and navigating through menus. A Quick Warning About Deleting Things There is a command to delete files called rm (remove). You need to be very careful with it. When you delete a file using your mouse, it usually goes into a Trash or Recycle Bin. You can get it back if you made a mistake. When you delete a file using the terminal command rm, it does not go to the trash. It is instantly and permanently gone. Because of this, it is highly recommended to stick to creating files and moving around until you are completely comfortable with the command line. Wrapping Up That is the big secret of the terminal. It is not magic. It is just a very direct way of giving your computer instructions. Do not worry about memorizing every single command in the world. Even professional programmers have to look things up online every single day. Start by just opening the terminal, checking where you are with pwd, and looking around with ls. Once you get used to the text interface, you will realize it is just another tool in your toolbelt.

More from this blog

H

Hack United Blog

117 posts

Hack United is a non-profit organization founded by teenagers with a passion for programming and technology. On this blog, we spread recent tech news with a target audience of teenagers.