≡ Menu

sort command

I have a large number of files stored in ~/Downloads/ directory. How do I sort and print sizes in human readable format using du -h command under Ubuntu Linux LTS version 12.04 or any other Linux distributions?
[click to continue…]

Linux ls Command: Sort Files By Size

How do I sort all *.avi or *.py files in $HOME/Download/ directory by file size using Linux ls command line utility?
[click to continue…]

Linux / Unix: Sort Specific Field or Column

How do I sort output of find . -type f -iname "pattern*" -ls command by seventh column in Linux? Sample input:

7782638 15084 -rw-r--r-- 1 tom tom 15422474 Aug 1 2011 ./logserver42/2011/hsbcreports_201107.html
7782637 14504 -rw-r--r-- 1 tom tom 14830464 Jul 1 2011 ./logserver42/2011/hsbcreports_201106.html
7782643 14408 -rw-r--r-- 1 tom tom 14730488 Dec 1 2011 ./logserver42/2011/hsbcreports_201111.html
7782640 19656 -rw-r--r-- 1 tom tom 20101379 Oct 1 2011 ./logserver42/2011/hsbcreports_201109.html
7782634 17588 -rw-r--r-- 1 tom tom 17985190 Apr 1 2011 ./logserver42/2011/hsbcreports_201103.html
7782641 20796 -rw-r--r-- 1 tom tom 21263382 Nov 1 2011 ./logserver42/2011/hsbcreports_201110.html
7798789 13296 -rw-r--r-- 1 tom tom 13590695 Mar 1 2012 ./logserver42/2012/hsbcreports_201202.html
7798788 12220 -rw-r--r-- 1 tom tom 12495686 Feb 1 2012 ./logserver42/2012/hsbcreports_201201.html
5701709 1648 -rw-r--r-- 1 tom tom 1681600 Nov 1 11:14 ./logserver42/2012/hsbcreports_201210.html
7798802 8944 -rw-r--r-- 1 tom tom 9138603 Jun 1 10:13 ./logserver42/2012/hsbcreports_201205.html
5701710 648 -rw-r--r-- 1 tom tom 657811 Nov 10 11:13 ./logserver42/2012/hsbcreports_201211.html
7798805 7360 -rw-r--r-- 1 tom tom 7523891 Sep 1 10:11 ./logserver42/2012/hsbcreports_201208.html
7323999 776 -rw-r--r-- 1 tom tom 787924 Jun 12 2006 ./logserver42/2006/hsbcreports_200605.html
7324001 140 -rw-r--r-- 1 tom tom 139058 Aug 22 2006 ./logserver42/2006/hsbcreports_200607.html
7324000 44 -rw-r--r-- 1 tom tom 41447 Jun 12 2006 ./logserver42/2006/hsbcreports_200606.html
7324003 1972 -rw-r--r-- 1 tom tom 2014614 Oct 1 2006 ./logserver42/2006/hsbcreports_200609.html
7356496 3136 -rw-r--r-- 1 tom tom 3205737 Dec 1 2007 ./logserver42/2007/hsbcreports_200711.html

I need the following output:

7324000 44 -rw-r--r-- 1 tom tom 41447 Jun 12 2006 ./logserver42/2006/hsbcreports_200606.html
7324001 140 -rw-r--r-- 1 tom tom 139058 Aug 22 2006 ./logserver42/2006/hsbcreports_200607.html
5701710 648 -rw-r--r-- 1 tom tom 657811 Nov 10 11:13 ./logserver42/2012/hsbcreports_201211.html
7323999 776 -rw-r--r-- 1 tom tom 787924 Jun 12 2006 ./logserver42/2006/hsbcreports_200605.html
5701709 1648 -rw-r--r-- 1 tom tom 1681600 Nov 1 11:14 ./logserver42/2012/hsbcreports_201210.html
7324003 1972 -rw-r--r-- 1 tom tom 2014614 Oct 1 2006 ./logserver42/2006/hsbcreports_200609.html
7356496 3136 -rw-r--r-- 1 tom tom 3205737 Dec 1 2007 ./logserver42/2007/hsbcreports_200711.html
7798805 7360 -rw-r--r-- 1 tom tom 7523891 Sep 1 10:11 ./logserver42/2012/hsbcreports_201208.html
7798802 8944 -rw-r--r-- 1 tom tom 9138603 Jun 1 10:13 ./logserver42/2012/hsbcreports_201205.html
7798788 12220 -rw-r--r-- 1 tom tom 12495686 Feb 1 2012 ./logserver42/2012/hsbcreports_201201.html
7798789 13296 -rw-r--r-- 1 tom tom 13590695 Mar 1 2012 ./logserver42/2012/hsbcreports_201202.html
7782643 14408 -rw-r--r-- 1 tom tom 14730488 Dec 1 2011 ./logserver42/2011/hsbcreports_201111.html
7782637 14504 -rw-r--r-- 1 tom tom 14830464 Jul 1 2011 ./logserver42/2011/hsbcreports_201106.html
7782638 15084 -rw-r--r-- 1 tom tom 15422474 Aug 1 2011 ./logserver42/2011/hsbcreports_201107.html
7782634 17588 -rw-r--r-- 1 tom tom 17985190 Apr 1 2011 ./logserver42/2011/hsbcreports_201103.html
7782640 19656 -rw-r--r-- 1 tom tom 20101379 Oct 1 2011 ./logserver42/2011/hsbcreports_201109.html
7782641 20796 -rw-r--r-- 1 tom tom 21263382 Nov 1 2011 ./logserver42/2011/hsbcreports_201110.html

[click to continue…]

I need to get a list of sizes in human readable du output format. How do I get the output for du command in GB under Linux or UNIX operating systems?
[click to continue…]

How To Use awk In Bash Scripting

How do I use awk pattern scanning and processing language under bash scripts? Can you provide a few examples?
[click to continue…]

Linux / UNIX Shell: Sort Date

Q. How do I sort date type of data stored in a text file which is in following sample format:

Code Date TIME
HOS05 23/12/2008 10AM
HOS06 15/12/2008 2PM
HOS62 29/12/2008 10AM
HOS64 23/12/2008 2PM
HOS70 26/12/2008 10AM
ZFT01 06/12/2008 10AM
HOS73 11/12/2008 2PM
MHOS051 05/12/2008 10AM
MHOS041 20/12/2008 2PM
MHOS042 27/12/2008 2PM
MHOS053 11/12/2008 10AM
MHOS043 30/12/2008 2PM

How do I sort data date and time wise?
[click to continue…]

Shell: How To Remove Duplicate Text Lines

Q. I need to sort data from a log file but there are too many duplicate lines. How do I remove all duplicate lines from a text file under GNU/Linux?
[click to continue…]