The Linux File System I. The Linux File System 1. Introduction All users of a Linux OS have an account name (also referred to as a user name or a login name) and a password. When your Linux account is created, you are also given a home directory where all of your files and folders will reside. Your home directory 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 tilde 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 joe has logged in but has forgotten to log out. Shame on him. Too bad. 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). 573 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 Joe logs on, he 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 working directory. A typical Linux file system (also called a directory structure) might look like this: At the very top is the root directory, 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 slash. For example, the absolute pathname for the directory joe is /home/joe 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 path 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. 574 As an example, in the picture above, if your working directory is instructor, 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 ../instructor/hacking . In other words, to get from bob to hacking, you first must go up one directory to home (the parent directory, represented by the two dots), then from home you go down one directory to instructor, and then down to 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 instructor, then the command ls would yield the results: 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 instructor and you entered ls ../bob , the result would be: acme fleet 5. Changing Your Working Directory To change your working directory to another directory, simply enter the command cd followed by the directory you wish to change to. For example, if your working directory was instructor, you could change your working directory to bob by entering 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 subdirectory named work, I will see as my new prompt: 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-andall-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: 575 that means the root user has logged in and left the computer unattended. That would be bad. 576