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,454 results
netstat -lptu | grep -E "22.*ESTABLISHED" | cut -s -d ':' -f2 | awk '{print $2}'
2014-06-13 08:38:16
User: DarkXDroid
Functions: awk cut grep netstat
0

Show If Someone Is Connected To The Android Device On And Get Their IP Address

for i in `cat hosts_list`; do RES=`ssh [email protected]${i} "ps -ef " |awk '/[p]rocessname/ {print $2}'`; test "x${RES}" = "x" && echo $i; done
2014-10-03 14:57:54
User: arlequin
Functions: awk echo test
Tags: ssh awk test ps
0

Given a hosts list, ssh one by one and echo its name only if 'processname' is not running.

echo 'echo /etc/games/fortune > ~/mailsignature.txt' >> .bashrc
2015-11-07 15:17:12
User: dededede
Functions: echo
0

In Thunderbird open the settings for your email account, mark the checkbox for 'Attach the signature from a file instead' and use the filename '~/mailsignature.txt'

Now every time when you open a terminal you see the fortune displayed in the terminal and the mail signature gets regenerated.

bosh deployments --json | jq '.Tables[0].Rows[][0]' --raw-output
echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search]
2009-02-05 18:07:23
User: wwest4
Functions: echo read sed
0

customizable context searches - if you know sed, this is a basis for more complex context control than grep --context offers

gconftool-2 --set "/system/http_proxy/use_http_proxy" --type boolean true
2009-02-13 22:00:52
User: Kysic
0

Solution to activate (or deactivate with false instead of true) the global mandatory proxy under Ubuntu (not tested elsewhere).

Others keys you can configure :

gconftool-2 --set "/system/http_proxy/host" --type string "

gconftool-2 --set "/system/http_proxy/port" --type int 8080

gconftool-2 --set "/system/http_proxy/ignore_hosts" --type list --list-type string ["localhost","127.0.0.1","*.local"]

gconftool-2 --set "/system/proxy/mode" --type string manual

nikto.pl -h yourwebserver
2009-08-29 04:54:43
User: unixbhaskar
Tags: Security shell
0

This is wonderful perl script to check the web server security and vulnerability .Get it from here :http://www.cirt.net/nikto2

Here are some key features of "Nikto":

? Uses rfp's LibWhisker as a base for all network funtionality

? Main scan database in CSV format for easy updates

? Determines "OK" vs "NOT FOUND" responses for each server, if possible

? Determines CGI directories for each server, if possible

? Switch HTTP versions as needed so that the server understands requests properly

? SSL Support (Unix with OpenSSL or maybe Windows with ActiveState's Perl/NetSSL)

? Output to file in plain text, HTML or CSV

? Generic and "server type" specific checks

? Plugin support (standard PERL)

? Checks for outdated server software

? Proxy support (with authentication)

? Host authentication (Basic)

? Watches for "bogus" OK responses

? Attempts to perform educated guesses for Authentication realms

? Captures/prints any Cookies received

? Mutate mode to "go fishing" on web servers for odd items

? Builds Mutate checks based on robots.txt entries (if present)

? Scan multiple ports on a target to find web servers (can integrate nmap for speed, if available)

? Multiple IDS evasion techniques

? Users can add a custom scan database

? Supports automatic code/check updates (with web access)

? Multiple host/port scanning (scan list files)

? Username guessing plugin via the cgiwrap program and Apache ~user methods

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.