Linux and Bash One Liners
Command Line Fu – Top One Liners
- Wed, 21 Apr 2010 13:10:33 +0000: Get your external IP address - All commands sorted by votes
$ curl ifconfig.mecurl ifconfig.me/ip -> IP Adress
curl ifconfig.me/host -> Remote Host
curl ifconfig.me/ua ->User Agent
curl ifconfig.me/port -> Port
thonks to http://ifconfig.me/
by David Winterbottom (codeinthehole.com)
- Fri, 31 Jul 2009 16:08:59 +0000: Query Wikipedia via console over DNS - All commands sorted by votes
$ dig +short txt <keyword>.wp.dg.cxQuery Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.You can also write a little shell script like:
$ cat wikisole.sh#!/bin/shdig +short txt ${1}.wp.dg.cxand run it like
./wikisole.sh unixwere your first option ($1) will be used as search term.
by David Winterbottom (codeinthehole.com)
- Tue, 31 Mar 2009 10:29:20 +0000: Quick access to the ascii table. - All commands sorted by votes
$ man asciiby David Winterbottom (codeinthehole.com)
- Fri, 20 Mar 2009 14:18:56 +0000: currently mounted filesystems in nice layout - All commands sorted by votes
$ mount | column -tParticularly useful if you're mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting.
by David Winterbottom (codeinthehole.com)
- Fri, 20 Mar 2009 11:36:04 +0000: Place the argument of the most recent command on the shell - All commands sorted by votes
$ 'ALT+.' or '<ESC> .'When typing out long arguments, such as:
cp file.txt /var/www/wp-content/uploads/2009/03/You can put that argument on your command line by holding down the ALT key and pressing the period '.' or by pressing <ESC> then the period '.'. For example:
cd 'ALT+.'would put '/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing 'ALT+.' to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.
by David Winterbottom (codeinthehole.com)
- Tue, 17 Mar 2009 16:25:29 +0000: Execute a command without saving it in the history - All commands sorted by votes
$ <space>commandPrepending one or more spaces to your command won't be saved in history.
Useful for pr0n or passwords on the commandline.
Tested on BASH.
by David Winterbottom (codeinthehole.com)
- Wed, 11 Mar 2009 09:26:05 +0000: Rapidly invoke an editor to write a long, complex, or tricky command - All commands sorted by votes
$ ctrl-x eNext time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.
by David Winterbottom (codeinthehole.com)
- Sat, 21 Feb 2009 07:53:32 +0000: mtr, better than traceroute and ping combined - All commands sorted by votes
$ mtr google.commtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.
As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over‐loaded) link.
by David Winterbottom (codeinthehole.com)
- Tue, 17 Feb 2009 22:53:07 +0000: Download an entire website - All commands sorted by votes
$ wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com-p parameter tells wget to include all files, including images.
-e robots=off you don't want wget to obey by the robots.txt file
-U mozilla as your browsers identity.
--random-wait to let wget chose a random number of seconds to wait, avoid get into black list.
Other Useful wget Parameters:
--limit-rate=20k limits the rate at which it downloads files.
-b continues wget after logging out.
-o $HOME/wget_log.txt logs the output
by David Winterbottom (codeinthehole.com)
- Sun, 15 Feb 2009 14:20:25 +0000: Lists all listening ports together with the PID of the associated process - All commands sorted by votes
$ netstat -tlnpThe PID will only be printed if you're holding a root equivalent ID.
by David Winterbottom (codeinthehole.com)
- Wed, 11 Feb 2009 10:20:15 +0000: Runs previous command replacing foo by bar every time that foo appears - All commands sorted by votes
$ !!:gs/foo/barVery useful for rerunning a long command changing some arguments globally.
As opposed to ^foo^bar, which only replaces the first occurrence of foo, this one changes every occurrence.
by David Winterbottom (codeinthehole.com)
- Sun, 08 Feb 2009 10:10:00 +0000: output your microphone to a remote computer's speaker - All commands sorted by votes
$ dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dspThis will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.
by David Winterbottom (codeinthehole.com)
- Fri, 06 Feb 2009 00:33:08 +0000: Mount a temporary ram partition - All commands sorted by votes
$ mount -t tmpfs tmpfs /mnt -o size=1024mMakes a partition in ram which is useful if you need a temporary working space as read/write access is fast.
Be aware that anything saved in this partition will be gone after your computer is turned off.
by David Winterbottom (codeinthehole.com)
- Thu, 05 Feb 2009 20:17:41 +0000: Mount folder/filesystem through SSH - All commands sorted by votes
$ sshfs name@server:/path/to/folder /path/to/mount/pointInstall SSHFS from http://fuse.sourceforge.net/sshfs.html
Will allow you to mount a folder security over a network.
by David Winterbottom (codeinthehole.com)
- Thu, 05 Feb 2009 18:33:23 +0000: Update twitter via curl - All commands sorted by votes
$ curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xmlby David Winterbottom (codeinthehole.com)
- Thu, 05 Feb 2009 17:23:43 +0000: Capture video of a linux desktop - All commands sorted by votes
$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpgby David Winterbottom (codeinthehole.com)
- Thu, 05 Feb 2009 11:57:43 +0000: Serve current directory tree at http://$HOSTNAME:8000/ - All commands sorted by votes
$ python -m SimpleHTTPServerby David Winterbottom (codeinthehole.com)
- Thu, 05 Feb 2009 09:13:23 +0000: start a tunnel from some machine's port 80 to your local post 2001 - All commands sorted by votes
$ ssh -N -L2001:localhost:80 somemachinenow you can acces the website by going to http://localhost:2001/
by David Winterbottom (codeinthehole.com)
- Wed, 04 Feb 2009 22:41:21 +0000: change to the previous working directory - All commands sorted by votes
$ cd -by David Winterbottom (codeinthehole.com)
- Wed, 04 Feb 2009 11:33:19 +0000: Compare a remote file with a local file - All commands sorted by votes
$ ssh user@host cat /path/to/remotefile | diff /path/to/localfile -Useful for checking if there are differences between local and remote files.
by David Winterbottom (codeinthehole.com)
