How To: Show File Sizes When Listing Files In A Directory

Today we’re going to have an easy article that shows you how to show file sizes when listing files in a directory. It’s a simple set of commands and easy enough for a newbie to learn. Though the title is unwieldy, read on to learn how to show file sizes when listing files in a directory…

We’ll be using the ‘ls’ command for this exercise. Like normal, I’ll go ahead and suggest you read this page about why you shouldn’t parse the output from the ‘ls’ command. There are better ways and that link will explain it, and what you should consider, far better than I can.

Anyhow, the ‘ls’ command defines itself as:

ls – list directory contents

Of course, regular readers will recognize the ls command as we’ve used it numerous times before. Even though you shouldn’t parse the output from the command doesn’t mean it’s not still useful for a variety of other tasks.

Today, we’ll be exploring one of those tasks. We’re going to show you how to show file sizes when listing files in a directory – specifically with the ls command. Don’t worry, you won’t need to install anything. If you’re using any desktop Linux distro, the ls command is certainly available to you by default.

For the record, you should probably view the ls man page (run man ls in the terminal) to learn more about the command. It’s still a useful command – and I do sometimes parse the output from the command, but only when nobody is looking and when the output isn’t all that vital. I use grep with the ls command almost every day! Shh!!!

Show File Sizes When Listing Files In A Directory:

(That’s an unwieldy title!)

Anyhow, it’s the ls command. That’s a terminal-based command. So, of course, you’re going to need an open terminal (like so many of these articles). Press CTRL + ALT + T and your default terminal should open. Tada!

With your terminal now open, we can just use your home folder. To run the basic ls command, it’s just that:

Now, to show file sizes when listing files in a directory, you’d start with the -s flag:

You may find the output from that command is relatively useless without doing a bit of math to go along with it. Fortunately, you can tell the command to show the file size in a ‘human-readable format’. To do that, you’d run this command with the -h flag:

Now, if you wanted to show all the files, including the hidden files in that directory, you’d just add the -a flag. The command would look like this:

And if I was a Linux newbie, that’s the command I’d commit to memory. It doesn’t make a mess. The output is still plenty clear. It’s easy to understand. It’s easy to remember and turn into a habit. This way, when you ran the ls command, you just default to using -ash flags.

If you don’t want columns (and some do not), and you want more information such as file permissions or ownership values, you can just add an -lflag to the above. That’d look like:

So, it’s up to you…

You can remember ‘ash’ or you can remember ‘lash’. You can also not remember either and ignore the flags completely, but I find developing a habit is a good way to remember things. It’s your device, you do what you want!

Closure:

There you have it! You have another article. This one was simple enough and I hope you found it useful. If you’re new and running the ls command is new to you, it’s worth learning some additional flags and gathering more information at a glance. That’s why there’s this relatively simple article that shows you how to show file sizes when listing files in a directory.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Find Files Over A Certain Size

Today’s article is going to be a quick article, one where we learn how to find files over a certain size. We’ll be using the ‘find’ command, which we’ve used previously, even though it can be fairly complicated to use. If you want to play around with the ‘find’ command, read on!

Also, and this wasn’t the first article I wrote tonight. I wrote another article. It was a good article. No, it was a great article! Then, as I’m wrapping that article up and hit the preview button, I scrolled down and saw the automatic article recommendation thing at the bottom…

Yup… It was such a good article, I wrote it twice! Well, I couldn’t let that pass – as I’d just done so recently, so I’m writing a new one and this one should be entirely new!

Making the find command approachable to new users means doing it in small bits. Fortunately, the command tells you what it does by its very name. It does exactly what you’d expect – it helps you find files. In fact, it defines itself as:

find – search for files in a directory hierarchy

So, it does what you’d expect it to do – though it can seem fairly complicated to a new user. Let’s do our best to make it approachable, shall we?

Lets Find Files Over A Certain Size:

If you’re a regular reader, you’ll know what’s coming next…

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

So, if you just want to run this ‘find’ command in the directory (and recursive into sub-directories) you’re in, it’s nice and easy. Try this:

As you can guess, that finds files bigger than 100 MB in your current directory (and recursively). If you want to find files of a different size, you just change 100M to whatever you need – like 1000M (you can use G for gigabytes, for example).

If you want, you can specify a directory. Let’s say you want to do the entire system from the root directory (not to be confused with the root user). You just specify that – but you’ll want to use ‘sudo’ because you don’t have permission to read all those files.

Like this, you can specify the starting directory. If you want to find all files larger than 2 GB in your home directory (and sub-directories) then you just run this command:

There’s so much that you can do with the ‘find’ command. It’s really quite useful and I find myself using it with some regularity. Don’t forget to run the man find command to learn more about it. You can do a lot more than just find files over a certain size.

Closure:

So, I’ve tried to make the find command approachable by even novice users. It can be a bit complex looking, but it really is useful. If you think I’ve made it approachable, go ahead and comment. Of course, comment if you think the opposite is true. It’s all good, we’ve just tried to learn how to find files over a certain size.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Sort Files By Size (In The Terminal)

In today’s article, we’re going to cover something nice and simple; how to sort files by size in the terminal. This is something everyone should know, because sorting files is often a prerequisite to understanding and managing said files.

Besides, not all the articles have to be something complicated. The tagline for Linux-Tips is “Getting you up to speed!” It’s supposed to be aimed squarely at new Linux users. The problem is, many of those articles are boring to write and the 2nd largest group of readers aren’t really beginners. 

So, yeah…

Today, we’ll have a nice, basic article that tells you how to sort files by size – in the terminal. In fact, some of the more regular users may not have these commands memorized. Now’s a good time to learn ’em.

We’ll be using the ‘ls’ command for this. It is said that you shouldn’t parse the output of ‘ls’ for anything important. It’s bad practice for reasons I think I’ve touched on before. However, you can safely use ‘ls’ for this process as it’s just sorting the files by size and doing so by itself.

For those that don’t know, ‘ls’ has a ton of options. It’s a tool used to show the contents of a directory. You can use man ls to get more information about the command. We’ve previously covered:

Let’s Use ‘ls’ To Sort Files By Time

Well, today we’ll use ‘ls’ to …

Sort Files By Size:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You might just as well stay right there in your default location – which should be your home directory. Feel free to switch to a new directory, but you really won’t need to. It’s an easy command. 

First, we’ll show the output sorted to show the largest files first:

Of course, you can reverse that sort order and show the smallest files first. To do that, you just add -r (reverse) to your flags, like so:

That command should show you files listed with the smallest ones first and that’s really all there is to this article. Well, there’s the closure section – but nobody reads those.

Closure:

And, well, this particular closure section won’t have anything truly interesting or different in it. After all, this is just a simple article that shows you how to sort files by size. ‘Snot that much more to it. ‘Snot that much more that I can add.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.