1 / 19

Linux Fundamentals: Filesystem Hierarchy

Linux Fundamentals: Filesystem Hierarchy. This material is based on work supported by the National Science Foundation under Grant No. 0802551.

phiala
Download Presentation

Linux Fundamentals: Filesystem Hierarchy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Fundamentals:Filesystem Hierarchy This material is based on work supported by the National Science Foundation under Grant No. 0802551 Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author (s) and do not necessarily reflect the views of the National Science Foundation C1L9S1

  2. Lesson Overview U the Computers store thousands of files, directories, and folders scattered across one or many drives. To keep track of all files, computers keep a detailed record of each file, its location, changes made to the file, access dates, and other important information. Linux has a similar system of file storage and location process called the Filesystem Hierarchy Standard which defines where directories and the files contained within them are stored. This filesystem standard is explored in this lesson. It is very important to have a clear understanding of filesystems and storage locations because improper use of filesystem tools can corrupt or destroy important data. You will learn to manipulate files and directories using command line and other tools. Additionally, you will develop an understanding of the hierarchy used within Linux for file location and storage. C1L9S2

  3. Objectives – Student Expectations Student Expectations You should know what will be expected of you when you complete this lesson. These expectations are presented as objectives. Objectives are short statements of expectations that tell you what you must be able to do, perform, learn, or adjust after reviewing the lesson. Select the Objective tab on the left to review this lesson’s objective. C1L9S3

  4. Objectives Objective Given a configured Linux systems, users will be able to describe the Linux Filesystem Hierarchy Standard and use Linux commands to manipulate files as per industry standards. C1L9S4

  5. Lesson Outline • During this lesson, you will explore: • Filesystem Hierarchy (FHS) • File directory in Linux • File types • Viewing directories and files • Creating directories and files • Moving directories and files • Using wildcards • Deleting directories and files C1L9S5

  6. Filesystem Hierarchy Every operating system follows a standard to determine where files are stored on a hard drive so they can be found and used by the operating system at a later time. This standard is called a filesystem. File systems allow filesto be organized in a hierarchical-based directory. A hierarchy of files is necessary to give preferences and permissions to certain files but not to others. File directories are used to store files, subdirectories, programs,and configurationfiles. Linux uses the Filesystem Hierarchy Standard (FHS) –a process that began in the early 1990’s as an attempt to restructure the file and directory system in Linux and later, in other Unix-like distributions. However, most modern Unix/Linux distributions do not follow these standards as they were originally intended. Further reading: Linux Filesystem Hierarchy from TLDP Graphic of Filesystem Hierarchy C1L9S6

  7. Print Working Directory To view a demonstration of the PWD command, select PLAY below. Understanding the Linux filesystem hierarchy will allow you to save, locate, and retrieve files as needed. In the Unix/Linux environment (as with any other operating system), each directory has it’s own purpose and use. Unix/Linux systems have a root login, which requires a password to access. Linux systems also have a root directory represented by a forward slash (/). An absolute path or absolute file location always includes the root directory; consequently, the path begins with the forward slash (/) to indicate the root directory. You should always differentiate between the root login and the root directory. One is often confused with the other. Tip: If you forget the your current file location while working in a Linux command line environment, type the command pwd (print working directory) at the command prompt, and your path or current working directory will be displayed.   View Video VideoLesson9PrintWorkingDirectory(C1L9S16).mp4 C1L9S7

  8. File Directories in Linux The standard directory system in some Linux distributions (i.e. UBUNTU) may contain some of the following main directories: /bin, /dev, /etc, /home, /media, /root, /sbin, /tmp, /usr, and /var. Review the Linux File System Tree Overviewlink to learn about the specific purpose of each directory. In Unix/Linux systems, everything is considered a file. Therefore, every path would begin with the forward slash (root directory). For example: /home/mary/client client is located in the mary subdirectory maryis located in the homesubdirectory homeis located in the root (/) directory Locations within the file directory tree can be identified as having a relative or absolute pathname. For example, an absolute name would start with the slash "/", while a relative path name would not. Required Reading Root directory illustration C1L9S8

  9. File Types Linux files are categorized as “shareable versus unshareable,” and “variable” versus “static.” A shareable fileis one that may be stored on one computer but accessed and used by other computers. An unshareable filewill be the opposite—it is not shared with other computers. Files used for security purposes and device lock files are examples of unshareable files. A static fileis one that does not change during regular use, however, a system administrator may make changes to static files. Examples of static files include documentation files and libraries. On the other hand, a variable filechanges regularly and does not require a system administrator to make changes to it. C1L9S9

  10. File Types There are six specific file types in Unix/Linux. These file types create a file system where all processes, devices, and connections are accessed. File types include: Regular file – almost anything in an Unix/Linux system can be considered a file including text, binary, or executable items. Directory– a directory is a location to save other files. In Unix/Linux, a file may be listed in more than one directory to create a “link.” Device – all devices in Unix/Linux environments can be accessed as files. FHS compliant system • Socket – also referred to as "Unix domain socket" or "local domain socket." A socket represents the communication between two programs. • Pipe – Allows communication between two programs (or commands). • Symbolic (soft) link – similar to a “shortcut” in Windows. A link points to an original file, but if the original file is deleted, the link will be broken and invalid. Directory links are considered “soft links.” C1L9S10

  11. Viewing Directories and Files Let’s review Figure 1: clients and sales are directories. Notice the d at the beginning of the file rights (left).gomezand smith are files, notice the dash (-) at the beginning of the file rights Rodriguez smith represents a soft link file where smith is the source file and rodriguez is the symbolic link. (If smith is deleted, destroyed, or corrupted, then the rodriguez symbolic link would not function.) To view file types in a Unix/Linux environment type ls –all or ls –l at the command prompt. The results will display information for each file inside the directory. The dash (–) in front of the file permissions indicates the file is regular. The letter “d” indicates the filename is a directory (inside the directory) which makes it a sub-directory. The letter “l” indicates a symbolic file. To review the different switches you can use with the ls command (list directory contents) you can review previous lessons. To search man pages in your Unix/Linux system type man ls at the command prompt. C1L9S11

  12. Creating Directories and Files Access your command line to create files. Refer to Fig 2. To create a directory:mkdir <name of the file> To create the clients directory: mkdir clients To create a file: touch <nameofthefile>To create the gomez file: touch gomez To create multiple directories in one command line: mkdir <directory name 1> <directory name 2> To create smith and lopez: mkdir smith lopez To create a symbolic link; ln –s <nameofsourcefile> <nameofsymboliclink> To remove a symbolic link, view this reference. To create the Rodriguez symbolic link, type: ln –s smith rodriguez To view the contents of the directory, type: ls –l at the command prompt. C1L9S12

  13. Moving Directories and Files The mv (move command allows you to move files and directories. (Refer to figure 3). Terry created a file and named it bonus. At the command prompt, he types ls –l to view the list of files in that directory. He is certain bonus is a file (and not a directory) because the first character that appears for the bonus file is a dash (–) indicating file status. Terry wants to move the bonus file into the lopez subdirectory. At the prompt he types mv bonus lopez where bonus is the file to be moved and lopez is the destination directory to which bonus will be moved. Terry types ls -lagain to ensure bonus was indeed moved to the lopez directory. The file bonus does not show in the original directory listing. Therefore, bonuswas indeed moved. C1L9S13

  14. Moving Directories and Files Now Terry wants to make sure bonus is inside the lopez subdirectory. Before he can list the contents of the lopez subdirectory, he needs to move into the lopez subdirectory. At the prompt he types cd lopez Then he types ls –l to list the contents of the lopez subdirectory. The results confirm that the bonus file is stored at that location. To make sure, Terry types pwdto print the working directory, and indeed it displays Terry’s current working directory as /home/terry/lopez. To move out of the lopez subdirectory Terry types cd .. (cd command, followed by a space and two periods). This command takes him out of the lopez subdirectory and back to /home/terry. This move is confirmed when he types pwd(to check his current working directory) and it returns his path as being /home/terry. C1L9S14

  15. Finding Directories and Files Sometimes you will need to find a file but do not remember where you saved or stored it. To locate misplaced files, you can use the find command. You can find a file by typing the command find <filename> at the command prompt. For example, Terry forgot where he stored the bonus file. At the prompt, he types:find . –name bonus The computer returns the output indicating bonus is located inside the lopez subdirectory. Note: Years ago, you needed to add print at the end of the command line to get results. Most modern Unix distributions do not require this. Bonus file is located in the lopez directory C1L9S15

  16. Finding Directories and Files ls b??? Lsb??? is the command to list the contents of the directory for all filenames that begin with the letter b and are four characters long. Sometimes you will not remember the exact name or spelling of a file or directory you seek. In these instances, wildcard characters work well. There are two types of wildcard characters: the asterisk (*) and the question mark (?). Both types may be used in place of actual letters. However, there is a slight difference between them. The asterisk (represented by the * character on your keyboard) represents any number of characters. The question mark (represented by the ? symbol on your keyboard) represents one character. For example, if you are searching for a file that begins with B and you know it is four letters long, you would type ls B??? at the command prompt. If you knew the filename begins with b but you do not remember the other letters in the filename, you would type ls b* at the command prompt. The asterisk (*) wildcard is used more frequently than the question mark (?) character to do wildcard searches in a Unix/Linux environment. ls b* Ls b* is the command to list the contents of the directory for all filenames that begin with the letter b. C1L9S16

  17. Removing Directories and Files Sometimes you will need to remove directories and files. The following commands will allow you to achieve this goal (refer to figure 4): To remove a file at the command prompt: rm <name of file> For example, to remove the gomez file: rm gomezTo learn more about the rm command you may visit the man rmpage. By default, the rm command removes files, not directories. Remember: Unix/Linux systems are case sensitive. Consequently, rm Gomez is not the same as rm gomez! C1L9S17

  18. Removing Directories and Files To remove a directory: rmdir <nameofdirectory> For example, to remove the clients directory: rmdir clients This directory was deleted because it was empty. If there were other items or files contained in this directory, you would have to use the rm –r command to delete it. To remove or delete a symbolic link:rm <symbolic link> The removal of a symbolic link will not affect nor delete the original file. To view the listing of directories and files created type: ls –l (or –all) at the command prompt. C1L9S18

  19. Summary Linux distributions use the Filesystem Hierarchy Standard (FHS) to determine the content and location of files and directories, but not all Linux distros follow this standard precisely. Linux is case sensitive so upper and lower case letters are differentiated. However, Linux treats everything within the OS as files. The main file location is called the root directory and is represented with a forward slash (/). File locations are called paths and can be relative or absolute. Relative paths are referenced based on your current location within a directory, while absolute paths have a fixed location and are not based on your current directory or location. Absolute paths reference the root directory. Linux accepts various commands at a command prompt to create, move, view, locate, rename, and delete files. C1L9S19

More Related