Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands by hute37 from sorted by
Terminal - Commands by hute37 - 25 results
netstat -tlpn | sort -t: -k2 -n
2014-07-22 14:08:01
User: hute37
Functions: netstat sort
Tags: netstat
4

Show TCP Listen ports sorted by number

(bugs: IPV6 addresses not supported)

while (true); do date --utc; done | uniq -c
startx -- -fullscreen -noresize -unixkill
alias ssh-x='ssh -c arcfour,blowfish-cbc -XC'
/usr/bin/Xephyr :5 -query localhost -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 01:21:36
User: hute37
Tags: Xephyr xdmcp
-1

XDMCP ust be enabled (gdm,lightdm,xdm etc )

xinit $(which awesome) -- /usr/bin/Xephyr :5 -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 00:54:33
User: hute37
Functions: which
Tags: awesome
-2

alternatives:

xinit $(which gnome-awesome-session)

with cat /usr/local/bin/gnome-awesome-session:

#!/bin/bash

exec gnome-session --session awesome "$@"

following: http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome

note: in ubuntu 12.10 a probable Xephyr recent bug rejects keybd option ...

ssh -XfC -c blowfish user@host Xephyr dpms -fullscreen -query localhost :5
2012-11-01 18:59:57
User: hute37
Functions: ssh
Tags: ssh X Xephyr xdmcp
-1

ssh compresion -C option ...

on slow connection VNC performs better but in local LAN native secure X protocol is an option

command 3>&1 1>&2 2>&3 | tee file
2012-10-30 10:53:21
User: hute37
Functions: command tee
1

taken from

http://www.unix.com/shell-programming-scripting/158311-how-tee-stderr.html

"

What does it mean?

The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are:

- Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output;

- Making file descriptor 1 a copy of file descriptor 2, the standard error output;

- Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output)

in a short: we swapped the standard output and the standard error output.

"

cat z.log | perl -ne 'BEGIN{ print "DATE;RATE\n"; } /\[(\d.*)\]/ && print $1; /CURRENT RATE: +(\S+) msg.*/ && print ";" .$1 . "\n"; '
2012-04-03 13:52:20
User: hute37
Functions: cat perl
1

extract data in multiline blocks of data with perl pattern matching loop

cat z.log | cut -d ':' -f1,2 | uniq -c
cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
cat z.log | grep Timeout | cut -d ':' -f1 | sort | uniq -c
#(see sample) $ cat x | perl -pe 'BEGIN{ print "TIME;...\n"; } s!(\S+) - (\S+) - \[(\d\d)/(\S\S\S)/(\S+):(\d\d):(\d\d:\d\d) \S+\] "(\S+) (.*/)(\S+)(?:\.([^?]*)(\?\S*)?) HTTP/\S+" (\d+) (\S+)!$3-$4-$5 $6:$7;$6;$2;$1;$8;$13;1;$14;$11;$10;$9;$12;!' > x.csv
2012-02-10 16:58:50
User: hute37
Functions: cat perl
2

- excel date compatible with a separate hour field

- added a fixed 1 for easier request counter aggregation

- split URL in directory, filename, fileext, query

- used with tomcat valve with response bytes replaced by elapsed time

pcregrep --color -M -N CRLF -e "SQLEngine\.\w+\W*\([^\)]*\)" -r --include='\.java$'
cat table-mv.txt | perl -pe 's{([^;]+);([^;]+)}{tbl$1/tbl$2}' | perl -pe 's{(\S+)}{perl -i -pe #s/$1/g# xxx.sql}' | tr "#" "\'" | bash
2011-10-05 15:55:34
User: hute37
Functions: cat perl tr
0

with a semicolon text file map, apply multiple replace to a single file

perl -i -pe 'BEGIN{undef $/;} s/START.*?STOP/replace_string/smg' file_to_change
while true ; do sleep 1 ; clear ; (netstat -tn | grep -P ':36089\s+\d') ; done
2011-09-28 11:39:43
User: hute37
Functions: clear grep netstat sleep true
-3

shell loop to scan netstat output avoiding loolback aliases (local/remote swap for local connections)

/bin/ls *.png | xargs -l1 -I {} convert {} -modulate 100,100,70 ../../icons/32x32/{}
while sleep 1; do date; (netstat -a -n | grep 80) ; done
convert -compress jpeg *.jpg mydoc.pdf
ls *.jpg | awk -F'.' '{ printf "%s %04d.%s\n", $0, $1, $2; }' | xargs -n2 mv
2011-05-01 13:32:58
User: hute37
Functions: awk ls printf xargs
Tags: awk mv xargs
3

rename file name with fixed length nomeric format pattern

setxkbmap it
pcregrep -r --exclude_dir='.svn' --include='.*jsp$' -A 2 -B 2 --color "pHtmlHome" .
2010-12-09 15:26:07
User: hute37
Tags: perl grep
0

range context (-A -B) search, with exclusion of vcs directories

pcregrep --color -M -N CRLF "owa_pattern\.\w+\W*\([^\)]*\)" source.sql
sudo hwinfo --framebuffer
2010-10-03 14:45:02
User: hute37
Functions: sudo
4

look at /boot/grub/menu.lst for somethig like:

## additional options to use with the default boot option, but not with the

## alternatives

## e.g. defoptions=vga=791 resume=/dev/hda5

## defoptions=vga=795

# defoptions=vga=873

## altoption boot targets option

## multiple altoptions lines are allowed

## e.g. altoptions=(extra menu suffix) extra boot options

## altoptions=(recovery) single

# altoptions=(verbose mode) vga=775 debug

# altoptions=(console mode) vga=ask

# altoptions=(graphic mode) quiet splash

# altoptions=(recovery mode) single

vga=(decimal value) is framebuffer mode