Commands by bandit36 (3)

  • You can use this to loop any command to periodically see the output. while true; do [YOUR COMMAND HERE]; sleep [# of seconds]; done; Alternatively, you can put it in a simple shell script to save typing! #/!bin/bash while true; do $1; sleep $2; done; /path/to/ "ifconfig eth0 | grep 'inet addr:'" 60 Show Sample Output

    while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done;
    bandit36 · 2009-04-01 19:29:28 8
  • populate the auth.hosts file with a list of IP addresses that are authorized to be in use and when you run this command it will return the addresses that are pingable and not in the authorized list. Can be combined with the "Command line Twitter" command to tweet unauthorized access. Show Sample Output

    diff <(nmap -sP | grep ^Host | sed 's/.appears to be up.//g' | sed 's/Host //g') auth.hosts | sed 's/[0-9][a-z,A-Z][0-9]$//' | sed 's/</UNAUTHORIZED IP -/g'
    bandit36 · 2009-03-12 05:28:08 3
  • This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the "if" & "of" locations. sudo dd if=/media/disk/backup/sda.backup of=/dev/sda Alternatively, you can use an SSH connection to do your backups: dd if=/dev/sda | ssh dd of=~/backup/sda.backup

    sudo dd if=/dev/sda of=/media/disk/backup/sda.backup
    bandit36 · 2009-02-27 20:23:37 2

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

Propagate a directory to another and create symlink to content
Lndir create from source directory to destination directory a full symlink tree of all contents of source directory, really useful for propagate changes from a directory to another.

Get the Volume labels all bitlocker volumes had before being encrypted
Get information of volume labels of bitlocker volumes, even if they are encrypted and locked (no access to filesystem, no password provided). Note that the volume labels can have spaces, but only if you name then before encryption. Renaming a bitlocker partition after being encrypted does not have the same effect as doing it before.

find all open files by named process
lists all files that are opened by processess named $processname egrep 'w.+REG' is to filter out non file listings in lsof, awk to get the filenames, and sort | uniq to remove duplciation

Extract all 404 errors from your apache accesslog (prefix lines by occurrences number)

find the 10 latest (modified) files
order the files by modification (thanks stanishjohnd) time, one file per output line and filter first 10

Nicely display permissions in octal format with filename
Nicely display permissions in octal format and filename for a given directory

Google dictionary of word definitions
$ wget -qO - ",de&client=te" this does the actual google dictionary query, returns a JSON string encapsulated in some fancy tag $ sed 's/dict_api\.callbacks.id100.//' here we remove the tag beginning $ sed 's/,200,null)//' and here the tag end There are also some special characters which could cause problems with some JSON parsers, so if you get some errors, this is probably the case (sed is your friend). I laso like to trim the "webDefinitions" part, because it (sometimes) contains misleading information. $ sed 's/\,\"webDefinitions.*//' (but remember to append a "}" at the end, because the JSON string will be invalid) The output also contains links to mp3 files with pronounciation. As of now, this is only usable in the English language. If you choose other than English, you will only get webDefinitions (which are crap).

Open screen on the previous command
I often find myself wanting to open screen on whatever command I'm currently running. Unfortunately, opening a fresh screen session spawns a new bash session, which doesn't keep my history, so calling screen directly with the previous command is the only way to go.

Get rid from a blank display without reboot
Killall5 will kill your session and redirect to login screen. -Very useful when suffering display problems. -Can use F1-F6 -Need to login in the particular console if not already

oneliner to transfer a directory using ssh and tar
this will tar/send/untrar a whole directory.

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: