Note: Some of the materials used previously, whether gathered from online searches or summarized from personal learning, are generally saved locally. Now, I am organizing this content on the public account for easier retrieval and to provide it to friends who may need it.This document records some commands that are frequently used in daily work:
1. View disk space usage statistics
df
Commonly used: df -h
2. Check the size of the current folder’s space usage
du
Commonly used:
du -sh
du –max-depth=1 -h
–max-depth shows the directory depth, -sh only displays the total size, showing some directories.
3. Zip compress a directory to a specified address
zip -r -q /data/bak/temp_yyyyMMdd.zip /home/ekp/ekp/
Explanation:
-r means to recursively process files in subdirectories
-q means quiet, no log output
The first address is the destination file, directly defined to the zip file
The second address is the source directory, so the root directory in the compressed file starts from this directory.
4. View the hard disk resource status in the system
lsblk # You can view the hard disk mounting status in the system, mainly used in scenarios like mounting hard disks, directory mapping, etc.
5. Format the hard disk to be mounted
For example: sudo mkfs -t ext4 /dev/vdb # Only operate on new hard disks, otherwise it may cause data loss
6. Execute mounting the hard disk
For example: sudo mount /dev/vdb /data
The first is the hard disk path, which can be obtained by the lsblk command.
The second is the local directory to mount to, which needs to be created first if it does not exist, command like: sudo mkdir /data
7. Split compression
For example: zip -s 1024m src.zip –out src_split.zip
# After compression, src.zip is 4.6G, split it so that each sub-compressed package does not exceed 1G, generating 5 compressed packages src_split.z01 (1G), src_split.z02 (1G), src_split.z03 (1G), src_split.z04 (1G), and src_split.zip (0.6G)
8. Merge and decompress (Method 1)
# Merge the above 5 compressed packages into a single compressed file single.zip
zip src_split.zip -s=0 –out single.zip
# Decompress single.zip
unzip -d ./single.zip
9. Merge and decompress (Method 2)
# For example, if the linux.zip folder is split into: linux.zip.001, linux.zip.002, linux.zip.003, … then:
First cat linux.zip* > linux.zip # Merge into one zip package
Then unzip linux.zip # Decompress the zip package
10. Restart the operating system 1
Command: reboot # Restart immediately
11. Restart the operating system 2
Command: shutdown -r now # Restart now, you can also: shutdown -r -t 10 # Specify the number of seconds to execute the restart
Note: The above content is my summary and may not be applicable to all machine environments. The actual operating system used is: redhat7.2