Sponsored Content
Full Discussion: Sort by file/directory size
Top Forums UNIX for Beginners Questions & Answers Sort by file/directory size Post 303013435 by John K on Wednesday 21st of February 2018 10:20:49 AM
Old 02-21-2018
Sort by file/directory size

OS : RHEL 6.6

I want to list the files/directories sorted (Ascending or Desceding) by their size.

As you can see in the below example, du command doesn't sort by size.
In Linux world, is there any other command or workaround using du command to list the files/directories sorted by their size.

Code:
[manhba@reporting-node1 Data_Extraction]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.6 (Santiago)

[manhba@reporting-node1 Data_Extraction]$ ls -lrdth *
drwxrwxr-x 2 manhba manhba 4.0K Dec 16 12:03 WO0000000073502_SBL
drwxrwxr-x 2 manhba manhba 4.0K Dec 16 12:54 WO0000000073255_SBL
drwxrwxr-x 2 manhba manhba 4.0K Dec 17 15:50 WO0000000073265_SBL
drwxrwxr-x 2 manhba manhba 4.0K Dec 22 01:02 WO0000000074061_SBL
drwxrwxr-x 2 manhba manhba 4.0K Dec 27 05:06 WO0000000072057_SBL
drwxrwxr-x 2 manhba manhba 4.0K Jan  4 15:37 3_Jan_2018
drwxrwxr-x 2 manhba manhba 4.0K Jan  4 16:00 WO0000000075793
drwxrwxr-x 2 manhba manhba 4.0K Jan  5 06:20 WO0000000075787
drwxrwxr-x 2 manhba manhba 4.0K Jan  5 22:16 WO0000000075994_jan5
drwxrwxr-x 2 manhba manhba 4.0K Jan  9 05:09 WO0000000076411
drwxrwxr-x 2 manhba manhba 4.0K Jan 17 13:30 WO0000000077242
drwxrwxr-x 2 manhba manhba 4.0K Jan 26 05:57 WO0000000078972
drwxrwxr-x 2 manhba manhba 4.0K Feb  2 14:25 WO0000000080132_OSS
drwxrwxr-x 2 manhba manhba 4.0K Feb  3 19:58 WO0000000075775
drwxrwxr-x 2 manhba manhba 4.0K Feb  6 15:08 WO0000000080606
drwxrwxr-x 2 manhba manhba 4.0K Feb  7 11:21 WO0000000076180
drwxrwxr-x 2 manhba manhba 4.0K Feb  7 11:21 WO0000000080071
drwx------ 2 manhba manhba 4.0K Feb  7 11:24 WO0000000080703
drwxrwxr-x 2 manhba manhba 4.0K Feb  8 07:19 WO0000000080072
drwxrwxr-x 2 manhba manhba 4.0K Feb  9 15:17 WO0000000081126
drwxrwxr-x 2 manhba manhba 4.0K Feb 14 22:04 WO0000000081452
drwxrwxr-x 2 manhba manhba 4.0K Feb 16 15:37 WO0000000081648
drwxrwxr-x 3 manhba manhba 4.0K Feb 20 02:07 WO0000000080073
drwxrwxr-x 2 manhba manhba 4.0K Feb 20 14:34 WO0000000082620
[manhba@reporting-node1 Data_Extraction]$
[manhba@reporting-node1 Data_Extraction]$
[manhba@reporting-node1 Data_Extraction]$ du -sh *
1.1M    3_Jan_2018
8.0K    WO0000000072057_SBL
20K     WO0000000073255_SBL
168K    WO0000000073265_SBL
22M     WO0000000073502_SBL
8.0K    WO0000000074061_SBL
6.8M    WO0000000075775
4.1M    WO0000000075787
52K     WO0000000075793
1.8M    WO0000000075994_jan5
8.0K    WO0000000076180
27M     WO0000000076411
596K    WO0000000077242
75M     WO0000000078972
24K     WO0000000080071
170M    WO0000000080072
12G     WO0000000080073 ----------------------> Largest directory
1.1M    WO0000000080132_OSS
35M     WO0000000080606
2.5M    WO0000000080703
8.4M    WO0000000081126
760K    WO0000000081452
20K     WO0000000081648
2.5G    WO0000000082620  -------------------------> Second largest directory
[manhba@reporting-node1 Data_Extraction]$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

2. Shell Programming and Scripting

How to know size of file in a directory

Hi, I have to directory /usr/inbound ------------- 10900.txt 10889.txt 109290202.txt I need to create inbound directory and i need to know size of these files one by one if file size is zero i need to print message like "empty file" Please help me how to solve this thanks krish. (1 Reply)
Discussion started by: kittusri9
1 Replies

3. UNIX for Dummies Questions & Answers

How can I sort the file names in the directory

Hi , I have a list of files in the directory I want to sort based on the file name. But in the middle of filename contains the number based on that I need to sort.Could you suggest me on the same? Example filenames: /user1$ls RS.DEV.ISV.F1.RS.REFDATA.DATA... (1 Reply)
Discussion started by: praveen.thumati
1 Replies

4. UNIX for Dummies Questions & Answers

Sort by size, then list file in each directory

Hi, I have directories with name like: aaa bbb ccc ... I would like to to see which directories are the largest and then list the files within each. I have success using: du -ks * | sort -rin | head -n 20 which gives me an output like: 120 bbb 27 ccc 3 aaa ... I would like... (3 Replies)
Discussion started by: ChatPerdu
3 Replies

5. Shell Programming and Scripting

Size of file and directory

Hello. I do have a problem. The statement sounds like this: Given a directory, find all subdirectories (regardless of depth) which contain a file that has more than a half of the size of the respective subdirectory. I've tried to solve this in many ways, but all I came up with is half... (1 Reply)
Discussion started by: WorkOfArt
1 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

Can't sort file by size column

Hello, I've done ls -ls >fileout1 When I do the sort command for +4 it sorts it bu group. When I do +5 it sorts it by date. But it's skipping the file size column. Example: rwxr-xr-x 1 Grueben sup 65 16 Sep 13:58 cdee How can I sort it by file size? It doesn't... (2 Replies)
Discussion started by: Grueben
2 Replies

8. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

9. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

10. Programming

Size of a directory or a file

Hello, Here is my code: :~$ truncate -s 16M MyTestFile.txt :~$ du -h MyTestFile.txt 4,0K MyTestFile.txt Q1: Please why du -h does not work in this case ? Q2: Other than "du -h", how can i get the size of a directory (using linux command) Thanks a lot. Best Regards. (2 Replies)
Discussion started by: chercheur111
2 Replies
SORT(1) 						      General Commands Manual							   SORT(1)

NAME
sort - sort a file of ASCII lines SYNOPSIS
sort [-bcdfimnru] [-tc] [-o name] [+pos1] [-pos2] file ... OPTIONS
-b Skip leading blanks when making comparisons -c Check to see if a file is sorted -d Dictionary order: ignore punctuation -f Fold upper case onto lower case -i Ignore nonASCII characters -m Merge presorted files -n Numeric sort order -o Next argument is output file -r Reverse the sort order -t Following character is field separator -u Unique mode (delete duplicate lines) EXAMPLES
sort -nr file # Sort keys numerically, reversed sort +2 -4 file # Sort using fields 2 and 3 as key sort +2 -t: -o out # Field separator is : sort +.3 -.6 # Characters 3 through 5 form the key DESCRIPTION
Sort sorts one or more files. If no files are specified, stdin is sorted. Output is written on standard output, unless -o is specified. The options +pos1 -pos2 use only fields pos1 up to but not including pos2 as the sort key, where a field is a string of characters delim- ited by spaces and tabs, unless a different field delimiter is specified with -t. Both pos1 and pos2 have the form m.n where m tells the number of fields and n tells the number of characters. Either m or n may be omitted. SEE ALSO
comm(1), grep(1), uniq(1). SORT(1)
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy