Cit 370 Lab Exercise 10 Topic: The Linux File System




Дата канвертавання27.04.2016
Памер10.97 Kb.
CIT 370 Lab Exercise 10

Topic: The Linux File System

Due Date: Thursday, October 8


Read the notes on the Linux File System before starting this lab. Start VMware and boot your CentOS virtual machine. Log in as yourself and open two terminal windows. In one, open vi to answer questions. In the other, you will do various commands. As usual, questions are placed in italics and commands in bold courier font.


  1. Exploring the file system

    1. The df command reports the disk file space usage. Enter df and look over the results. What do the results mean? Hint: recall the partitioning steps from the Linux installation.

    2. The various parts of the file system are made available by mounting them. You can see what is mounted at boot time by looking at the /etc/fstab file, and what is currently mounted by looking at the /etc/mtab file. Look at these. Compare them line by line and see if you can make sense of how they appear. NOTE: rw, in mtab means that the file space is readable and writable, ro would be read only. The command mount will mount a partition to the filespace while umount will unmount a partition. If a partition is unmounted, it is no longer accessible (until it is mounted again). To mount all of the file systems in /etc/fstab, use mount –a. Type cat /etc/fstab again and examine the contents. How do the lines of this file relate to what you saw when you did df? Type umount /var. What happened? su to root and repeat this. What happened? Obviously, you cannot umount a file system that is currently busy, and the system uses /var all the time. You would also not be able to umount /home since you have a file open. Two partitions that are not busy at the moment are sys and tmpfs. Umount tmpfs. What instruction did you enter? To remount a partition, you type mount device location, as in mount /dev/sda5 /home (if /home were stored at /dev/sda5). For tmpfs, the device is /dev/shm. Mount tmpfs again. What instruction did you type in? Note: if this does not work you can also remount it by doing mount –a. Do df again to make sure that tmpfs is mounted again. Now unmount /sys and then try to remount it. How were you able to do these? Exit as root.

    3. The du instruction can be useful for a system administrator who needs to determine if a user is using more than their fair share of disk space. The du instruction tells you the amount of disk usage that a particular directory is using. Switch to root so that you can access all of the various directories in spite of permissions. Now cd to your own directory and type du. You will see all of your subdirectories listed before you see the final number. Type du –s to limit the output to just the size of the directory. What was the result? Now do du /home/zappaf. What was output? Now do du /etc and compare the result to du –s /etc. What is the size of etc? Exit from root and retry the last command. What happened and why?

    4. cd to /dev and look at the files. Everything in the Linux file system is a file, including devices. The idea is the same as redirecting your output to a file or redirecting a file to input, but in these cases the file is really some type of device. If you do an ls –l, the first entry in the permission list describes the type of file (we are used to seeing – for files, d for directories, or l for symbolic links). Type the command ls -l /dev/s* The “b” for the file type indicates block storage. What types of devices are these? Type ls –l /dev/console. This is the system console. What is the file type? (See Table 4-3 on page 176). What type is associated with the letter “s”? Name a file that is of this type.

    5. Explore the programs in /bin, /usr/bin, /sbin and /usr/sbin. How do these programs differ in terms of the types of programs and their uses? That is, why are these executable programs separated into three groupings like they are?

    6. The PATH variable stores directories to automatically check when you issue a command. The which command will search all directories in PATH along with the current directory for a file. Explore the which command and find out where each of these files is located: yum, sed, useradd. What did you find out from each of your which commands? Why did you get the result you did for useradd? Another way to find the location of a file is through find, which you will explore next.




  1. Find The find command allows you to search the some portion of the file system for files. Read about the command on page 178. To list the .txt files starting in your home directory, you would enter find ~ -name “*.txt” –print | less where ~ means your home directory, -name *.txt means to search for anything named “*.txt”, and –print means to output the results to the screen. Note: if you want to search starting at / (the root of the file space), you should be root because you, as a normal user, will not have access to many directories. You can also use –ls instead of –print.

  1. Use the find command to locate myfoo.txt. What was the output of the command?

  2. Type which brl_nbchords. Notice that the file isn’t in one of the locations in your path. So now, use find to locate brl_nbchords. Where did you find it?

You can use the find command to find files based on various parameter values instead of name, such as the last modification time (date), last access time (date), file size, file permission and whether a file is empty. For modification and access time, use –mtime and –atime followed by +# or -# where # is an integer value like 10 (for 10 days). To combine multiple conditions, place the mtime and atime statements within \( and \) and separate each item with –o for or, and –a for and. The command find ~ \( -mtime +10 –o –atime +10 \) –ls will find files that were last modified more than 10 days ago or accessed more than 10 days ago. The –perm option allows you to compare permissions. You follow –perm by the 3 digit value of a permission, so for instance to find all files whose permissions are 744 use –perm 744. The –size option allows you to specify a size where the size is a numeric value, a + (more than) or – (less than) and a unit such as ‘c’ for bytes, k for kilobytes, M for megabytes and G for gigabytes. For instance, find ~ -size +10000c –print finds all files in your home directory greater than 10000 bytes. Return to your own account to do steps c-f.

  1. Find all files in your directory starting at ~ that were modified or accessed within the last 2 days (use – instead of +). Which ones were listed?

  2. Enter a find command to locate all ordinary files in your directory space with rw-rw-r-- permission. Try again with r-xr-xr--. What commands did you come up with?

  3. Find and print all files in your file space whose size is less than 50 bytes. What command did you enter? How many files were found?

  4. The –empty parameter will find any file or directory that is empty. Find all empty files in your home directory. What files did you find? What command did you enter?


Email your answers file to your instructor, shutdown your VM, exit out of VMware and log off.


База данных защищена авторским правом ©shkola.of.by 2016
звярнуцца да адміністрацыі

    Галоўная старонка