It's easy to find files and directories in Linux
#已易读的格式显示指定目录或文件的大小, the-s option specifies the size of each subdirectory or file not shown in detail for the directory
Du-sh [Dirname|filename]
Such as:
The size of the current directory:
The code is as follows |
Copy Code |
Du-sh.
|
The size of the next file or directory in the current directory:
The code is as follows |
Copy Code |
Du-sh *
|
Displays the top 10 most occupied files or directories:
The code is as follows |
Copy Code |
Du-s * | Sort-nr | Head |
*-H readable format displays the size of the specified directory or file
*-S option specifies the size of each subdirectory or file not shown in detail for the directory
How do I find all the large files in the directory?
The Find command under Linux is used to look up files, and it is known to be omnipotent through man finds. So it's a cinch to find files by file size. Search for size from man find, you can see the following information:
-size N[CWBKMG]
File uses n units of space. The following suffixes can be used:
b for 512-byte blocks (here is the ' default if no suffix is used)
C for bytes
W for two-byte words
K for kilobytes (Units of 1024 bytes)
M for megabytes (units of 1048576 bytes)
G for gigabytes (units of 1073741824 bytes)
Note: The default unit is B, and it represents 512 bytes, so 2 means that 1k,1m is 2048, if you do not want to convert, you can use other units, such as C, K, m, etc.
A.
1 syntax for Redhat/centos/fedora Linux
The code is as follows |
Copy Code |
Find {/path/to/directory/}-type f-size +{size-in-kb}k-exec ls-lh {}; | awk ' {print $ ': ' $} ' |
Instance:
Find files larger than 50MB in the current directory
The code is as follows |
Copy Code |
$ find. -type f-size +50000k-exec ls-lh {}; | awk ' {print $ ': ' $} ' |
Find a file with a directory/var/log greater than 100MB
The code is as follows |
Copy Code |
# Find/var/log-type F-size +100000k-exec ls-lh {}; | awk ' {print $ ': ' $} ' |
2 syntax for Debian/ubuntu Linux
Find {/path/to/directory}-type f-size +{file-size-in-kb}k-exec ls-lh {}; | awk ' {print $ ': ' $} '
Instance:
Find files larger than 10MB in the current directory
The code is as follows |
Copy Code |
$ find. -type f-size +10000k-exec ls-lh {}; | awk ' {print $ ': ' $} ' Sample output: ./.kde/share/apps/akregator/archive/http___blogs.msdn.com_mainfeed.aspx?type=allblogs.mk4:91m ./out/out.tar.gz:828m ./.cache/tracker/file-meta.db:101m ./ubuntu-8.04-desktop-i386.iso:700m ./vivek/out/mp3/eric:230m |
List files with a file size of less than 500b in the home directory:
The code is as follows |
Copy Code |
$ find $HOME-size-500b OR $ find ~-size-500b |
List the files in the root directory with a size of 512-byte blocks:
The code is as follows |
Copy Code |
# Find/-size 20 |