Quoting the Introduction to user commands manual entry:
"Linux is a flavour of Unix, and as a first approximation all user commands under Unix work precisely the same under Linux (and FreeBSD and lots of other Unix-like systems).
Under Linux there are GUIs (graphical user interfaces), where you can point and click and drag, and hopefully get work done without first reading lots of documentation. The traditional Unix environment is a CLI (command line interface), where you type commands to tell the computer what to do. That is faster and more powerful, but requires finding out what the commands are."
The Terminal program provides a command-line interface called a shell where you type commands to tell the computer what to do. Start the Terminal program using the Applications menu.
A window similar to that shown to the right should appear.
The prompt ea40 % indicates that the name of this computer is ea40. You will see a different name corresponding to the name of your computer. You will also see a number beside the name (probably the number 1); the number is the history number of the current command line.
In EECS2030, it is important that you become comfortable working with files from the command line because this is how you will be submitting your program files for grading (including during tests).
You are probably already familiar with the notion of a computer file that represents some piece of information on a storage device (e.g., MP3 music files, JPEG picture files, word processor documents).
You are probably also aware that you can use folders to organize your computer files (e.g., under Windows you have Desktop, Documents, and Favorites folders). You can even put folders inside of other folders.
You might also know that every file and folder has a unique name called the absolute path or absolute pathname. The absolute path is simply the full list of folders that you need to traverse to reach a particular file or folder. For example, in Windows the the absolute path C:\Users\Bob\Music refers to Bob's Music folder, and the backslashes \ are used to separate folder names.
In Linux, it is more common to use the term directory instead of folder.
Your home directory is where all of your EECS account files are stored. Of course, you can (and should) create directories inside of your home directory to organize your files. Every person with a EECS account has their own home directory.
No matter which lab computer you use, your home directory always has the same absolute pathname.
By default, the shell will start in your home directory.
To see the full pathname of your home directory, invoke the pwd command by typing it in the terminal and pressing the Enter key. You should get a slightly different result than that shown to the right.
pwd prints the full path of the current working directory.
Notice that the terminal you are using has been pre-configured to display the current working directory in the title bar.
Linux uses a single hierarchical directory structure to organize all of its files. This is different than Windows where each drive ( C:, D:, etc.) has its own separate directory structure.
The top-most directory in Linux is called the root directory, and is identified by the slash character /.
Use the change directory command cd to switch to the root directory.
Use the command ls ("ell-ess" not "one-ess") to list the files contained in the current working directory.
You might not get the exact same output as shown in the figure because the EECS computer systems are regularly updated.
The names listed in blue are all directory names. Many of these directories are common to all standard Linux distributions, and are described by the Filesystem Hierarchy Standard.
Notice that the root directory contains other directories. Those directories in turn contain other directories, and so on. One of the directories in the root directory is named eecs.
Use the change directory command to switch to the eecs directory.
Notice that you did not need to specify the full path /eecs because you were already in the root directory / (you can always use the full path if you want).
The eecs directory contains all of the files and directories belonging to people in the Department of Electrical Engineering and Computer Science.
Use the command ls to list the files contained in the current working directory.
Again, you may see some differences from the figure.
Many of the Linux command-line programs allow the user to specify optional flags that control how the program should behave. The flags are often (but not always) specified using a hyphen -.
Use the long format flag -l ("hypen-ell") with ls to display extra information about the files in the current working directory.
The long format listing produces a lot of output, most of which won't make sense to you at this time.
Even expert users have a hard time remembering all of the options for all of the commands. All of the commonly used command-line programs have a manual page that you can access using the man program.
Access the manual for ls using the command man ls
You can move forward in the manual by pressing the Space key. Move backwards by pressing the b key. Quit using the q key.
ls has a large number of optional flags. Don't worry about trying to understand them all right now; just get used to navigating the man page, but keep the following questions in mind.
What flag would you use to:
Try out your answers; did they do what you expect?
Recall that we are currently in the directory /eecs.
To move up one directory to the parent directory you use the command cd .. (which in this case will take us to the root directory).
The shell interprets .. as being the parent directory to the current working directory.
The ls command by itself will list the contents of the current working directory. If you want to list the contents of a different directory, you can specify the name of the directory.
ls bin will list the contents of the bin directory.
The directory /bin contains many of the essential command-line programs.
There are quite a few files in /bin. The files listed in green are all programs runnable by the user.
Use the change directory command to switch to the bin directory.
The ls command lists information about the files you specify. As you have already seen, if you specify no files, then ls lists the files in the current working directory.
Suppose that you want to list all of the files that begin with the letter l. You can do this by using the command ls l*
Most Linux shells will interpret the asterisk * to mean "any sequence of characters"; thus, ls l* means "list all files with a name starting with l followed by any sequence of characters".
Notice that the ls command is found in /bin.
You can return to your home directory by using the cd on its own. If you don't specify which directory to change to, cd assumes you want to go to your home directory.
You could also use cd ~ (where ~ is the "tilde" character usually located on the top left key of the keyboard).
At this point, you might be wondering if it is possible to list the contents of anyone's directory. Ask the person next to you what their EECS account name is, and try to list the contents of their home directory. Can you list the contents?
In the example shown, burtonma is my account that has student-level privileges that I use to test assignments, labs, and tests before releasing them to students. Notice that even though I own that account, I still cannot list the contents of the burtonma home directory because I am not logged in as that user.
To see why you cannot list the contents of another student's directory, invoke the command shown to the right (replace burtonma with someone else's account name that isn't yours.)
The output should look something like:
drwx--x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
You don't need to know what every piece of information in the output means, but some of the information can be very useful.
The username of the owner of the directory is:
drwx--x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
The groupname of the group that owns the directory is:
drwx--x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
All EECS undergraduate students belong to the group ugrad.
The letter d indicates that the entry is a directory.
drwx--x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
The letters rwx indicates that the user burtonma has:
d rwx--x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
The letters --x indicates that anyone in the group ugrad has:
drwx --x--x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
This set of permissions explains why you cannot list the contents, or read the files, of another student. You belong to the group ugrad and the group does not have read permission on the directory.
The letters --x indicates that everyone else (not the user and not in the group), such as faculty, has:
drwx--x --x 44 burtonma ugrad 4096 Sep 5 14:43 ../burtonma
This set of permissions means that your files are safe from your professor (but not from the system staff, who have superuser permissions, meaning that they have the ability to read or write any file on the filesystem).
Command | Meaning |
pwd | Print the full (absolute) pathname of the current working directory. |
cd dirname | Change to the named directory. |
cd .. | Change to the parent directory of the current working directory. |
cd | Change to the user's home directory. |
ls | List the contents of the current working directory. |
ls dirname | List the contents of the named directory. |
ls -l | List using long format the contents of the current working directory. |
ls -l dirname | List using long format the contents of the named directory. |
ls -ld dirname | List using long format the name (but not the contents) of the named directory. |