Commands using nl (21)

  • by determining most popular use in history using percentage . Show Sample Output

    history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
    turrtle13 · 2016-04-24 17:21:35 0
  • This is how you can do this without having to use oneline Show Sample Output

    git log | nl -w9 -v0 --body-numbering='pcommit\ [0-9a-f]\{40\}' | sed 's/^ \+\([0-9]\+\)\s\+/HEAD~\1 /'
    guywithnose · 2015-11-23 21:53:33 0
  • Print a git log (in reverse order) giving a reference relative to HEAD. HEAD (the current revision) can also be referred to as HEAD~0 The previous revision is HEAD~1 then HEAD~2 etc. . Add line numbers to the git output, starting at zero: ... | nl -v0 | ... . Insert the string 'HEAD~' before the number using sed: ... | sed 's/^ \+/&HEAD~/' . Thanks to bartonski for the idea :-) Show Sample Output

    git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'
    flatcap · 2015-11-23 21:35:57 0
  • I copied this (let's be honest) somewhere on internet and I just made it as a function ready to be used as alias. It shows the 10 most used commands from history. This seems to be just another "most used commands from history", but hey.. this is a function!!! :D Show Sample Output

    mosth() { history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10; }
    nnsense · 2015-05-11 17:41:55 3

  • 1
    read -p "Please enter the 4chan url: "|egrep '//[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait
    unixmonkey73764 · 2014-03-09 05:56:14 0
  • perhaps you should use CMD[$2] instead of CMD[$4] Show Sample Output

    history | awk '{CMD[$4]++;count++;} END { for (a in CMD )print CMD[a] " " CMD[a]/count*100 "% " a }' | sort -nr | nl | column -t | head -n 10
    jasee · 2013-07-05 02:38:04 0
  • This command print the last line of a file with in first position the total lines number. Show Sample Output

    nl FILE_NAME | tail -n 1
    P3ter · 2013-07-04 21:54:59 0
  • Interesting to see which packages are larger than the kernel package. Useful to understand which RPMs might be candidates to remove if drive space is restricted. Show Sample Output

    rpm -qa --queryformat '%{size} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16
    mpb · 2013-03-19 21:10:54 0
  • "nl -ba" numbers all lines in the file (including empty lines), "sort -nr" sorts the lines in descending order, and the "cut" command finally removes the line numbers again.

    nl -ba FILE | sort -nr | cut -f2-
    maher · 2012-06-24 23:07:06 1
  • usage: dng BRE [selection] default selection is the last match DNS is ok, but although domainnames may be easier to remember than IP numbers, it still requires typing them out. This can be error-prone. Even more so than typing IPv4 numbers, depending on the domainname, its length and complexity.

    dng(){ local a;a=$(sed '/'"$1"'/!d' /etc/hosts |sed '=;'"${2-1,$}"'!d'|sed '/ /!d');echo $a|tr '\040' '\n'|nl -bp'[0-9]$'|less -E;export dn=$(echo $a|sed 's,.* ,,');export ip=$(echo $a|sed 's, .*,,');echo \$dn=$dn;echo \$ip=$ip;}
    argv · 2012-04-01 23:57:09 0

  • 2
    nl file.txt > file_numbered.txt
    totti · 2011-09-14 20:10:49 1
  • Add permanent line numbers to a file without creating a temp file. The rm command deletes file10 while the nl command works on the open file descriptor of file10 which it outputs into a new file again named file10. The new file10 will now be numbered in the same directory with the same file name and content as before, but it will in fact be a new file, using (ls -i) to show its inode number will prove this.

    { rm -f file10 && nl > file10; } < file10
    zlemini · 2010-04-08 21:08:23 4

  • 5
    git reflog show | grep '}: commit' | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed s/commit://g | sed -e 's/HEAD*@{[0-9]*}://g'
    jimthunderbird · 2010-03-09 07:44:05 0
  • This function is used to sort selected lines of a text file to the end of that file. Especially useful in cases where human intervention is necessary to sort out parts of a file. Let's say that you have a text file which contains the words rough slimy red fluff dough For whatever reason, you want to sort all words rhyming with 'tough' to the bottom of the file, and all words denoting colors to the top, while keeping the order of the rest of the file intact. '$EDITOR' will open, showing all of the lines in the given file, numbered with '0' padding. Adding a '~' to the beginning of the line will cause the line to sort to the end of the file, adding '!' will cause it to sort to the beginning. Show Sample Output

    2end () ( export LC_ALL=C; nl -n rz $1 > $1.tmp; ${EDITOR:-vi} $1.tmp; sort $1.tmp | sed -r 's/^.*[0-9]+\t+//' > $1; rm $1.tmp; )
    bartonski · 2010-03-06 23:02:28 3

  • 1
    git log --reverse --pretty=oneline | cut -c41- | nl | sort -nr
    jimthunderbird · 2010-02-24 19:36:20 0
  • Works in RHEL5 and derivatives.

    nl <filename>
    SuperFly · 2010-01-06 16:14:43 0

  • 26
    solarislackware · 2009-12-08 19:30:32 3
  • Not as far off as you thought, now is it? -mac fanboy Show Sample Output

    file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl | tail -1 | cut -f1 -f3; file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i "mach-o object i386" |nl | tail -1 | cut -f1 -f3
    digitalshadow · 2009-09-11 16:43:27 1
  • Next time you see a mac fanboy bragging about 64-bitness of 10.6 give him this so he might sh? Show Sample Output

    file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -i x86_64 |nl |tail -1 |cut -f1 -f3 && file /System/Library/Extensions/*.kext/Contents/MacOS/* |grep -v x86_64 |nl |tail -1 |cut -f1 -f3
    commandlinefu · 2009-09-03 14:28:02 3
  • The nl command lists the contents of a file where is each line is prefixed by a line number. For more information about this command, check out its man page. I tested under Mac OS X and Xubuntu 9.04

    nl filename | more
    haivu · 2009-05-04 07:35:16 3
  • Low on disk space? Check the largest installed RPMs for delete canditates. Show Sample Output

    rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
    mpb · 2009-03-15 22:18:17 0

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Copy a file structure without files
Taken from:

Do some Perl learning...
Prerequisites: module Pod::Webserver installed. You can install it typing: $ sudo perl -MCPAN -e 'install Pod::Webserver' You can replace elinks with your fav browser. For FF: $podwebserver& sleep 2; firefox -remote 'openurl(, new-tab )' If you have Firefox open, this will pop-up the index web in a new tab.

Fetch all GPG keys that are currently missing in your keyring
For instance, if people have signed your key, this will fetch the signers' keys.

Rename files in batch

Decode base64-encoded file in one line of Perl
Another option is openssl.

Print every Nth line (to a maximum)
Thanks to knoppix5 for the idea :-) Print selected lines from a file or the output of a command. Usage: $ every NTH MAX [FILE] Print every NTH line (from the first MAX lines) of FILE. If FILE is omitted, stdin is used. The command simply passes the input to a sed script: $ sed -n -e "${2}q" -e "0~${1}p" ${3:-/dev/stdin} print no output $ sed -n quit after this many lines (controlled by the second parameter) $ -e "${2}q" print every NTH line (controlled by the first parameter) $ -e "0~${1}p" take input from $3 (if it exists) otherwise use /dev/stdin ${3:-/dev/stdin}

Convert a file from ISO-8859-1 (or whatever) to UTF-8 (or whatever)
I use it sometimes when I work on a french file transferred from a windows XP to a Debian-UTF8 system. Those are not correctly displayed: ? ? ? and so on $man tcs # for all charsets

Install pip with Proxy
Installs pip packages defining a proxy

Watch active calls on an Asterisk PBX
Only the number of calls nothing else.

Cut/Copy everything arround brackets or parentheses on vim (in normal mode)
Put the cursor on either curly braces ( {, } ). Then press d% The d is delete command, and % is movement command that move the cursor to another matching parentheses (or curly braces in this case). This action will delete every character that was on the way of the movement (from the first curly braces to the second).

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: