1 / 51

Chapter 6

Chapter 6. Linux File System. File System. File System management how to store informations on storage devices The Hierarchical Structure Types of file Common File system Tasks. /. home. etc. bin. boot. usr. dev. lib. root. …. local. bin.

zarita
Download Presentation

Chapter 6

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. Chapter 6 Linux File System

  2. File System File System management how to store informations on storage devices • The Hierarchical Structure • Types of file • Common File system Tasks

  3. / home etc bin boot usr dev lib root … local bin The Hierarchical Structure of the Linux File System

  4. The Hierarchical Structure of the Linux File System • / - first of mount point in linux • /bin - contains shells (bash) and file system management utilities • /etc - keep linux text-based configuration files • /boot - keep important linux booting files • /dev - keep all device files • /usr - keep all user binary and X library • /home - keep user home directory • /proc - is pseudo file system for tracking running process and state of linux system

  5. The Hierarchical Structure of the Linux File System • /var - keeping variable data, log file and printer spooling • /lib - contain shared library that is required by system program • /tmp - contain system temporary file • /root - the root user’s home directory • /sbin - contains important system management and admin files (fdisk, fsck, ifconfig, init, mkfs, shutdown, halt) • /media - system use to mount externel devices (CD/DVD , floppy drives) (or /mnt)

  6. The Hierarchical Structure of the Linux File System • Files in /etc directory

  7. The Hierarchical Structure of the Linux File System • FHS (Filesystem Hierarchy Standard) provide a standard directory structure for the file system, ensuring consistency between systems and distributions. • http://www.pathname.com/fhs

  8. Types of Files • Regular files • Links • FIFOs • Sockets

  9. Navigating the File System • Path • absolute path • Current directory& relative path • Home directory (~) • pwd, cd, ls • pwd (Present Working Directory) • Display the current directory $ pwd • cd • Change the current directory $ cd /var/log $ cd.. $ cd ~ (or press cd )

  10. Navigating the File System • pwd, cd, ls • ls • List the files and subdirectories that exist within a directory $ ls / $ ls /bin $ ls –l / $ ls –a /var/run $ ls –R /var/run $ ls

  11. Navigating the File System $ ls –l ~ 1 file type 2 Owner’s /Group/Other Permissions 3 Number of link 7 Last Update datetime 6 Size 5 Group’s name 4 Owner’s name 8 File/Dir name

  12. Navigating the File System • File type • normal file - • Block device file b • Character device file c • Directory d • Link file l • Permissions on file /directory • Read r • Write w • Execute x

  13. Creating Files and Directories • Creating a new file : touch or vi • touch command touch myfile.txt // size = 0 • Using a Text editor vi newfile.txt vi /home/user1/file.txt • Creating a directory : mkdir mkdir myDir mkdir /home/ti/myDir mkdir -p /home/ti/aa/bb

  14. Viewing text file content • cat, more, less, head, tail cat filename |more more filename less filename • Auto stop when full screen. Using spacebar, page up, page down, arrow keys when viewing head filename • Display the first couple of lines of a text file tail filename • Display the last couple of lines of a text file • tail –f filename : display new content to be added to the end of the file

  15. Copying, moving, deleting • cp, mv, rm, rmdir cp /tmp/schedule.txt ~ //copy file cp –R ~/myDir ~/backup //copy dir. mv /tmp/mylog.txt /var/log //move file mv myfile.txt mynewfile.txt //rename rm filename //delete file rm -r dirname //delete directory rm -i filename //prompt rmdir dirname//delete empty directory

  16. Using wildcard charaters • * , ? , [ab] , [a-z] Example : there are these files in current directory vd.txt, vda.txt, vdb.txt, vdabc.txt, vd1.txt, vd22.txt , vd3.txt $ cp *.txt /home/an //copy 7 files $ cp vd[1-5].txt /home/an // copy 2 file $ cp vd[ab].txt /home/an // copy 2 file

  17. Link files • Hard link and Symbolic link (soft link) • Pointers a different file/directory in the file system • Symbolic link : similar shortcut in Windows OS • ln pointee_file pointer_file • ln -s pointee_file pointer_file (pointee_file = source file/dir pointer_file = hard link/ symbolic link file) $ ln -s /usr/share/doc/ ~/docs

  18. Running executable file Linux OS searches through the directories listed in your PATH environment variable for the executable file you specified. • Adding a new path to the $PATH PATH=$PATH:newpath • Determine resident of exec file which $ which vi /usr/bin/vi $ which ls /bin/ls

  19. Searching the File System • find , locate, grep • Find utility searchs for files of a specified name, or owner, or size • Using *, ? when specified name find path -name “filename” find path -user “username” find path -size “size” find path -size “+size” find path -size “-size” find / -name “*.log” find / -user “root” find / -size “+100”

  20. Searching the File System • Locate utility builds an index of the files. When searching files, locate runs a query of the index, doesn’t search the file system directly. • Locate runs much faster than find • To use locate , must first install the findutils-locate package

  21. Searching the File System • Using grep to search for content within a file grep search_text file grep –r “help” /*.txt grep “help” *.txt

  22. Manage Disk Partitions • Using fdisk to create disk partitions • Building a file system with mkfs • Mounting a partition with mount • Checking the file system with fsck

  23. Storage Devices In Linux system , storage devices is referenced as device files that stored in /dev directory.

  24. M B R 1 2 3 4 primary M B R 1 2 3 4 5 6 7 8 logical extended Partitions • Primary and Extended partitions • On the IDE hard disk, up to four primary partitions • One of the primary partitions can be extended partition • Include many logical partitions

  25. Partitions • Each Partition is referenced as one device, and have a device file in /dev • Partitions as sda1, sda2, sda3 ,… have corresponding device driver files as /dev/sda1, /dev/sda2, /dev/sda3, … • Ex. fdisk /dev/sda mount /dev/sda2

  26. File system • A file system style is the way that data is organized to store in the storage device • Linux supports many of fs styles • ext2, ext3, ext4, reiser ,… // Linux • vfat, fat32, ntfs // Windows • iso9660,… //cdrom • File system term also refer to a partition has been formatted with a file system

  27. Hình: Hệ thống tập tin ảo File system • Linux uses a Virtual File System (VFS) that creates a single hierarchy that encompasses all partitions on all storage devices in the system

  28. sda / sda1 sda2 home etc bin usr sda3 local bin sda4 Logic file system Storage device Mount • Mount the partition into an existing directory in your file system, before can use it (read/write data).

  29. sda / sda1 sda2 home etc bin usr sda3 hda1 local bin sda4 logic file system Storage device Unmount • Unmount the partition into a directory Storage device

  30. Unmount • T1 : / được mount với sda1 $ ls /usr/local vd1.txt • T2: /usr được mount với sda2 $ vi /usr/local/vd2.txt $ ls /usr/local ??? • T3: umount /usr với sda2 $ ls /usr/local ???

  31. Using fdisk to create disk partitions • Syntax : $ fdisk /dev/sdb =>press m to open menu • Choose p to view partition table • Choose n to make new partition • Choose d to delete a partition • Choose w to write table and exit, or q to exit without saving

  32. Using fdisk to create disk partitions • To make a new partition • Choose making a primary partition or extended partition ? • Size of partition (MB or start and end cylinder) • Have to create at least two partitions on a primary hard disk : swap partition and root partition • a swap partition • OS uses it as virtual memory • it’s size is at least twice as large as your installed RAM

  33. Using fdisk to create disk partitions

  34. Using fdisk to create disk partitions • To view the partition table $ fdisk -l

  35. Building a file system with mkfs • mkfs • Used to make an ext2 or ext3 (or FAT) file system on a partiton mkfs -t ext3 /dev/sda2 • mkreiserfs • Used to make a Reiser file system on a partition mkreiserfs /dev/sdc3 • Other utilities : • mkswap, mk2fs, mkfs.msdos, mkfs.vfat

  36. Mounting a partition with mount • mount command syntax: mount –t type devicetarget-dir • type : ext2, ext3, reiserfs, … • device : /dev/hda1, /dev/hdb1, … • target-dir : /, /var, /home, /mnt/cdrom, …

  37. / hda3, ext2 /var /home hda4,ext2 hda1,ext2 Mounting a partition with mount • Using mount command $ mount –t ext2 /dev/hda3 / $ mount –t ext2 /dev/hda4 /home $ mount –t ext2 /dev/hda1 /var

  38. Mounting a partition with mount • After mounting the partition, you can use the mount command with no options to view all mounted file systems. Or using df utility $ mount $ df (the mount command uses mtab file to view all mounted file systems )

  39. Mounting a partition with mount • Automatically mount when the system boot or reboot • The /etc/fstab file contains a list of file systems that the operating system mounts whenever it boots. • Each line specifies a separate file system to be mounted on boot partition mount_point fs_type options dump check

  40. Mounting a partition with mount • You can add a new mount partition entry in /etc/fstab that Linux will automatically mount at boot. - Using vi editor to open /etc/fstab, then add the new line …

  41. unmount • Using umount command: two ways umount dir_name umount device_name • Have to unmount before unplug removable devices • Unmount to free the mount point • Automatically unmount when the OS shutdowns (halt)

  42. Đĩa USB : /dev/sdb • Có 2 partittion /dev/sdb1 /mnt/usb1 /dev/sdb2 /mnt/usb2 • Cần rút đĩa USB => thực hiện unmount umount /dev/sdb umount /dev/sdb1 umount /dev/sdb2 Hoặc: umount /mnt/usb1 umount /mnt/usb2

  43. Checking the file system with fsck • Using fsck to check your file systems for errors and make repairs fsck device $ fsck /dev/sdc1

  44. Use Removable Media • Floppies, optical devices, USB, FireWire devices • Need to mount with a directory • Need to unmount before remove

  45. Working with floppy $ mount –t vfat /dev/fd0 /media/floppy $ mount $ vi /etc/fstab /dev/fd0 /media/floppy auto noauto,user,sync 0 0 $ mount /dev/fd0 $ umount /dev/fd0

  46. Working with optical devices • mount –t iso9660 /dev/hdc /media/cdrom • Adding a line in /etc/fstab file : /dev/hdc /media/cdrom iso9660 noauto,user,sync 0 0 so, mount a cdrom by entering mount /dev/hdc • umount /dev/hdc

  47. USB , FireWire devices • Automatically detect a new device when connect an external storage device • SCSI device • Check /var/log/messages file after connecting the device • Create on the device • A partition • A file system • Mount device mount –t auto /dev/sdd /media/thumbdrive • umount the device before remove it

  48. Using YaST • YaST utility • Install software, manage hardware settings, partition hard drives, configure bootloaders, configure network board, configure users and groups, settings for the services running on system • Ex. : Using YaST to partition on usb disk

  49. Back up data • Selecting a Backup Medium • Floppies, tape drive • CDs, DVDs • USB • External hard drives

  50. Back up data • Selecting a Backup Strategy • Selecting Backup type : Full Incremental Differential • Selecting a backup schedule • Determining what to back up

More Related