[LINUX] Disk-related commands often used in Ubuntu (memories)

Introduction

I'm using ubuntu, and for backup, I often use disk-related commands such as connecting an external SSD to copy data and setting the database storage location to the secondary disk.

So this time, I have summarized the commands that I often use as a memorandum for myself. I hope it helps you.

Frequently used commands related to disk management

I mainly use the following commands to use the disk on Linux.

--fdisk command --blkid command --dmesg command --tree command --df command --du command --mkfs command --mount / umount command --lshw command --lsblk command

Frequently used commands

#Partition list display
sudo fdisk -l

#Hard disk information acquisition
sudo blkid

#Make sure the device is recognized
dmesg | grep sd

#Only directories are displayed up to the second level
tree -d -L 2

#Check free space
sudo df -h

#Check which disk the root directory is on
df / -h

#See which device is mounted where
df -Th

#Show which directory has the largest capacity
sudo du -sh /*

#Show the top 5 directories with the most capacity
sudo du -sm ./* | sort -rn | head -5

#Ext4 format HDD
sudo mkfs.ext4 "Disk path"

#Disc mount
sudo mount "Disk path" "Directory path to mount"

#Disc unmount
umount /mnt

#Display hardware information
sudo lshw -short -C disk 

#List block devices(Show disc name and platter(HDD for 1 and SSD for 0)) 
lsblk -o name,rota

#Check if the disk is HDD or SSD(HDD if the return value is 1, SSD if the return value is 0) 
cat /sys/block/"Disk name"/queue/rotational

Supplement 1 --- Handling of Linux discs

Unlike Windows, Linux does not have a drive letter, so there are no expressions such as C drive or D drive. Therefore, when you mount the partition on the disk, it will be treated like a folder and you will be able to access the contents of the HDD.

When the disk is recognized, each HDD is expressed as / dev / sda, / dev / sdb, and so on. The part of sd is fixed, and the alphabet after it seems to continue in order from a. (Sr for CD / DVD drive)

Supplement 2 --- Linux directory structure

The Linux directory structure is created according to the FHS (Filesystem Hierarchy Standard) standard. The directories directly under the root directory specified by the current FHS (FHS 3.0) that are required are "/ bin", "/ boot", "/ dev", "/ etc", "/ lib", and "/ media". There are 14 "/ mnt", "/ opt", "/ run", "/ sbin", "/ srv", "/ tmp", "/ usr", and "/ var" ("/ home" and "/ root" are specified as options. ).

directory role
/ Root directory. This is the starting point of the hierarchy.
/bin Contains executable files needed to boot or repair the system in single-user mode. For example, executable files such as cat, cp, ls, more, tar.
/boot Includes Linux kernel, boot manager, etc. This directory contains only the files needed during the boot process.
/dev A device attached to a computer that references a physical device(Mouse, keyboard, disc, etc.)Where to put special files and device files.
/etc The directory that contains most system configuration files. Also in subdirectories/etc/rc.d contains the initialization script.
/lib The location where the shared libraries needed to boot the system and the shared libraries needed to execute commands on the root file system are located.
/media CD-Mount point for external media such as ROMs and floppy disks.
/mnt The mount point for the temporarily mounted file system.
/opt Places static files for add-on packages.
/run Contains data related to the running process.
/sbin /Like bin, this directory contains the commands needed to boot the system. However, commands that general users do not normally execute are placed here.
/srv Temporary files that can be deleted unconditionally are placed by regular jobs or at system startup.
/tmp Temporary files that can be deleted unconditionally are placed by regular jobs or at system startup.
/usr Contains files that the user installs independently. A structure similar to that directly under the route has been created.
/var Files that change in size, such as spool files and log files, are placed.

Of course, this is not the only thing defined in the FHS, but it also mentions the underlying directories (such as "/ usr / share").

When I actually hit the following command on Ubuntu, the following directory structure was displayed.

tree -d -L 2

image.png

Referenced, helpful site

-View Ubuntu disk space -Linux Disk Management -Linux bean knowledge 173-FHS (Filesystem Hierarchy Standard)

Recommended Posts

Disk-related commands often used in Ubuntu (memories)
Settings often used in Jupyter
Frequently used commands in virtualenv
Commands often used in the development environment during Python implementation
I tried to summarize the commands often used in business
8 Frequently Used Commands in Python Django
Grammar summary often used in pandas
Commands often used on GAE / P
Summary of methods often used in pandas
Summary of frequently used commands in matplotlib
[Linux] List of Linux commands used in practice
Processing memos often used in pandas (beginners)
Commands often used in the terminal (EC2 server) (for your own viewing)
Techniques often used in python short coding (Notepad)
Code often used in Python / Django apps [prefectures]
A collection of code often used in personal Python
A collection of commands frequently used in server management
A collection of Excel operations often used in Python
pyenv Frequently used commands
Frequently used tmux commands
Frequently used Linux commands
Frequently used Linux commands
Frequently used linux commands
R in Anaconda (in Ubuntu 14.04)
Beep in Python (Ubuntu)
Frequently used pip commands
I tried to summarize the code often used in Pandas