The Basics

There are a few central commands that are integral to using terminal.


cd

cd will let you change the directory that you are located in. This is key in navigating though your computer. pwd will allow you to “print working directory,” or the directory that you are currently in (filepath). cd will then let you change directories to one you specify (for example, “cd /Users/username/Documents/”

“cd ..” will move you up once in the filepath. In our example, if we did this command twice, we would end up at “/Users/”

Instead of typing a whole filepath after “cd” to change directories, we can use subdirectories sometimes. Say we are in “/Users/” and we would like to move to “/Users/username” We can do this in two ways. We can use “cd /Users/username” or we can simply use “cd username”

Screen Shot 2013-05-21 at 11.30.40 AM

Not putting a forward slash “/” in front of a folder name means we want to navigate to a folder with that name that is in the directory we are already inside.

Using “cd” and putting nothing after that will return you to your home directory.


ls

ls lists the files in a directory, for example if you type “ls /directorypath” you will get a list of all the files in /directorypath. If you type just “ls” you will get a list of all the files in your current working directory (the directory you get when you use the command “pwd”).

There are some flags you can use on ls that can be very helpful. The following two are the most commonly used ones.

-l includes extra information, such as file size, permissions, owner, ect.

-a includes files that may be hidden initially

Screen Shot 2013-05-21 at 11.28.07 AM

To use a flag, you would type “ls -a” or “ls -l” or “ls -al”

 


chmod

This is used to change permissions of folders and files. What does this mean? You can have read, write, or execute permissions on a folder or file. The “people” that have permissions are “user,” “group,” and “others.”  The user is the owner of the file/folder.

There are multiple ways to use this command, but we’re only going to go over one. Essentially, the format is “chmod person+permission filename”

To represent the “people” we use “u” “g” and “o”

To represent the permissions we use “r” “w” and “x”

So to give the user read and write permission, we can type “chmod u+rw filename”

To give the user and group read permission, we can type “chmod ug+r filename”

To give user, group, and others write permission, we can type “chmod a+w filename”

We can also remove privileges. For example, if we want to remove write privileges from others, we can type “chmod o-w filename”


sudo

Using sudo before another command grants you the permissions of the superuser (like the system administrator) while doing that command. This can be useful if the user you are logged into does not have permission to do an action on a file.

XKCD comic

http://xkcd.com/149/

If you find you need to do this for multiple commands, it might be advantageous to use the command su

Simply typing “su” changes your user to the superuser.

You can also type “su username” to change your user to another user (denoted by username).