This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by yudistira-19
Examining File Systems
To get an overview of local and remote file system devices and the amount of free space available, run the df command. When the df command is run without arguments, it reports total disk space, used disk space, free disk space, and the percentage of the total disk space used on all mounted regular file systems. It reports on both local and remote file systems.
The following example displays the file systems and mount points on host.
The partitioning on the host system shows two physical file systems, which are mounted on / and /boot. This is common for virtual machines. The tmpfs and devtmpfs devices are file systems in system memory. All files written into tmpfs or devtmpfs disappear after system reboot.
To improve readability of the output sizes, there are two different human-readable options: -h or -H. The difference between these two options is that -h reports in KiB (210), MiB (220), or GiB (230), while the -H option reports in SI units: KB (103), MB (106), or GB (109). Hard drive manufacturers usually use SI units when advertising their products.
For more detailed information about space used by a certain directory tree, use the du command. The du command has -h and -H options to convert the output to human-readable format. The du command shows the size of all files in the current directory tree recursively.
Show a disk usage report for the /usr/share directory on host:
Identifying the Block Device
A hot-pluggable storage device, whether a hard disk drive (HDD) or solid-state device (SSD) in a server caddy, or a USB storage device, might be plugged into a different port each time they are attached to a system.
Use the lsblk command to list the details of a specified block device or all the available devices.
The lsblk -fp command lists the full path of the device, along with the UUIDs and mount points, as well as the type of file system in the partition. If the file system is not mounted, the mount point will be blank.
Unmounting File Systems
The shutdown and reboot procedures unmount all file systems automatically. As part of this process, any file system data cached in memory is flushed to the storage device thus ensuring that the file system suffers no data corruption.
#umount /mnt/data
Unmounting is not possible if the mounted file system is in use. For the umount command to succeed, all processes needs to stop accessing data under the mount point.
In the example below, the umount fails because the file system is in use (the shell is using /mnt/data as its current working directory), generating an error message.
[root@host ~]# cd /mnt/data
[root@host data]# umount /mnt/data
umount: /mnt/data: target is busy.
The lsof command lists all open files and the process accessing them in the provided directory. It is useful to identify which processes currently prevent the file system from successful unmounting.
[root@host data]# lsof /mnt/data
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 1593 root cwd DIR 253,17 6 128 /mnt/data
lsof 2532 root cwd DIR 253,17 19 128 /mnt/data
lsof 2533 root cwd DIR 253,17 19 128 /mnt/data
Locating Files by Name
The locate command finds files based on the name or path to the file. It is fast because it looks up this information from the mlocate database. However, this database is not updated in real time, and it must be frequently updated for results to be accurate. This also means that locate will not find files that have been created since the last update of the database.
The locate database is automatically updated every day. However, at any time the root user can issue the updatedb command to force an immediate update.
# updatedb
The locate command restricts results for unprivileged users. In order to see the resulting file name, the user must have search permission on the directory in which the file resides.
Search for files with passwd in the name or path in directory trees readable by user on host
$ locate passwd
The -i option performs a case-insensitive search. With this option, all possible combinations of upper and lowercase letters match the search.
$ locate -i messages
The -n option limits the number of returned search results by the locate command. The following example limits the search results returned by locate to the first five matches:
$ locate -n 5 snow.png
Searching for Files in Real Time
The find command locates files by performing a real-time search in the file-system hierarchy. It is slower than locate, but more accurate. It can also search for files based on criteria other than the file name, such as the permissions of the file, type of file, its size, or its modification time.
The find command looks at files in the file system using the user account that executed the search. The user invoking the find command must have read and execute permission on a directory to examine its contents.
The first argument to the find command is the directory to search. If the directory argument is omitted, find starts the search in the current directory and looks for matches in any subdirectory.
To search for files by file name, use the -name FILENAME option. With this option, find returns the path to files matching FILENAME exactly. For example, to search for files named sshd_config starting from the / directory, run the following command:
# find / -name sshd_config
/etc/ssh/sshd_config
THANKYOU
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by yudistira-19
yudistira-19 | Sciencx (2022-09-25T13:08:06+00:00) LINUX FILE SYSTEM. Retrieved from https://www.scien.cx/2022/09/25/linux-file-system/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.