SoFunction
Updated on 2025-03-09

Common disk disk operation commands for Linux


#Sort the top 15 directories or files of the warrior by directory size
du -xB M --max-depth=2 /var | sort -rn | head -n 15

# List the file sizes of all current subdirectories
du -h --max-depth=1

# List the 10 largest files or directories
du -s * | sort -n | tail

#Sort from large to small by directory size
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'

#List the file tree of the path directory
du -h /path | sort -h

# Monitor the file size changes of the corresponding directory every 60 seconds
watch -n60 du /var/log/messages


#Recursively delete .svn directories in all subdirectories in the current directory
find . -type d -name '.svn' -print0 | xargs -0 rm -rdf

#List the current disk usage
df -P | column -t

#Monitor disk usage
watch -d -n 5 df

#List the current usage of inode
df -i <partition>

#Sorted from high to low by usage per disk
df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)


# Check the usage of physical disks
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"

#Check the size and usage of all disks
df -H

#View all partition usage
fdisk -l /dev/sda

# Show all partitions of the system or given partitions
fdisk -l
# When displayed, the number of sectors is not the number of cylinders
fdisk -u
# Display the number of blocks for the specified partition
fdisk -s partition

#View the read and write capacity of the disk
iostat -m -d /dev/sda1

#Test the disk read and write speed
hdparm -t /dev/sda

#See all links to a file
find -L / -samefile /path/to/file -exec ls -ld {} +

#See the largest 5 files
find . -type f -exec ls -s {} \; | sort -n -r | head -5

#View files 365 days ago and delete them
find ./ -type f -mtime +365 -exec rm -f {} \;

#View files larger than 100M
find . -type f -size +100M