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.


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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,446 results
date +%A | cut -c $(( $(date +%A | wc -c) - 1 ))
2010-04-07 00:23:15
User: DaveQB
Functions: cut date wc
Tags: bash echo cut date wc
0

A command to find out what the day ends in. Can be edited slightly to find out what "any" output ends in.

NB: I haven't tested with weird and wonderful output.

ls -Xp /path/to/dir | grep -Eo "\.[^/]+$" | uniq
2010-08-12 16:32:54
User: karpoke
Functions: grep ls
Tags: uniq ls grep
0

If we want files with more than one extension, like .tar.gz, only appear the latest, .gz:

ls -Xp /path/to/dir | grep -Eo "\.[^./]+$" | uniq
for url in `cat urls `; do title=`curl $url 2>&1 | grep -i '<title>.*</title>'` && curl $url > /tmp/u && mail -s "$title" [email protected] < /tmp/u ; done
2010-10-16 19:10:19
Functions: grep mail
0

Note, you need to replace the email address with your private Instapaper email address.

There are a bunch of possible improvements such as,

- Not writing a temp file

- Doesnt strip tags (tho Instapaper does thankfully)

- Shouldnt require 2 curls

hexdump -e '8/1 "%02X ""\t"" "' -e '8/1 "%c""\n"' /dev/sda1 | less /mystring
dpkg -S locale.alias
for((r=1;r<10;r++));do v=1;echo -n "$v ";for((c=1;c<$r;c++));do v2=$(($(echo "$v*($r-$c)/$c")));echo -n "$v2 ";v=$v2;done;echo;done
2011-02-10 18:38:04
User: flatcap
Functions: echo
Tags: bash math
0

http://en.wikipedia.org/wiki/Pascal%27s_triangle

This one's for bartonski. Enjoy.

132 characters. I'm sure we can do better.

Note: after row 64 we overflow integer maths.

pwdadm -f ADMCHG [user]
2011-04-28 02:22:03
User: mack
0

This command is AIX compatible.

It will prompt the user for a new password at next logon

awk 'sub("$", "\r")' unixfile.txt > winfile.txt
cat dirtyfile.txt | awk '{gsub(/[[:punct:]]/,"")}1' | tr A-Z a-z | sed 's/[0-9]*//g' | sed -e 's/ //g' | strings | tr -cs '[:alpha:]' '\ ' | sed -e 's/ /\n/g' | tr A-Z a-z | sort -u > cleanfile.txt
2011-08-28 01:26:04
User: purehate
Functions: awk cat sed sort strings tr
0

Using large wordlists is cumbersome. Using password cracking programs with rules such as Hashcat or John the ripper is much more effective. In order to do this many times we need to "clean" a wordlist removing all numbers, special characters, spaces, whitespace and other garbage. This command will covert a entire wordlist to all lowercase with no garbage.

find . -newer /tmp/foo -exec touch --date "2011-12-12" {} \;
2011-12-15 04:55:57
User: djangofan
Functions: find touch
0

Modify all files newer than another file and touch them to a specific date.

find . ! -regex '.*/\(unit-test\|android\)/.*' \( -name '*.c' -o -name '*.cpp' \)
2012-04-26 17:53:45
User: flatcap
Functions: find
Tags: find
0

Find files matching multiple descriptions (*.c and *.cpp) excluding multiple directories (unit-test and android).

cut -d: -f 1 names.txt
2012-06-26 19:28:25
User: ankush108
Functions: cut
Tags: column cut
0

Display the 1st field (employee name) from a colon delimited file

perl -e '$s="$s\xFF" while length($s)<512; print $s while 1' | dd of=/dev/sdX
^bar^foo^
perl -lne 'print unless $seen{$_}++'
^Z <...> % &
2014-06-13 15:35:52
User: Dev_NIX
Tags: job control
0

Like this you can continue a suspended job without blocking again your terminal

git reflog --date=local | grep "Oct 2 .* checkout: moving from .* to" | grep -o "[a-zA-Z0-9\-]*$" | sort | uniq
2014-10-03 15:12:22
User: Trindaz
Functions: grep sort
0

Replace "Oct 2" in the first grep pattern to be the date to view branch work from

sudo aa-complain /etc/apparmor.d/usr.bin.chromium-browser
2015-09-30 18:56:28
User: lordtoran
Functions: sudo
0

If AppArmor is installed with all profiles enforced, Chromium may refuse to start, printing a "failed to launch zygote process" error on stderr.

This command switches the Chromium profile from enforce to complain mode, effectively un-sandboxing the browser, but depending on the system setup it may be a smaller deal than a nonfunctional application.

manview() { lynx -dump -accept_all_cookies 'http://www.csuglab.cornell.edu/cgi-bin/adm/man.cgi?section=all&topic='"$1" | less; }
2009-03-11 19:02:11
User: Ben
0

manview searches man pages on the internets in case the man command doesn't work for some reason or if you think the man pages in Cornell's flavor of Solaris might differ from yours. It dumps the manpage info from lynx to less, so it ends up looking remarkably like a real manpage. Put it in your .bash_profile or .bashrc, and then you can use it like a regular command: typing "manview ssh" will give you the manpage for ssh.

awk '{print NR,$0}'
df -kh /dev/vg0*/lv*
rdesktop -u <username> -p <password> -g 1366x724 -a 16 -D -z -P <servername / IP Address>
2010-06-09 11:47:35
User: mariusbutuc
Tags: rdesktop RDP
0

The above command will:

- open a Remote Desktop connection to [servername / IP Address],

- authenticate using [username] and [password],

- configure resolution to best fit your desktop (I have a 1366x768px resolution so I left space for 2 panels of 22px each),

- sets the color depth for the connection to 16 bpp,

- hides the window manager decorations,

- enables compression of the RDP data stream,

- enables persistent bitmap caching.

netstat -a -o -n | grep 8080
2011-04-28 09:58:59
User: evandrix
Functions: grep netstat
0

I cannot run Tomcat from Eclipse. It says that there?s other process that is running on port 8080, but I don?t know what is the process, and how to stop it from the Services manger in Windows. So here?s how you can kill and find out what is that process:

To find out what PID 8080 was (hopefully not a trojan)

I typed tasklist /FI ?PID eq 8080″

taskkill /F /PID 2600

vlc mms://twcilivewm.fplive.net/twcilive-live/twci_350
ps aux | grep PID | grep -v 'grep' | awk '{ print $1 }'
2011-11-05 04:53:29
User: nssy
Functions: awk grep ps
Tags: bash awk grep ps
0

Gets the current system user running a process with the specified pid