10 basic command line phrases that are handy for beginners

If you’re new to command line, this will give you an overview of some of the most used phrases to do basic things like moving around the folders in your system, creating and deleting files, creating and deleting directories, and a fun command that makes your computer talk to you.

Here is a short list, but if you would like a more detailed explanation for each, scroll down! (In the short list below, everything that is bold is a command, anything following until the next bolded statement is the output from the terminal). If you follow the same command steps, your terminal should look very similar to the lines below.
Users-MacBook-Air:~ Username$ pwd
/Users/Bylka
Users-MacBook-Air:~ Username$ ls
Applications Library Public
Desktop Movies
Documents Music
Downloads Pictures
Users-MacBook-Air:~ Username$ ls -l
total 0
drwx------ 4 Username staff 136 Jan 7 2016 Applications
drwx------+ 7 Username staff 238 Dec 28 17:50 Desktop
drwx------+ 25 Username staff 850 Feb 23 17:12 Documents
drwx------+ 90 Username staff 3060 Feb 26 18:59 Downloads
drwx------@ 51 Username staff 1734 Aug 18 2016 Library
drwx------+ 3 Username staff 102 Dec 27 2015 Movies
drwx------+ 4 Username staff 136 Aug 18 2016 Music
drwx------+ 6 Username staff 204 Nov 3 19:24 Pictures
drwxr-xr-x+ 5 Username staff 170 Dec 27 2015 Public
Users-MacBook-Air:~ Username$ cd Documents
Users-MacBook-Air:Documents Username$ touch filename.txt
Users-MacBook-Air:Documents Username$ echo hello
hello
Users-MacBook-Air:Documents Username$ echo hello >> filename.txt
Users-MacBook-Air:Documents Username$ cat filename.txt
hello
Users-MacBook-Air:Documents Username$ cat filename.txt|say
Users-MacBook-Air:Documents Username$ rm filename.txt
Users-MacBook-Air:Documents Username$ mkdir FakeFolder
Users-MacBook-Air:Documents Username$ rm -rf FakeFolder
Users-MacBook-Air:Documents Username$
  1. pwd : pwd stands for “print working directory”, this command tells the computer to show you where you are. It prints out the full pathname of the directory you are currently in. Example: if I am chilling in my Documents folder and I write pwd in my terminal, it will print:
Users-MacBook-Air:~ Username$ pwd
/Users/Username/Documents
#This means I am currently inside the Documents folder in my computer

2. ls : this is the command that will list all files which are located within whatever directory you are in. This will display the files and folders in column/row format. If you’d like to see all the contents in a list format, the command is : ls -l

Users-MacBook-Air:~ Username$ ls
Applications Library Public
Desktop Movies
Documents Music
Downloads Pictures
Users-MacBook-Air:~ Username$ ls -l
total 0
drwx------ 4 Username staff 136 Jan 7 2016 Applications
drwx------+ 7 Username staff 238 Dec 28 17:50 Desktop
drwx------+ 25 Username staff 850 Feb 23 17:12 Documents
drwx------+ 90 Username staff 3060 Feb 26 18:59 Downloads
drwx------@ 51 Username staff 1734 Aug 18 2016 Library
drwx------+ 3 Username staff 102 Dec 27 2015 Movies
drwx------+ 4 Username staff 136 Aug 18 2016 Music
drwx------+ 6 Username staff 204 Nov 3 19:24 Pictures
drwxr-xr-x+ 5 Username staff 170 Dec 27 2015 Public

3. cd : this stands for “change directory”. The way you use it is by typing cd “Name of directory which you would like to move to”. If you are in your user directory, you will probably have the default folders “Documents”, “Pictures”, etc. so to move to one of these you’d write “cd Pictures” and you would find yourself inside the Pictures folder.

There are also variations of the “cd” command to either move down one level or go home altogether. So to move back to your user directory from the Pictures directory, you would need to type: <cd ..>. Now let’s say in the Pictures folder, you have a folder called Vacations and inside that folder you have a folder named Hawaii, so your pathname here is: User/Pictures/Vacations/Hawaii, if you are in folder Hawaii and type in <cd ..> you will back one level, which is Vacations. If you are in Hawaii and type in <cd ~>, then you will move all the way back to user which is your “home”.

#As we saw from step #2 I have a few categories that I can go into from being inside the folder that is my username. A lot of us often use the Documents folder, so let's do an example with that one:
Users-MacBook-Air:~ Username$ cd Documents
#Please note! Capitalization is important!
#Extra tip: if you start typing "Documents" but only get to "Doc" you can use the tab key to finish the string
Users-MacBook-Air:~ Username$ cd Documents
Users-MacBook-Air:Documents Username$
#Above is what you will see - the only difference is that you can now see the word "Document" in the text of the prompt. But you are now within the Documents folder and if you input the <ls> command again, it will display the contents of you Documents folder

4. touch <file name> : the touch command creates a file in whatever directory you are currently in. The syntax is <touch filename.txt>. This command creates a text file called “filename”. The type of file you create is up to you, just make sure you get the right extension.

Users-MacBook-Air:Documents Username$ touch filename.txt
Users-MacBook-Air:Documents Username$
#This command will not return an output, because the action of creating the file "filename.txt" is done. However if you type in <ls>, you will find this file in the list of files and folders

5. echo <input> : the <echo> command just echoes back whatever you input into the terminal. Feel free to play around with this!

Users-MacBook-Air:Documents Username$ echo hshshfkfkkfkfkf
hshshfkfkkfkfkf
Users-MacBook-Air:Documents Username$ echo hello world
hello world
Users-MacBook-Air:Documents Username$

A variation of the <echo> command is to use it to place input into some file <echo hello >> filename.txt> (puts the string “hello” into the file you created)

Users-MacBook-Air:Documents Username$ echo hello >> filename.txt
Users-MacBook-Air:Documents Username$
#This code just added "hello" to the file called "filename.txt". You can even open it up in a text editor to see for yourself! Just go to your Documents folder and open up the file the way you'd usually open a text file.

6. cat <file name> : the <cat> stands for “concatenate”, this command will display the contents of a file, so in the example we used above, if we type in <cat filename.txt>, the output should be “hello” — or whatever your imagination came up with.

Users-MacBook-Air:Documents Username$ cat filename.txt
hello
Users-MacBook-Air:Documents Username$
#If you happen to have some doc in your Documents folder, you can try to print out its contents using <cat> too!

BONUS STEP! To hear what you computer sounds like type in the following:

Users-MacBook-Air:Documents Username$ cat filename.txt|say
#FYI - this is just for fun

7. rm <file name> : If you’re playing around, kind of like we are right now, and don’t want random fake files in your computer, there is also a way to remove them using the terminal. <rm> stands for “remove”.

Users-MacBook-Air:Documents Username$ rm filename.txt
#There will not be any output because the action is done, if you write command <ls> you will no longer see this text file.

8. mkdir <folder name> : <mkdir> stands for “make directory”. Make sure that whatever folder name you choose, it is considered as one string. FakeFolder is one string, Fake Folder are two strings, “Fake Folder” is also one string. If your command is <mkdir Fake Folder>, you will create one folder named “Fake” and another folder named “Folder”.

Users-MacBook-Air:Documents Username$ mkdir FakeFolder
Users-MacBook-Air:Documents Username$
#There will not be any output because the action is done, if you write command <ls> you will now see "FakeFolder" in the list

9. rm -rf <folder name> : <rm -rf FakeFolder> removes a directory in its entirety.

WARNING: This is a serious warning! DO NOT run this command while you’re in your home folder, even you do, it’s probably going to try to stop you — DO NOT run this command with <sudo> in front of it (sudo overrides precautions — think twice before you use this).

Usually if there are files inside a directory, the system will try to stop you from deleting it. For example using the command <rmdir FakeFolder>, if there is even one file inside FakeFolder you will see an error (see below).

Users-MacBook-Air:Documents Username$ rmdir FakeFolder
rmdir: FakeFolder: Directory not empty
Users-MacBook-Air:Documents Username$ rm -rf FakeFolder
Users-MacBook-Air:Documents Username$
#First we see the error output, because rmdir cannot be used to delete a directory that has files inside it. When using rm -rf there will not be any output because the action is done, if you write command <ls> you will now see that the folder called "FakeFolder" is gone from the list

10. <command> k : Pressing your command key and then k will clear your terminal. Also typing in “clear” will do the same thing. :)

Just use this the same way you use command v or command c - you won't see anything, but your terminal will be shiny clean!
Users-MacBook-Air:Documents Username$