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 using sudo from sorted by
Terminal - Commands using sudo - 400 results
sudo chown -R user2:user2 /../../somedirectory
2009-09-23 21:27:45
User: bkn390
Functions: chown sudo
-1

This will change the ownership of /../../somedirectory as well as all its subdirectories so they will be be owned by user2 - typically used when a directory is owned by root:root

(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
find repMainPath -maxdepth 1 -mindepth 1 -type d | while read dir; do echo processing $dir; sudo svnadmin dump --deltas $dir >dumpPath/`basename $dir`; done
2009-09-15 20:14:51
User: Marco
Functions: dump echo find read sudo
Tags: bash svn
2

This command dumps all SVN repositories inside of folder "repMainPath" (not recursively) to the folder "dumpPath", where one dump file will be created for each SVN repository.

sudo tune2fs -m 1 /dev/sda4
2009-09-14 21:11:55
User: bassel
Functions: sudo tune2fs
2

According to tune2fs manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons (like syslogd, for ex.) and other root level processes; also the reserved space can prevent the filesystem from fragmenting as it fills up. By default this is 5% regardless of the size of the partition.

http://www.ducea.com/2008/03/04/ext3-reserved-blocks-percentage/

sudo arp -s 192.168.1.200 00:35:cf:56:b2:2g temp && ssh root@192.168.1.200
2009-09-11 07:49:28
User: svg
Functions: arp ssh sudo
8

Instead of looking for the right ip address, just pick whatever address you like and set a static ip mapping.

sudo dd if=/dev/hda1 of=/dev/hdb2
2009-09-05 09:16:52
User: 0disse0
Functions: dd sudo
5

This command clone the first partition of the primary master IDE drive to the second partition

of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)

sudo mknod /dev/ttyS4 c 4 68
2009-09-05 09:12:44
User: 0disse0
Functions: c++ mknod sudo
Tags: serial mknod tty
0

When you need to add another tty device that can automatically start at boot time

sudo dscl localhost -append /Local/Default/Groups/admin GroupMembership username
2009-09-03 04:40:10
User: kulor
Functions: sudo
0

adding users to groups on OS X is not a straightforward process, you need to use the new in built in Directory Service command line utility...

sudo grub-install --recheck /dev/sda1
sudo /bin/netstat -tpee
2009-08-28 04:02:10
User: unixbhaskar
Functions: sudo
Tags: shell
3

To get the connection information of protocol tcp and extended infortmation.

sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1
2009-08-27 14:18:47
User: alvinx
Functions: du find sudo tail xargs
2

get diskusage of files (in this case logfiles in /var/log) modified during the last n days:

sudo find /var/log/ -mtime -n -type f | xargs du -ch

n -> last modified n*24 hours ago

Numeric arguments can be specified as

+n for greater than n,

-n for less than n,

n for exactly n.

=> so 7*24 hours (about 7 days) is -7

sudo find /var/log/ -mtime -7 -type f | xargs du -ch | tail -n1
sudo aptitude unmarkauto $(apt-cache depends some-deb-meta-package-name | grep Depends | cut -d: -f2)
2009-08-26 12:56:33
User: yra
Functions: cut grep sudo
2

Debian: Mark all dependent packages as manually installed. So they are not automatically removed if you remove some meta package - like gnome-desktop-environment for example.

sudo iptables-save > /etc/iptables.up.rules
2009-08-19 14:55:05
User: kamiller
Functions: iptables-save sudo
-3

Stores the currently active iptables rules to a file that will be applied upon reboot

sudo iptables-restore < /etc/iptables.test.rules
2009-08-19 14:38:08
User: kamiller
Functions: iptables-restore sudo
Tags: iptables
-2

If you don't save the rule set it won't be applied during a reboot

sudo dmesg
sudo du -ks $(ls -d */) | sort -nr | cut -f2 | xargs -d '\n' du -sh 2> /dev/null
2009-08-17 22:21:09
User: Code_Bleu
Functions: cut du ls sort sudo xargs
Tags: disk usage
7

This allows the output to be sorted from largest to smallest in human readable format.

vditool COPYDD my.vdi my.dd ; sudo mount -t ntfs -o ro,noatime,noexex,loop,offset=32256 my.dd ./my_dir
sudo du -sh $(ls -d */) 2> /dev/null
sudo snmptrap -m ALL -v 2c -c public trapserver "" UCD-DEMO-MIB::ucdDemoPublic SNMPv2-MIB::sysLocation.0 s "Just here"
sudo cat /usr/share/icons/*/*/* > /dev/dsp
2009-08-06 03:12:27
User: 12345678
Functions: cat sudo
0

Plays the sound of the file, should sound like *some* kind of music, most files sound like static but some are really cool.

variations:

sudo cat /dev/sda > /dev/dsp sudo cat /dev/sda5 | aplay

Check out http://bbs.archlinux.org/viewtopic.php?id=70937 for more variations!

semi-dupe--like http://www.commandlinefu.com/commands/view/985/generate-white-noise but with different syntax and program.

curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
2009-08-03 10:14:02
User: Patola
Functions: echo screen sudo top
18

This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.

htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.

The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml

sudo apt-get -o Acquire::http::Dl-Limit=25 install <package>
2009-07-31 19:43:45
User: dunnix
Functions: install sudo
Tags: apt-get
4

apt-get is pretty aggressive when it downloads, potentially hogging the bandwidth of your network. The 25 is in KB, change this to your needs.

sudo wget -c "http://nmap.org/dist/nmap-5.00.tar.bz2" && bzip2 -cd nmap-5.00.tar.bz2 | tar xvf - && cd nmap-5.00 && ./configure && make && sudo make install
2009-07-26 11:36:53
User: hemanth
Functions: bzip2 cd make sudo tar wget
-6

Just copy and paste the code in your terminal.

Note : sudo apt-get for debian versions , change as per your requirement .

Source : www.h3manth.com