Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 26, 2022 02:35 am GMT

Accessing Linux File Systems on RHEL 8 (RedHat Enterprise Linux 8)

Storage Management Concepts

Files on a Linux server are accessed through the file-system hierarchy, a single inverted tree of directories. This file system hierarchy is assembled from file systems provided by the storage devices available to your system. Each file system is a storage device that has been formatted to store files.

In a sense, the Linux file-system hierarchy presents a collection of file systems on separate storage devices as if it were one set of files on one giant storage device that you can navigate. Much of the time, you do not need to know which storage device a particular file is on, you just need to know the directory that file is in.

Disk Partitions
Normally, you do not make the entire storage device into one file system. Storage devices are typically divided up into smaller chunks called partitions.
Partitions are block devices in their own right. On SATA-attached storage, the first partition on the first disk is /dev/sda1. The third partition on the second disk is /dev/sdb3, and so on. Paravirtualized storage devices have a similar naming system.Partitions allow you to compartmentalize a disk: the various partitions can be formatted with different file systems or used for different purposes.

Tools for Managing Partitions on Linux

There are several command line interface (CLI) based tools that are commonly used to view drive and partition information and to manage partitions.

To get an overview of local and remote file system devices and the amount of free space available, run the df(disk free) command.

$ df

Example:Image description For more detailed information about space used by a certain directory tree, use the du(disk usage) command.

# du /directory-name/directory-name

Example :Image description The du command has -h and -H options to convert the output to human-readable format.
Example :Image description

Mounting and Unmounting File Systems

Mounting File Systems Manually
The mount command allows the root user to manually mount a file system.The first argument of the mount command specifies the file system to mount. The second argument specifies the directory to use as the mount point in the file-system hierarchy.

Use the lsblk command to list the details of a specified block device or all the available devices.Image description

Mounting by Block Device Name
The following example mounts the file system in the /dev/sdb1 partition on the directory /mnt/data.

# mount /dev/sdb1 /mnt/data

To mount a file system, the destination directory must already exist.

Mounting by File-system UUID
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.
Image description
Mount the file system by the UUID of the file system.

# mount UUID="959f776a-84bd-4cfb-a9c9-e13623930202" /mnt/data

Unmounting File Systems
To unmount a file system, the umount command expects the mount point as an argument.

# umount /mnt/data

For the umount command to succeed, all processes needs to stop accessing data under the mount point.
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.

# lsof /mnt/data

Once the processes are identified, an action can be taken, such as waiting for the process to complete or sending a SIGTERM or SIGKILL signal to the process. In this case, it is sufficient to change the current working directory to a directory outside the mount point.

Locating Files on the System

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

Example of searching for a file with the name passwd.
Image description
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

Output :
Image description

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.
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:
Image description

In the following example, search for files starting in the / directory that end in .txt:
Image description
To search for files in the /etc/ directory that contain the word, pass, anywhere in their names on host, run the following command:
Image description
To perform a case-insensitive search for a given file name, use the -iname option, followed by the file name to search.

#find / -iname '*messages*'

Searching Files Based on Ownership or Permission
Search for files owned by user in the /home/user directory on host.

$ find -user user

Search for files owned by the group user in the /home/user directory on host.

$ find -group user

Search for files owned by user ID 1000 in the /home/user directory on host.

$ find -uid 1000

Search for files owned by group ID 1000 in the /home/user directory on host.

$ find -gid 1000

The -user, and -group options can be used together to search files where file owner and group owner are different.
Example :

# find / -user root -group mail

The -perm option is used to look for files with a particular set of permissions. Permissions can be described as octal values, with some combination of 4, 2, and 1 for read, write, and execute. Permissions can be preceded by a / or - sign.

To use a more complex example, the following command matches any file for which the user has read, write, and execute permissions, members of the group have read and write permissions, and others have read-only access:

$ find /home -perm 764

Searching Files Based on Size
Use the following list as the units with the -size option:

  • k, for kilobyte
  • M, for megabyte
  • G, for gigabyte

The example below shows how to search for files with a size of 10 megabytes, rounded up.

$ find -size 10M

To search the files with a size more than 10 gigabytes.

$ find -size +10G

Searching Files Based on Modification Time
The -mmin option, followed by the time in minutes, searches for all files that had their content changed at n minutes ago in the past.It also supports fractional values when used with ranges (+n and -n).

To find all files that had their file content changed 120 minutes ago on host, run:

# find / -mmin 120

In this example, files that were modified more than 200 minutes ago are listed.

# find / -mmin +200

Searching Files Based on File Type

The -type option in the find command limits the search scope to a given file type. Use the following list to pass the required flags to limit the scope of search:

  • f, for regular file
  • d, for directory
  • l, for soft link
  • b, for block deviceExample ;Search for all directories in the /etc directory on host.
# find /etc -type d

Search for all soft links on host.

# find / -type l

Original Link: https://dev.to/mohammadalwan/accessing-linux-file-systems-on-rhel-8-redhat-enterprise-linux-8-25aa

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To