CentOS command for searching large files

Source: Internet
Author: User

CentOS command for searching large files
You can use the find and parameter size to find the file size in CentOS. You can use du to find a large directory or file size, next I will introduce the simple file search and directory size in CentOS.

# The size of the specified directory or file is displayed in a readable format. The-s option specifies that the size of each subdirectory or file is not displayed in detail for the directory.
Du-sh [dirname | filename]

For example:

Current Directory size:

Copy the Code du-sh as follows.


Size of files or directories in the current directory:

The Code is as follows: copy the Code du-sh *


Display the first 10 Most occupied files or directories:

The Code is as follows:

Du-s * | sort-nr | head

*-H the readable format shows the size of the specified directory or file
* The-s option specifies that the size of each subdirectory or file is not displayed in detail for the directory.

How do I find all the large files in the directory?

The find command in linux is used to find files. man find can be used to find files that are omnipotent. Therefore, simply find the file according to the file size. Search for the size from man find. The following information is displayed:

-Size n [cwbkMG]
File uses n units of space. The following suffixes can be used:

B for 512-byte blocks (this is the default if no suffix is used)

C for bytes

W for two-bytewords

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. Therefore, 2 indicates 1 K, and 1 m indicates 2048. If you do not want to convert it yourself, you can use other units, such as c, K, and M

A.

1) syntax for RedHat/CentOS/Fedora Linux

The Code is as follows:

Find {/path/to/directory/}-type f-size + {size-in-kb} k-exec ls-lh {}; | awk '{print $9 ":" $5 }'

Instance:

Search for files larger than 50 MB in the current directory

The Code is as follows:

$ Find.-type f-size + 50000 k-exec ls-lh {}; | awk '{print $9 ":" $5 }'

Search for files whose directory/var/log is greater than MB

The Code is as follows:

# Find/var/log-type f-size + 100000 k-exec ls-lh {}; | awk '{print $9 ":" $5 }'

2) syntax for Debian/UbuntuLinux

Find {/path/to/directory}-type f-size + {file-size-in-kb} k-exec ls-lh {}; | awk '{print $8 ":" $5 }'

Instance:

Search for files larger than 10 MB in the current directory

The Code is as follows:

$ Find.-type f-size + 10000 k-exec ls-lh {}; | awk '{print $8 ":" $5 }'

Sample output:
./. Kde/share/apps/akregator/Archive/http ___ blogs.msdn.com _ MainFeed. aspx? Type = AllBlogs. mk4: 91 M
./Out/out.tar.gz: 828 M
./. Cache/tracker/file-meta.db: 101 M
./Ubuntu-8.04-desktop-i386.iso: 700 M
./Vivek/out/mp3/Eric: 230 M

List Files with a file size smaller than B in the home directory:

The Code is as follows:

$ Find $ HOME-size-500b
OR
$ Find ~ -Size-500b

List Files with a size of 20 512-byte blocks in the root directory:

Copy the Code as follows # find/-size 20

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.