Thursday, February 25, 2016

How to sort the files and directories size wise

   1 . Command -  Using ls command

     
     Command              ->   ls -lS     
                                              l  - Long Listing  which lists permission, links, user, group, size ,
                                                  modified/created date, file name             
                                             S  - Sort the files by Size in Descending order by default. 
                                                    Note -S is a capital letter  
     Command Usage   ->  List the files and directories file size wise ( default descending order) 





   2 . Command -  Using ls & sort commands


     Command              ->    ls -l | sort -k 5 -r   

                                             k - indicates the key and 5 indicates 5th key ( size)
                                             r - reverse in descending order size wise
                             
     Command Usage   ->  This command list the file in long format and pass the output into
                                            sort  command. Sort command takes the 5th key ( size ) and order
                                            by size in descending order.  
  
  Note                             ->   pipe symbol (|) is to pass the output of 
                                              command to next command. 

   

No comments:

Post a Comment