CentOS 파일 시스템 관리

CentOS is one of the most popular Linux distributions used in server environments. One of the key aspects of managing a CentOS server is filesystem management. In this blog post, we will explore various commands and techniques available in CentOS for filesystem management using bash.

1. Checking Disk Usage

It’s important to regularly monitor disk usage to ensure optimal performance and avoid disk space issues. The df command provides detailed information about the disk space usage on filesystems.

$ df -h

The -h flag displays the disk space usage in a human-readable format.

2. Navigating the Filesystem

To navigate through the CentOS filesystem, we can use the cd command. For example, to navigate to the root directory, we simply use:

$ cd /

The cd command can also be used to move into specific directories:

$ cd /var/log

3. Creating and Deleting Files and Directories

To create a new directory, we can use the mkdir command followed by the directory name:

$ mkdir my_directory

To create a new file, we can use the touch command followed by the file name:

$ touch my_file.txt

To delete a directory, we use the rmdir command:

$ rmdir my_directory

To delete a file, we use the rm command:

$ rm my_file.txt

Note: Be cautious when using the rm command as it permanently deletes files and directories.

4. View and Edit Files

To view the contents of a file, we can use the cat, less, or more command.

$ cat my_file.txt

To edit a file, we can use the vi or nano editor.

$ vi my_file.txt

The vi editor is more advanced and can take some time to learn, while nano is a more user-friendly option.

5. Disk Partitioning and Formatting

To manage disk partitions in CentOS, we use the fdisk command. It allows us to create, delete, and modify partitions on our disks.

$ fdisk /dev/sda

To format a partition, we use the appropriate formatting command for the filesystem type, such as mkfs.ext4.

$ mkfs.ext4 /dev/sda1

Caution: Be careful when formatting partitions as it permanently erases all data on the partition.

Conclusion

In this blog post, we covered some essential commands and techniques for CentOS filesystem management in bash. Monitoring disk usage with df, navigating the filesystem with cd, creating and deleting files and directories with mkdir, touch, rmdir, and rm, viewing and editing files with cat, less, more, vi, and nano, and disk partitioning and formatting with fdisk and mkfs were some of the key topics discussed.

Proper filesystem management is crucial for maintaining the performance and reliability of your CentOS server. With these commands and techniques, you’ll be well-equipped to manage your CentOS filesystem efficiently.