Introduction:
Hard disks and storage devices are normally divided up into smaller chunks called partitions. A partition is a way to compartmentalize a disk. Different parts of it can be formatted with different file systems or used for different purpose. For example, one partition could contain user home directories while another could contain system data and logs. If a user fills up the home directory partition with data, the system partition may still have space available. Placing data in two separate file systems on two separate partitions helps in planning data storage.
Storage devices are represented by a special file type called block device. The block device is stored in the /dev directory. In Red Hat Enterprise Linux, the first SCSI, PATA/SATA, or USB hard drive detected is /dev/sda, the second is /dev/sdb, and so on. This name represents the whole drive. The first primary partition on /dev/sda is /dev/sda1, the second partition is /dev/sda2 and so on.
Display the file system and mount points [root@asim ~]#df |
Display file with human readable format [root@asim ~]#df -h |
Show a disk usage report for the /root directory [root@asim ~]#du /root |
Mounting and Unmounting file system manually
The mount command expects the file system argument in one of two different ways:
The device file of the partition holding the file system, residing in /dev
The UUID, a universal unique identifier of the file system.
Check UUID and other details of devices [root@asim ~]#blkid |
Mount by device file of the partition that holds the file system [root@asim ~]#mount /dev/vdb1 /mnt/xyz |
Mount file system by UUID, [root@asim ~]#mount UUID=”12xz97 1265qd 49624s 78qsz6” /mnt/xyz |
Unmounting the device [root@asim ~]#umount /mnt/xyz |
List all open files and the process [root@asim ~]#lsof /mnt/xyz |
Accessing removable storage device
Removable media, such as USB flash device and drives, get automatically mounted by the graphical desktop environment when plugged in. The mount point for the removable medium is /run/media/<user>/<label>.
The <user> is the user logged into the graphical environment.
The <label> is the name given to the file system when it was created.
Steps to mount and unmount a removable pen drive
[root@asim ~]#blkid [root@asim ~]#mkdir /mnt/xyz Or [root@asim ~]#mount UUID=”12xz97 1265qd 49624s 78qsz6” /mnt/xyz [root@asim ~]#cp f1.txt /mnt/xyz [root@asim ~]#umount /mnt/xyz |
Managing links between files
Creating a hard links:
A hard link is a new directory entry with a reference to an existing file on the file system. Every file in a file system has one hard link by default. To save space, instead of copying, a new hard link can be created to reference the same file. A new hard link either needs to have a different file name, if it is created in the same directory as the existing hard link, or it needs to reside in a different directory. All hard links pointing to the same file have the same permissions, link count, user/group ownership, time stamps, and file content. Hard link pointing to the same file content need to be on the same file system.
[root@asim ~]#mkdir –p today/1/2/3/4/5/6 [root@asim ~]#cat>today/1/2/3/4/5/6/original Contents [root@asim ~]#tree today/ [root@asim ~]#ln today/1/2/3/4/5/6/original linkname [root@asim ~]#ls –l (shows linkname entry) [root@asim ~]#cat linkname [root@asim ~]#rm today/1/2/3/4/5/6/original [root@asim ~]#cat linkname (still display the same content because hard link is not deleted [root@asim ~]#ln –s /dev /root/devicefiles [root@asim ~]#ls [root@asim ~]#cd /devicefiles [root@asim ~]#ls (show all the content of /dev) |
Tools for finding files (Locate and Find)
A system administrator needs tools for searching files matching certain criteria on the file system. This section discusses two commands that can search files in the file system. The locate command searches a pre generated database for file names or file paths and returns the results instantly. The find command searches the file system in real time by crawling through the file system.
When searching entries as a regular user, results are returned only for where the user invoking the locate search has read permissions on the directory trees readable by user student on machine.
[root@asim ~]#locate passwd
[root@asim ~]#locate image
[root@asim ~]#locate –l message
[root@asim ~]#locate –n 5 image.png
[root@asim ~]#find / -name sshd_config
[root@asim ~]#find / -name ‘*.txt’
[root@asim ~]#find /etc –name ‘*pass*’
[root@asim ~]#find / – iname ‘*messages*’
[root@asim ~]#find –user student
[root@asim ~]#find -group student
[root@asim ~]#find –uid 1000
[root@asim ~]#find –gid 1000
[root@asim ~]#find /home – perm 764
[root@asim ~]#find –size 10M
[root@asim ~]#find – size +10G
[root@asim ~]#find – size -10K