Commands by knl (1)

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

Check These Out

Replace spaces in a filename with hyphens
As long as you have perl based rename. You can check: =$ rename --help Unknown option: help Usage: rename [-v] [-n] [-f] perlexpr [filenames] That's the good one.

Download and install the OpenStore on the Ubuntu Phone
This will download and install the latest version of the open store on the ubuntu phone, this store includes unconfined applications such as the TweakGeek and the Ubuntu Touch Tweak Tool. You can see the install instructions from here:

'readlink' equivalent using shell commands, and following all links
This is a equivalent to the GNU ' readlink' tool, but it supports following all the links, even in different directories. An interesting alternative is this one, that gets the path of the destination file $ myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link" | sed "s|^\([^/].*\)\$|$(dirname $1)/\1|"); }

Backup a filesystem to a remote machine and use cstream to throttle bandwidth of the backup
This command will nicely dump a filesystem to STDOUT, compress it, encrypt it with the gpg key of your choice, throttle the the data stream to 60kb/s and finally use ssh to copy the contents to an image on a remote machine.

Count all the files in the directory and child directories

Print just line 4 from a textfile
this method should be the fastest

Execute multiple commands from history
Assuming that 219,229 and 221 are entries in history, I recall them in a single line for execute multiple commands 219 ifdown wlan0 ... 221 ifup wlan0 ... 229 iwconfig wlan0 mode Managed so the result is execution of # ifdown wlan0 ; iwconfig wlan0 mode Managed ; ifup wlan0

Startup a VPN connection through command line

get rid of lines with non ascii characters
found here:

Read and write to TCP or UDP sockets with common bash tools
Ever needed to test firewalls but didn't have netcat, telnet or even FTP? Enter /dev/tcp, your new best friend. /dev/tcp/(hostname)/(port) is a bash builtin that bash can use to open connections to TCP and UDP ports. This one-liner opens a connection on a port to a server and lets you read and write to it from the terminal. How it works: First, exec sets up a redirect for /dev/tcp/$server/$port to file descriptor 5. Then, as per some excellent feedback from @flatcap, we launch a redirect from file descriptor 5 to STDOUT and send that to the background (which is what causes the PID to be printed when the commands are run), and then redirect STDIN to file descriptor 5 with the second cat. Finally, when the second cat dies (the connection is closed), we clean up the file descriptor with 'exec 5>&-'. It can be used to test FTP, HTTP, NTP, or can connect to netcat listening on a port (makes for a simple chat client!) Replace /tcp/ with /udp/ to use UDP instead.

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.


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: