It's odd that du has the opposite behavior of ls in this regard. By default du will recursively give you the disk usage of each sub-directory.
In contrast, ls will only give list files in the specified directory. I called it duls because it shows the output from both du and ls in that order :.
The paste utility creates columns from its input according to the specification that you give it. Given two input files, it puts them side by side, with a tab as separator. It will therefore understand globbing characters and path names with spaces etc. The double minuses -- signals the end of command line options to du and ls. Without these, saying duls -l would confuse du and any option for du that ls doesn't have would confuse ls and the options that exist in both utilities might not mean the same thing, and it would be a pretty mess.
The cut after du simply cuts out the first column of the du -hs output the sizes. I decided to put the du output on the left, otherwise I would have had to manage a wobbly right column due to varying lengths of file names. This has been tested in both bash and in ksh This awesome CLI utility allows you to easily find the large files and directories recursive total size interactively.
For example, from inside the root of a well known open source project we do:. Another cool feature of ncdu is that you can first dump the sizes in a JSON format, and later reuse them.
This way, you can first export only once, which can take hours, and then explore the files, quit, explore again, etc. To display the same size information but without printing their sub directories recursively which can be a huge list , just use the --max-depth option:. Then you sort them numerically and reverse the sort so it puts the bigger ones first.
The only downside to this command is that the computer does not know that Gigabyte is bigger than Megabyte so it will only sort by numbers and you will often find listings like this:. If you want more control over the size that you want to list the directories over, you can use the threshold -t switch as in:. Units that are described in wiki follows:. It may happen that the size of the files is different, e. I use the following script, including ls to sum up the directory size. The result in in bytes taking all sub directories into account.
As a result, the total size shown by. So, just wanted to share this, in case somebody faced the same problem. Then you will be able to get all sizes folders over all your server. Easy to help to you to find the biggest sizes. I ran into an issue similar to what Martin Wilde described, in my case comparing the same directory on two different servers after mirroring with rsync.
Instead of using a script I added the -b flag to the du which counts the size in bytes and as far as I can determine eliminated the differences on the two servers. You still can use -s -h to get a comprehensible output. It is important to note here that du gives you disk usage.
Different machines can use different block sizes, so on one machine a block could be bytes and another machine could contain block sizes of If you want to know the size of all the files in a directory, for each directory you can do something like:. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Its primary use is to show files and directories within a file system and giving detailed information. It is available in all systems that use the Linux kernel. This tutorial will use the ls command to show you how to get information such as file and directory size in a human-readable format. By default, the ls command shows details about files and directories in the current working directory.
To list files outside your current working directory, you can pass an absolute path to the ls command as:. Ls also allows you to pass multiple directories at once. All you have to do is pass the path separated by space. For example:. The command above shows both the files and directories inside the home directory. The du command in Linux is used for checking the size of directory. Here are various ways you can find the size of directory in Linux with the du command.
Linux Handbook Abhishek Prakash. Quick tutorial to show you how to find the biggest files on your Linux machine using a few commands that you may already be familiar with du, sort, and head. Linux Handbook Christopher Murray. Quick Tip. Send login link. Check your inbox and click the link.
Sorry, something went wrong. Please try again. Top command shows the most CPU consuming processes first. Learn how to sort top on memory usage instead.
0コメント