The

I. The Linux File System

1. Introduction All users of a Linux OS have an account name (also referred to as a name or a login name) and a . When your Linux account is created, you are also given a home where all of your files and folders will reside. Your has the same name as your account name.

You may be wondering: Hey, I’m using Linux in EC310 and I was never asked for an account name and password while logging on? That is because your textbook author (Jon Erickson) has set up your VMware software to provide Linux “already open” for you. We have, however, changed your account name to midshipman since that is, after all, your first name.

You have been entering commands using the bash shell as your command line interface. Every time you have entered a command such as

gcc –g smith_2_1.c or

nano smith_2_1.c you have entered that command at the bash shell’s prompt. The bash shell’s prompt for ordinary users is the dollar sign. Before the prompt, you will see your account name and your computer's name.

Your account name Your computer's name The prompt

There is one additional item in the picture above that you may have noticed: the symbol (~). The tilde is an abbreviation for your home directory. When you log in, you are placed by default in your home directory.

If you wander up to a computer and notice that someone is logged on, and you see

then the user whose account name is jose has logged in but has forgotten to log out. What a dope. Shame on him. He is evil. Evil Jose.

If you ever forget who you are, even though your account name is staring you in the face, you can enter:

whoami as shown below:

In Linux, just as with Windows, there are files. And in Linux, just as with Windows, there are directories (in Windows terminology, these are referred to as folders), which hold files (or other directories).

A Linux system (like a Windows system) may support multiple users. In such cases, each user is given his own home directory. When you logon, you are automatically placed in your home directory. When Jose logs on, he 1 is automatically placed in his home directory. Your home directory is the natural location for any directories or files that you create. You can leave your home directory and move to other directories. Whatever directory you find yourself in, that directory is termed your .

A typical Linux file system (also called a directory structure) might look like this:

At the very top is the , denoted /. The root directory contains all directories and files.

2. Absolute Pathnames Every file can be referenced by its absolute pathname, which starts at the root directory and traipses down the inverted tree structure, with each entry also separated by a forward . For example, the absolute pathname for the directory is jose

/home/jose Note that in an absolute pathnames, the slash (/) character has two different meanings. The first slash always refers to the root directory. Any other slashes that may be present simply serve as separators.

Since absolute pathnames can be long, a few shortcuts are provided:

• To specify a directory or file in your current directory, you can use just the name of the directory or file.

• A tilde serves as an abbreviation for your own home directory.

• A tilde followed by another user’s name serves as an abbreviation for that other user’s home directory

In the Linux command line, preceding the prompt, you are also provided with an indication of your current working directory. If you are in your home directory (which, as an absolute name for our classwork in EC310, might be something like /home/midshipman ), this will appear as just a tilde since, recall, a tilde serves as an abbreviation for your own home directory.

3. Relative Pathnames Whereas absolute pathnames always start from the root, relative pathnames start from your current location (i.e., your working directory). The notation relies on the use of two dots (..) to serve as an abbreviation for the immediate parent of the current directory.

As an example, in the picture above, if your working directory is dane, the relative pathname of the home directory is simply: .. On the other hand, if your working directory is bob, the relative pathname of the directory Hacking would be ../dane/Hacking . In other words, to get from bob to Hacking, you first 2 must go up one directory to home (the parent directory, represented by the two dots), then from home you go down one directory to , and then down to . dane Hacking Another shortcut is also available for use in relative pathnames. A single dot (.) can be used as a shorthand notation for your current working directory.

4. Listing Files You can list the contents of the working directory by using the ls command. For example, if, in the picture above, your working directory was , then the command would yield the results: dane ls

Hacking Cyber spoofing You can list the files in a different directory by typing ls followed by the absolute or relative pathname of the directory you are seeking information about. For example, if your working directory was dane and you entered , the result would be: ls ../bob

Acme Ramshead 5. Changing Your Working Directory To change your working directory to another directory, simply enter the command followed by the directory you wish to change to. For example, if your working directory was , you could change your working directory to by entering dane bob

cd ../bob When you change your working directory, the command line will update to indicate your new working directory. For example, if I am the user named midshipman and I change my directory to a sub-directory named , I will see as my new prompt: work

Working directory changed to ~/work

If you find yourself lost in the file system, you can instantly reset your working directory back to your home directory by simply typing cd by itself. You may have already noticed that we have changed our working directory at the start of most security exercises by typing:

cd booksrc 6. The root User Every Linux system has a special user named root. The root user is the great-and-all- powerful system administrator of the Linux system. The root user can access any file on the system, including the files of individual users. The root user can read the files of all users, can write over any files, and can delete any files. The root user can load any software onto the system (e.g., programs). The root user owns the system.

The dream of all hackers is to somehow become the root user. In Linux, the root user has a special prompt, the pound sign ( ). If you walk up to a computer and see this: #

that means the root user has logged in and left the computer unattended. That would be bad.

Assistant Professor Patrick Vincent

Help us improve these notes! Send comments, corrections and clarifications to [email protected] 3