In OS X or Linux, you can do a lot with Terminal. This is where you can enter in commands, and your computer will execute them. You can do anything from basic file management, to running programs, to even playing games. But in order to do all that, you have to start with the basics. Here are a few commands you’ll need to get a grip on first.
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”
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 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
To use a flag, you would type “ls -a” or “ls -l” or “ls -al”
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”
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.
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).
Be careful though, you can do some serious damage if you use this command when you shouldn’t!
Now you have a place to start. These commands can help you navigate through your files and give you access to things. Play around and look them up for other useful flags and suggestions, and begin your journey with Terminal!
For more terminal information, check out Apple’s great online Manual or this more basic Wiki article!