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.

Universal configuration monitoring and system of record for IT.

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:



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!

Top Tags





Commands by zlemini from sorted by
Terminal - Commands by zlemini - 40 results
sudo -E rpm -Uvh "http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
2015-10-29 14:06:48
User: zlemini
Functions: rpm sudo

In this case the current user has proxy variable set which allows access to the rpm on the internet but needs root privs to install it.

Running sudo -E preserves the current user proxy var and allows the rpm install to be executed with sudo.

: </dev/tcp/
2015-08-28 19:07:27
User: zlemini

For times when netcat isn't available.

Will throw a Connection refused message if a port is closed.


(: </dev/tcp/ &>/dev/null && echo "OPEN" || echo "CLOSED"
sed -i.$(date +%F@%T) 's/^LogLevel warn/LogLevel debug/g' httpd.conf
2015-07-22 14:47:26
User: zlemini
Functions: date sed

httpd.conf httpd.conf.2015-07-22@14:43:20

curl -s -o /dev/null -w "%{http_code}\n" localhost
sudo bash -c "> /var/log/httpd/access_log"
for i in chmod chown; do sudo "$i" --reference=/home/user/copyfromfile /tmp/targetfile; done
2014-08-28 15:08:32
User: zlemini
Functions: chmod sudo

Copy both perms and owner group from one file to another.

awk -F: '{print $2}' access_log | sort | uniq -c
pssh -h RemoteHosts.txt -P -I < ~/LocalScript.sh
2014-07-14 16:02:12
User: zlemini

Runs a local script over ssh assuming ssh keys are in place.

-P argument prints results to stdout.

# Uses - https://code.google.com/p/parallel-ssh/

prepend () { array=("$@"); len=${#array[@]}; file=${array[$len-1]}; text=${array[@]:0:$len-1}; printf '%s\n' 0a "$text" . w | ed -s "$file"; }
2013-12-09 21:59:26
User: zlemini
Functions: ed printf
Tags: sed replace


$ prepend content to add [filename]

Uses ed, so no temp files created.

cut -d " " -f1,4 access_log | sort | uniq -c | sort -rn | head
2013-09-20 21:29:32
User: zlemini
Functions: cut sort uniq

Analyze an Apache access log for the time period with most activity and display the hit count, requesting IP and the timestamp. May help detect a brute force dos attack.

curl -s http://www.census.gov/popclock/data/population/world | awk -F'[:,]' '{print $7}'
sxh () { for i in "${@:2}"; do ssh "$i" "$1"; done ; }
2013-04-12 11:34:02
User: zlemini
Functions: ssh

Oneliner to run commands on multiple servers over ssh.

- First parameter "$1" is the command you want to execute remotely.

( It can be multiple commands e.g. "hostname;uptime")

- Second parameter "${@:2}" represents the remote host/s you want to run the command/s on.

prompt (){ if [ "$1" = "on" ]; then . ~/.bash_profile; else if [ "$1" = "off" ];then PS1="$ ";fi;fi; }
2013-02-17 13:41:18
User: zlemini

Bash function to change your default prompt to something simpler and restore it to normal afterwards.

diff -BI '^#' file{1,2}
python -c "help('modules')"
echo /home/foo/dir1/bar | awk -F/ -v OFS=/ '{$3 = "dir2"}1'
2012-10-26 16:17:20
User: zlemini
Functions: awk echo

Awk replaces the value of a specific field while retaining the field separator "/" .

grep -- -- file
xmlstarlet ed -s "/breakfast_menu/food" -t elem -n 'foo' -v "bar" simple.xml
2012-06-03 18:35:53
User: zlemini
Functions: ed

This inserts an element as last child under /breakfast_menu/food in simple.xml.

xml used - http://www.w3schools.com/xml/simple.xml

perl -e 'printf "%04o\n", (stat shift)[2] & 0777;' file
2012-03-22 15:05:04
User: zlemini
Functions: perl stat

This prints file access rights in octal - useful when "stat" is unavailable.

pscp -h hosts.txt -l username /etc/hosts /tmp/hosts
2012-01-24 12:19:30
User: zlemini

You can push files to up to 32 servers at once assuming ssh keys are in place.

Great tool, it is part of the pssh suite.

ssh -t remotebox "tail -f /var/log/remote.log"
2011-12-12 20:24:23
User: zlemini
Functions: ssh

This is also handy for taking a look at resource usage of a remote box.

ssh -t remotebox top
find / -type f -size +500M -size -1G
awk '{gsub("foo","bar",$5)}1' file
2011-11-09 18:24:23
User: zlemini
Functions: awk

Awk replaces every instance of foo with bar in the 5th column only.

awk '{$1=$3=""}1' file
2011-10-25 22:15:06
User: zlemini
Functions: awk

Print all columns except the 1st and 3rd.

wget -b http://dl.google.com/android/android-sdk_r14-linux.tgz