Linux show files with size

HowTo: Linux / Unix See File Size Command

a] ls command – list directory contents.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements ls/du/stat
Est. reading time Less than a one minute

b] du command – estimate file space usage.

c] stat command – display file or file system status.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Examples

To determine the size of a file called /bin/grep, enter:

In the above output example, the 175488 is the size of the file. For a more user friendly output, pass the -h option to the ls command:

Here is what we see:

In the above output example, the 172K is the size of the file. The du command provides the same output in a more user friendly way and it hides all other details too:
du -h /bin/grep
Now du command reporting file size on screen:

Finally, stat command also provide file size:
stat /bin/grep
Linux stat command outputs:

The following commands are executed on Apple OS X Unix operating systems to file out the file size of the /usr/bin/vim binary file:
$ ls -l /usr/bin/vim
$ ls -lh /usr/bin/vim
$ stat -x /usr/bin/vim

Fig.01: Finding out file size using various command line options on OS X Unix OS

Summing up

You learned different Linux and Unix commands to display file size using the command-line option. You need to type these commands using the terminal application. One can execute them over remote ssh session too, using the ssh command:

Finding file size using ssh command over the remote session (cloud server)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

How to List All Files Ordered by Size in Linux

In one of our several articles about listing files using the popular ls command, we covered how to list and sort files by last modification time (date and time) in Linux. In this short handy article, we will present a number of useful ls command options to list all of the files in a certain directory and sort them by file size in Linux.

To list all files in a directory, open a terminal window and run the following command. Note that when ls invoked without any arguments, it will list the files in the current working directory.

In the following command the -l flag means long listing and -a tells ls to list all files including (.) or hidden files. To avoid showing the . and .. files, use the -A option instead of -a .

List All Files in Linux

To list all files and sort them by size, use the -S option. By default, it displays output in descending order (biggest to smallest in size).

List All Files Sort By Sizes

You can output the file sizes in human-readable format by adding the -h option as shown.

List Files Sort By Sizes in Linux

And to sort in reverse order, add the -r flag as follows.

List All Files Sort By Sizes in Reverse Order

Besides, you can list subdirectories recursively using the -R option.

List Sub-directories Recursively

You will also find the following related articles useful:

If you any other way to list the files ordered by sizes in Linux, do share with us or do you have questions or thoughts to share about this guide? If yes, reach us via the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Display File Size in Human Readable Format (KB, MB, GB) in Linux Terminal

You probably already know that you can use ls command with long listing option -l to show file size in Linux.

But unfortunately, the long listing shows the file size in blocks and that’s not of much use to us humans.

Good thing is that you can combine the option -l with -h to show the file size in human readable format.

As you can see, it is better to display file size in human-readable format.

As you can see, file sizes are now displayed in K (for KB), M for (MB). If the file size is in Bytes, it is not displayed with any suffix. In the above example, char.sh is 140 Bytes in size.

Did you notice the size of new_dir directory? It is 4 KB. If you use ls -lh command on directories, it always shows the size of directory as 4.0 K.

By default, the block size in most Linux system is 4096 Bytes or 4 KB. A directory in Linux is simply a file with the information about the memory location of all the files in it.

You can force ls command to display file size in MB with the —block-size flag.

The problem with this approach is that all the files with size less than 1 MB will also be displayed with file size 1 MB.

The ls command also has -s option to display size. You should combine with -h to show the file size in human readable form.

Here’s the output:

You can also use the stat command in Linux to check the file size.

I hope you find this quick tip helpful in seeing the file size in Linux.

Источник

How to Find Out Top Directories and Files (Disk Space) in Linux

As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find unnecessary junk and free up them from your hard disk.

This brief tutorial describes how to find the largest files and folders in the Linux file system using du (disk usage) and find command. If you want to learn more about these two commands, then head over to the following articles.

How to Find Biggest Files and Directories in Linux

Run the following command to find out top biggest directories under /home partition.

Find Largest Directories in Linux

The above command displays the biggest 5 directories of my /home partition.

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, run:

Find Biggest Directories Only

Let us break down the command and see what says each parameter.

  1. du command: Estimate file space usage.
  2. a : Displays all files and folders.
  3. sort command : Sort lines of text files.
  4. -n : Compare according to string numerical value.
  5. -r : Reverse the result of comparisons.
  6. head : Output the first part of files.
  7. -n : Print the first ‘n’ lines. (In our case, We displayed the first 5 lines).

Some of you would like to display the above result in human-readable format. i.e you might want to display the largest files in KB, MB, or GB.

Find Top Directories Sizes in Linux

The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space.

To display the largest folders/files including the sub-directories, run:

Find Largest Folder and Subdirectories

Find out the meaning of each option using in above command:

  1. du command: Estimate file space usage.
  2. -h : Print sizes in human-readable format (e.g., 10MB).
  3. -S : Do not include the size of subdirectories.
  4. -s : Display only a total for each argument.
  5. sort command : sort lines of text files.
  6. -r : Reverse the result of comparisons.
  7. -h : Compare human readable numbers (e.g., 2K, 1G).
  8. head : Output the first part of files.

Find Out Top File Sizes Only

If you want to display the biggest file sizes only, then run the following command:

Find Top File Sizes in Linux

To find the largest files in a particular location, just include the path beside the find command:

Find Top File Size in Specific Location

The above command will display the largest file from /home/tecmint/Downloads directory.

That’s all for now. Finding the biggest files and folders is no big deal. Even a novice administrator can easily find them. If you find this tutorial useful, please share it on your social networks and support TecMint.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD

How to find out top 10 files and directories on Linux or Unix

There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files:

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux and Unix-like OS
Est. reading time 3 minutes

Steps to find Largest Directories in Linux

  1. du command : Estimate file space usage.
  2. sort command : Sort lines of text files or given input data.
  3. head command : Output the first part of files i.e. to display first 10 largest file.
  4. find command : Search file.

How to find out top Directories and files in Linux

Type the following command at the shell prompt to find out top 10 largest file/directories:
# du -a /var | sort -n -r | head -n 10
Sample outputs:

If you want more human readable output try (works with GNU/Linux du version/user only):
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10
$ du -hsx — * | sort -rh | head -10
Where,

  • du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
  • du command -s option : show only a total for each argument (summary).
  • du command -x option : skip directories on different file systems.
  • sort command -r option : reverse the result of comparisons.
  • sort command -h option : compare human readable numbers. This is GNU sort specific option only.
  • head command -10 OR -n 10 option : show the first 10 lines.

The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):

Find the largest file in a directory and its subdirectories using the find command

Type the following GNU/find command:

You can skip directories and only display files, type:

Hunt down disk space hogs with ducks

Let us find out top directories and files using disk space in Linux or Unix with help of the following bash shell alias:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Run it as follows to get top 10 files/dirs eating your disk space:
$ ducks
Sample outputs:

Fig.01 Finding the largest files/directories on a Linux or Unix-like system

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Great, but what if I only want the largest files and not the directories?

To find out largest file only use command ls as follows in current directory:
ls -lSh . | head -5
Output:
-rw-r–r– 1 vivek vivek 267M 2004-08-04 15:37 WindowsXP-KB835935-SP2-ENU.exe
-rw-r–r– 1 vivek vivek 96M 2005-12-30 14:03 VMware-workstation-5.5.1-19175.tar.gz
ls -lSh /bin | head -5
You can also use find command but not du:
find /var -type f -ls | sort -k 7 -r -n | head -10

Hope this helps

And yes to find the smallest files use command:
ls -lSr /var

Or use find command with -size flag.
find / -type f -size +20000k -exec ls -lh <> ; | awk ‘< print $8 “: ” $5 >’

Read man page of find for more info.

“find / -type f -size +20000k -exec ls -lh <> ; | awk ‘< print $8 “: ” $5 >’”

needs to have the exec altered

find / -type f -size +20000k -exec ls -lh <> \; | awk ‘< print $8 “: ” $5 >’

Also, I find this output easier to read

find . -type f -size +20000k -exec ls -lh <> \; | awk ‘

How do I can list all the files in several directories and at the end write the totat of all the files and directories.I’m using the du command as fallow:
du -sh /public/base/sites/F*/*20070115*

this command give me the size of all the files but not the global total.

can somebody help me. please write me. john_fernandez@verizon.com.do

“If you want more human readable output try:

# du -ha /var | sort -n -r | head -n 10”

Im pretty sure that this will put 999kb above 1gb so I don’t think that this works.

This does not work.

# du -ha /var | sort -n -r | head -n 10″

as Joe says this ignores files over 1gb

You could try this, gives a human readable output in MB

find . -type f | xargs ls -s | sort -rn | awk ‘‘ | head

Human readable version:

for X in $(du -s * | sort -nr | cut -f 2); do du -hs $X ; done

If you set du to human readable I think it will not sort the way you really want.

For the above problems. I would like to find a way to list only the last level directories’ sizes.

(I want to filter somehow this:
/home
/home/user
/home/user/mail

I just want to see the lasts of the tree!)

this is what i use.

for i in G M K; do du -ah | grep 7$i | sort -nr -k 1; done | head -n 11

Worked like charm

find . -type f -print0| xargs -0 ls -s | sort -rn | awk ‘’ | head

! -print0 for filenames with spaces …
(and xargs -0 combined)

No wonder windows rule

Yeah you just go ahead and wait the 3 hours this search would take on Windows.

How about the 3 hours it takes to read through a bunch of unexplained programming nonsense. I swear half of the time all Linux guys do is insult other users….Example, the first listing is great as it begins to explain what the flags do, but I have no idea were to put some of them, pipes are not explained…ect

This is why Winblows users should not try and use Linux, they are very unintelligent and lack the ability to look up simple things.

Fast forwarda few years, Linux won, bro 🙂

“Late last week, hell had apparently frozen over with the news that Microsoft had developed a Linux distribution of its own. The work was done as part of the company’s Azure cloud platform, which uses Linux-based network switches as part of its software-defined networking infrastructure.” — SOURCE HERE.

Winfan, I read this page wondering how to do these things in Windows — can you post instructions? Thanks!

This may vary depending on the version of Windows you’re using, but the basic procedure is: open the find/search window, go to the advanced options, and there will be an option there to enter in a size parameter. Simple.

In XP, press F3 or go Start->Search. Choose “All files and folders”, then “More advanced options”, then “What size is it?”, then specify a size.

I believe beez was being sarcastic towards Winfan as was his right after Winfans brainless comment. Most Linux distro GUI’s come with search function just like Windows GUI.

Now just try to do the search on command line on Windows (server)…

@winfan… how do you do this in windows? you don’t 😛

c:\>dir /S /O-S | more

The simple dir /S command from c:\ will give you all files and directories from c:\ all the way through the drive and will sort from largest to smallest running through each directory. You can filter using /A if you’d like to restrict by hidden, system, archive files, read only files etc. and passing the output to another windows command if you need to further restrict or search in the files for something like “show me all the files on my hard drive over 6MB that contain the word ‘log’ from largest to smallest.”

/O will Specify the sort order for the files with the S after it sorting by file size (smallest first) putting the – in front of the S reverses the order.

| more – you’re a unix dude, you should know what this means…

But if someone is doing some cleanup through their harddrive, this is the simple command I’d start with.

Just a note about the cockyness or us Unix admins (as I happen to be one now)
Not everyone that uses windows started using it with a mouse kid. Also not everyone who prefers windows is not cross-platform… We were running 64 bit clustered NT boxes on RISC processors at Digital Equipment Corporation with failover and failback in 1996 brother. Don’t believe me? Find a really old copy of Windows NT ver 3.51 open it and you’ll see two folders NT and Alpha.

The Department of Veterans Affairs had no problems with ever needing to reboot a “lousy unreliable windows box” because the Intel platform itself was the problem, not windows. We ran Alpha on 64 bit RISC processors and it was just as reliable as any Unix box or Mainframe we had. I had a Jensen Alpha running an exchange server for 5 years, and we only rebooted it every 6 months for giggles…

Windows machines are made to be used by the masses which means more dumbasses can kinda run one. A good Admin is a good Admin, no matter what platform. Be nice and be helpful or don’t post.

Notafan wrote:
@winfan… how do you do this in windows? you don’t 😛

Well, actually, there *is* cygwin (unix commands for Windows systems)
http://www.cygwin.com/

I find the following works rather well…

It lists all files or directories bigger than 50MB (just change size>50 to alter that) in the current directory (change the “.” to a directory path to specify another one) in a friendly, human-readable way and happily plays with spaces (I used it on an NTFS mount in fact).

I get a syntax error when coptying and pasting this command

Источник

Читайте также:  Linux как почистить корзину
Оцените статью