SUSE Linux Enterprise Desktop Administration Chapter 7 Manage Directories and Files
SUSE Linux Enterprise Desktop Administration Objectives Objective 1—Understand the File System Hierarchy Standard (FHS) Objective 2—Identify File Types in the Linux System Objective 3—Change Directories and List Directory Contents 2
SUSE Linux Enterprise Desktop Administration Objectives (continued) Objective 4—Create and View Files Objective 5—Work with Files and Directories Objective 6—Find Files on Linux 3
SUSE Linux Enterprise Desktop Administration Objective 1—Understand the File System Hierarchy Standard (FHS) The file system concept of Linux is considerably different than that of other operating systems A filename in Linux can be up to 255 characters long –Can contain any number of special characters You can also use umlauts, letters with diacritical marks, or other country-specific characters Linux differentiates between uppercase and lowercase letters 4
SUSE Linux Enterprise Desktop Administration The Hierarchical Structure of the File System Linux file system involves a hierarchical file system that can be depicted in the form of a tree Tree is not limited to a local partition –Can stretch over several partitions, which can be located on different computers in a network –Begins at the root A file in the tree is uniquely defined by its path Path refers to the directory names that lead to a file –Relative path –Absolute path 5
SUSE Linux Enterprise Desktop Administration6 Figure 7-1 Linux hierarchical file system The Hierarchical Structure of the File System (continued)
SUSE Linux Enterprise Desktop Administration The Hierarchical Structure of the File System (continued) The absolute path always begins with a slash (‘‘/’’), the symbol for the root directory You can change directories with the cd command –Using both absolute and relative paths 7
SUSE Linux Enterprise Desktop Administration FHS (Filesystem Hierarchy Standard) The structure of the file system is described in the Filesystem Hierarchy Standard (FHS) –Specifies which directories must be located on the first level after the root directory and what they contain The FHS defines a two-layered hierarchy: –The directories in the top layer (immediately below the root directory ‘‘/’’) –As a second layer, the directories under /usr and /var 8
SUSE Linux Enterprise Desktop Administration Root Directory (/) The root directory refers to the highest layer of the file system tree –Normally only directories (not files) are located here When the system is booted, the partition on which this directory is located is the first one mounted The following directories always have to be on the same partition as the root directory: –/bin, /dev, /etc, /lib, and /sbin 9
SUSE Linux Enterprise Desktop Administration Essential Binaries for Use by All Users (/bin) /bin contains executable programs that are required when no other file systems are mounted 10 Table 7-1 Some of the programs in the /bin directory
SUSE Linux Enterprise Desktop Administration Boot Directory (/boot) Contains static files of the boot loader GRUB The backed-up information for the Master Boot Record (MBR) and the system map files are also stored here Also contains the kernel that has the filename vmlinuz 11
SUSE Linux Enterprise Desktop Administration Other Partitions (/data) If YaST finds other (non-Windows) partitions or another hard disk during the installation –Creates mountpoints for each partition labeled: /data1 /data2 /dataX 12
SUSE Linux Enterprise Desktop Administration Device Files (/dev) Each hardware component existing in the system is represented as a file in the /dev directory Two kinds of device files are included: –Character-oriented device files –Block-oriented device files Major device numbers –Connection to device drivers in the kernel is implemented via numbered channels Corresponding to the number of the device driver in question 13
SUSE Linux Enterprise Desktop Administration Device Files (/dev) (continued) A driver might be responsible for several devices of the same type –To distinguish between these devices, the minor device number is used Most device files are created dynamically by udev in /dev –When the corresponding hardware is detected during the boot process The null device /dev/null is also located in this directory 14
SUSE Linux Enterprise Desktop Administration15 Table 7-2 Some important device files
SUSE Linux Enterprise Desktop Administration Configuration Files (/etc) The /etc directory and its subdirectories contain system configuration files –Almost all of them can be processed with any editor Normal users can read nearly all of these files, but they cannot edit any of them –According to the FHS, no executable programs can be located here –Subdirectories contain many shell scripts 16
SUSE Linux Enterprise Desktop Administration17 Table 7-3 Some important configuration files
SUSE Linux Enterprise Desktop Administration User Directories (/home) Home directory –Every user on a Linux system has his or her own area in which to work with files Individual configuration files can be found in the user’s home directory –These configuration files are hidden files –All these files have names that begin with a dot The home directory of a user can also be addressed via the shortcut “~” 18
SUSE Linux Enterprise Desktop Administration19 Table 7-4 Some important files in a user’s home directory
SUSE Linux Enterprise Desktop Administration Libraries (/lib) Many programs use specific functions that are also used by other programs –Functions are removed from the actual program, stored in the system, and only called up when the program runs Called shared libraries The /lib directory contains the libraries that are used by programs in the /bin and /sbin directories The kernel modules are located in the /lib/modules/ directory –Find additional libraries below the directory /usr 20
SUSE Linux Enterprise Desktop Administration Mountpoints for Removable Media (media/*) SUSE Linux creates directories in the /media/ directory for removable media it detects: –/media/floppy/—Created for a floppy disk drive –/media/cdrom/—Created for a CD-ROM drive –/media/cdrecorder—Created for a CD burner –/media/dvd—Created for a DVD drive –/media/usbdisk/—Created for a USB stick –/media/medianame—Created after inserting a labeled removable media 21
SUSE Linux Enterprise Desktop Administration Application Directory (/opt) Installed programs can store their static files in the /opt directory First, a directory with the name of the application is created –The files are then stored in that directory Examples include GNOME (/opt/gnome) and KDE (/opt/kde3) 22
SUSE Linux Enterprise Desktop Administration Home Directory of the Administrator (/root) The home directory of the system administrator should be on the same partition as the root directory, ‘‘/’’ Only then is it guaranteed that the user root can: –Always log in without a problem –Have his or her own configured environment available 23
SUSE Linux Enterprise Desktop Administration System Binaries (/sbin) The /sbin directory contains important programs for system administration Programs that are run by normal users are also located in /bin Programs in the /sbin directory can also, as a rule, be run by normal users –But only to display the configured values Changes to the configuration can only be made by the user root 24
SUSE Linux Enterprise Desktop Administration25 Table 7-5 An overview of important files in the /sbin directory System Binaries (/sbin) (continued)
SUSE Linux Enterprise Desktop Administration Data Directories for Services (/srv) The subdirectories of the /srv directory contain data of various services Examples: –The files of the Apache Web server are located in the /srv/www/ directory –The FTP server files are located in the /srv/ftp/ directory 26
SUSE Linux Enterprise Desktop Administration Temporary Area (/tmp) Various programs create temporary files that are stored in /tmp until they are deleted 27
SUSE Linux Enterprise Desktop Administration The Hierarchy Below /usr The /usr directory, in accordance with the FHS, represents a second hierarchical layer This is the location for all application programs, graphical interface files, additional libraries, locally installed programs, and commonly shared directories containing documentation 28
SUSE Linux Enterprise Desktop Administration29 Figure 7-6 Some of the important files in the /usr directory The Hierarchy Below /usr (continued)
SUSE Linux Enterprise Desktop Administration Variable Files (/var) The /var directory and its subdirectories contain files that can be modified while the system is running 30 Figure 7-7 Some of the most important directories beneath /var
SUSE Linux Enterprise Desktop Administration Windows Partitions (/windows) If YaST finds any partitions with a Microsoft file system, it automatically creates a /windows directory Inside this directory: subdirectories labeled with Windows drive characters 31
SUSE Linux Enterprise Desktop Administration Process Files (/proc) Linux handles process information that is made available to users via the /proc directory The /proc directory is generated dynamically when it is accessed –Contains files and directories –Each process has its own directory /proc also includes directories and files containing information about the state of the system 32
SUSE Linux Enterprise Desktop Administration33 Figure 7-8 Some of the important files in the /proc directory Process Files (/proc) (continued)
SUSE Linux Enterprise Desktop Administration System Information Directory (/sys) The /sys directory provides information, in the form of a tree structure, on various hardware buses, hardware devices, active devices, and their drivers Like the /proc directory, /sys is generated dynamically when it is accessed 34
SUSE Linux Enterprise Desktop Administration Mountpoint for Temporarily Mounted File Systems (/mnt) The standard directory for integrating file systems is /mnt –Should only be used for temporary purposes –For permanent mounts, you should create an appropriately named directory Mount hard drive partitions using the mount command To remove a partition, use the umount command If the file system format is not supported by the kernel, the command is aborted 35
SUSE Linux Enterprise Desktop Administration Directories for Mounting Other File Systems A directory must exist at the point where you intend to mount the file system –Referred to as the mount point In most cases, only the user root can mount and unmount directories –Removable media can be changed by a normal user The file /etc/mtab shows which file systems are currently mounted You can also share certain directories with many computers 36
SUSE Linux Enterprise Desktop Administration37 Table 7-9 Directories that can be shared Directories for Mounting Other File Systems (continued) Table 7-10 Directories that cannot be imported from other computers
SUSE Linux Enterprise Desktop Administration Exercise 7-1: Explore the SUSE Linux File System Hierarchy In this exercise, describe what directories the characters / and ~ refer to –Then, find out the mount point of the DVD –Mount the DVD manually at another position (/mnt) in the file system 38
SUSE Linux Enterprise Desktop Administration Objective 2—Identify File Types in the Linux System Available file types: –Normal Files –Directories –Device Files –Links –Sockets –FIFOs 39
SUSE Linux Enterprise Desktop Administration Normal Files Refer to files as they are also known in other operating systems: –Sets of contiguous data addressed with one name The names for such files can be freely chosen and there is no division into filename and file type 40
SUSE Linux Enterprise Desktop Administration Directories Directories are used to organize files and directories into groups Directories contain two entries with which the structure of the hierarchical file system is implemented –One of these entries (‘‘.’’) points to the directory itself –The other entry (‘‘..’’) points to the entry one level higher in the hierarchy 41
SUSE Linux Enterprise Desktop Administration Device Files Each piece of hardware in a Linux system is represented by a device file –With the exception of network cards Every program that wants to access hardware must access it through the corresponding device file –The programs write to or read from a device file The kernel then ensures that the data finds its way to the hardware or can be read from the file 42
SUSE Linux Enterprise Desktop Administration Links Links are references to files located at other points in the file system Data maintenance is simplified through the use of such links –Changes only need to be made to the original file –The changes are then automatically valid for all links 43
SUSE Linux Enterprise Desktop Administration Sockets A socket refers to a special file in the file system –Implements data exchange between two locally running processes 44
SUSE Linux Enterprise Desktop Administration FIFOs FIFO (First In First Out) or ‘‘named pipe’’ –Files that are used to exchange data between processes A FIFO file can only exchange data in one direction 45
SUSE Linux Enterprise Desktop Administration Objective 3—Change Directories and List Directory Contents You can use the following commands to change the active directory and list the contents of a directory: –cd –ls –pwd 46
SUSE Linux Enterprise Desktop Administration cd You can use the cd (change directory) command to change between directories 47 Table 7-11 Examples of the cd command
SUSE Linux Enterprise Desktop Administration ls The ls (list) command lists the specified files 48 Table 7-12 The most important options of the ls command
SUSE Linux Enterprise Desktop Administration pwd You can use the pwd (print working directory) command to display the path of the current directory If you enter pwd with the -P option, pwd prints the physical directory without any symbolic links 49
SUSE Linux Enterprise Desktop Administration Exercise 7-2: Change Directories and List Directory Contents In this exercise, describe what directories the characters. and.. refer to Then, change between directories (cd), display the name of the active directory (pwd), and list directory contents (ls) 50
SUSE Linux Enterprise Desktop Administration Objective 4—Create and View Files To create and view files, you need to know how to do the following: –Create a New File with touch –View a File with cat –View a File with less –View a File with head and tail 51
SUSE Linux Enterprise Desktop Administration Create a New File with touch You can use the touch command to change the time stamp of a file –Or create a new file with a size of 0 bytes 52 Table 7-13 The most important options of the touch command
SUSE Linux Enterprise Desktop Administration View a File with cat You can use the cat (concatenate) command to view the contents of a file –The command must include the filename of the file you want to see 53
SUSE Linux Enterprise Desktop Administration View a File with less You can use the less command to display the contents of a file page by page –Even compressed files (such as.gz and.bz2) can be displayed 54
SUSE Linux Enterprise Desktop Administration View a File with less (continued) 55 Table 7-14 Keystrokes used with the less command
SUSE Linux Enterprise Desktop Administration View a File with head and tail With the head command, you can view only the first few lines of a file The tail command shows you only the last few lines of a file By default, these commands only show 10 lines When used with the tail command, the option -f displays a continuously updated view of the last lines of a file 56
SUSE Linux Enterprise Desktop Administration Exercise 7-3: Create and View Files In this exercise, create an empty new_file file Then, display the content of the /var/log/messages file in the following ways: –At once with the cat command –Page by page with the less command; then, look for the word root in the file –In the first five lines with the head command –In the last lines continuously updated with the tail command –To view new log data, log in and log out as root 57
SUSE Linux Enterprise Desktop Administration Objective 5—Work with Files and Directories In this objective, you learn how to do the following: –Copy, Move, and Rename Files and Directories –Create Directories –Delete Files and Directories –Link Files 58
SUSE Linux Enterprise Desktop Administration Copy, Move, and Rename Files and Directories Move and rename files with mv –You can use the mv (move) command to move one or more files to another directory 59 Table 7-15 The options of the mv command
SUSE Linux Enterprise Desktop Administration Copy, Move, and Rename Files and Directories (continued) Copy files with cp –You can copy files and directories with the cp (copy) command –When using the command cp, remember the following: cp overwrites existing files without confirmation Avoid automatic overwriting by using the option –i –If you want to copy just the contents of a directory, the target directory must already exist 60
SUSE Linux Enterprise Desktop Administration Copy, Move, and Rename Files and Directories (continued) 61 Table 7-16 The options of the cp command
SUSE Linux Enterprise Desktop Administration Create Directories You can use the mkdir (make directory) command to create new directories The option -p lets you create a complete path, as in the following example: – mkdir --p proposal/january 62
SUSE Linux Enterprise Desktop Administration Delete Files and Directories Use rmdir to delete empty directories –You can use the rmdir (remove directory) command to remove the indicated directory or directories Use rm to delete files and directories –You can use the rm (remove) command to delete files without being asked for confirmation 63
SUSE Linux Enterprise Desktop Administration Delete Files and Directories (continued) 64 Table 7-17 The options of the rm command
SUSE Linux Enterprise Desktop Administration Exercise 7-4: Copy, Move, and Delete Files, Create and Delete Directories In this exercise, copy and move files with the cp and mv commands, create new directories with the mkdir command, and delete files and directories with the rm and rmdir commands 65
SUSE Linux Enterprise Desktop Administration Link Files File system formats in Linux keep data and administration information separate Each file is described by an inode (index node or information node) –To see the inode number, you can enter ls –i –Each inode is 128 bytes and contains all the information about this file apart from the filename The ln command creates a link –A link is a reference to a file 66
SUSE Linux Enterprise Desktop Administration Link Files (continued) Linux recognizes two kinds of links: –Hard links –Symbolic links You create a hard link by using the ln command, which points to the inode of an already existing file –Hard links can only be used when both the file and the link are in the same file system You can create a symbolic link with the ln command and the option –s –A symbolic link is assigned its own inode 67
SUSE Linux Enterprise Desktop Administration Link Files (continued) With symbolic links, the limits of the file system can be overcome The disadvantage is that a symbolic link can point to a nonexisting object An advantage of symbolic links is that you can create links to directories 68
SUSE Linux Enterprise Desktop Administration Exercise 7-5: Link Files In this exercise, create a symbolic link to the ~/my_file file and a hard link to the ~/my_file1 file with the ln command 69
SUSE Linux Enterprise Desktop Administration Objective 6—Find Files on Linux Two wildcards –‘‘?’’ (for any character) –‘‘*’’ (for none, one, or several characters) The following tools are introduced in this objective: –graphical search tools –find –which –type 70
SUSE Linux Enterprise Desktop Administration Graphical Search Tools If you enter search in the More Application search bar, you find two applications: –The Desktop Search Tool (Search) –The GNOME Search Tool (Search for Files) Search (Search) –When you enter a search term into the Desktop Search Tool, a list of documents that contain the search term appears as soon as you stop typing –Desktop Search Tool can be configured by selecting Search > Preferences 71
SUSE Linux Enterprise Desktop Administration72 Figure 7-3 The Desktop Search Tool
SUSE Linux Enterprise Desktop Administration73 Figure 7-4 Configuring the Desktop Search Tool
SUSE Linux Enterprise Desktop Administration Graphical Search Tools (continued) Search (Search) (continued) –The Indexing tab allows you to configure what is included in or excluded from the search index –See Figure 7-5 Search for files (GNOME Search Tool) –Allows you to search for information such as file size, date, or file owner –See Figures 7-6 and
SUSE Linux Enterprise Desktop Administration75 Figure 7-5 Configuring the Desktop Search Tool
SUSE Linux Enterprise Desktop Administration76 Figure 7-6 The GNOME Search Tool Graphical Search Tools (continued)
SUSE Linux Enterprise Desktop Administration77 Figure 7-7 More options for the GNOME Search Tool Graphical Search Tools (continued)
SUSE Linux Enterprise Desktop Administration find To search for files on the command line, you can use the find command Syntax for the find command: –find path criterion action Actions include the following: –print (default) –exec command 78
SUSE Linux Enterprise Desktop Administration79 Table 7-19 The properties the file should have
SUSE Linux Enterprise Desktop Administration which The which command searches all paths listed in the variable PATH for the specified command –Returns the full path of the command The PATH variable contains the directories where the shell looks for executable files You use which if you want to know which program is executed –When the command is entered without specifying a path 80
SUSE Linux Enterprise Desktop Administration type The type command command can be used to find out what kind of command is executed –When command is entered The option -a delivers all instances of a command bearing this name in the file system 81
SUSE Linux Enterprise Desktop Administration Exercise 7-6: Find Files on Linux In this exercise, find files with the whereis, which, and find commands and with the GNOME Search Tool 82
SUSE Linux Enterprise Desktop Administration Summary The Linux file system is arranged hierarchically using a series of directories to store files Regardless of the number of file systems, there is only one root directory in Linux, denoted by a ‘‘/’’ character Linux directories and files follow the Filesystem Hierarchy Standard (FHS) and their location can be described using absolute or relative pathnames 83
SUSE Linux Enterprise Desktop Administration Summary (continued) The /bin and /sbin directories contain executable binary programs The /boot directory contains information used to load the Linux kernel The /dev directory contains character and block- oriented device files that are used to identify most hardware devices on the Linux system 84
SUSE Linux Enterprise Desktop Administration Summary (continued) Most system configuration information is stored in text files under the /etc directory and shared libraries are stored under the /lib directory Home directories are typically located under the /home directory The /media and /mnt directories typically contain mount point subdirectories 85
SUSE Linux Enterprise Desktop Administration Summary (continued) There are many types of files that can exist on the Linux file system Text files are the most common file type; contents can be viewed by several utilities There are many file management commands Files can be a link to another file by name or by inode You can find files on the file system using a variety of utilities 86