380 likes | 561 Views
Chapter 6. Linux File System. File System. File System management how to store informations on storage devices. /. home. etc. bin. boot. usr. dev. lib. root. …. local. bin. Structure of the Linux File System. Structure of the Linux File System.
E N D
Chapter 6 Linux File System
File System • File System management how to store informations on storage devices
/ home etc bin boot usr dev lib root … local bin Structure of the Linux File System
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
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)
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
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 )
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
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
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
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
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
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
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
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
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
Searching the File System • find , locate, grep • search 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”
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
Searching the File System • Using grep to search for content within a file grep search_text file grep “help” *.txt
Partitions • To store information on a storage device • First, making partitions • Each Partition corresponding with one device, and have a device drive file in /dev • Parttitions as sda1, sda2, sda3 ,… have device drive files as /dev/sda1, /dev/sda2, /dev/sda3, … • Second, formating a partition using a style of file system • ext2, ext3, reiser, … • And, mounting file system with a directory in the directory tree
sda / sda1 sda2 home etc bin usr sda3 local bin sda4 Cấu trúc logic hệ thống tập tin Ổ đĩa vật lý
File /etc/fstab Device : Mount point : fstype : options : dump-number : fsck-number Page 309
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
5 6 7 8 Partitions M B R 1 2 3 4 primary M B R 1 2 3 4 logical extended
Using fdisk utility • Using fdisk utility to make partitions $ 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
Using fdisk utility • To make a new partition • Choose making a primary partition or extended partition ? • Size of partition (MB or start and end cylinder)
Using fdisk utility • To view the partition table $ fdisk -l
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
Format partition • Using a specify file system that supported by kernel • ext2, ext3, ext4, reiser ,… // Linux • vfat, fat32, ntfs // Windows • iso9660 //Cdrom • … • Using mkfs to make an ext2 or ext3 file system on a partition $ mkfs -t ext3 /dev/sdc1 • mkswap to make swap partition
Format partition • Orther commands : • Mk2fs • Mkreiserfs • mkreiserfs /dev/sdc3 • mkfs.msdos • mkfs.vfat • …
Mounting • You have to mount store devices before you can use them • The mount utility mounts the partition into an existing directory in your file system. • Any directory that you can mount a partition. But default location for mounting removable devices is /media for SUSE, /mnt for Fedora,..
Mounting • mount -t file_system_type device mount_point $ mount –t vfat /dev/sdb2 /media/usb $ mount –t -o roiso9660 /dev/cdrom /media/cd $ mount // to view all mounted file system
unmount • umount dir_name • umount device_name Unmount to make synchronic => have to unmount before unplug removable devices Unmount to free the mount point