Commands by unhammer (9)

  • Assuming you've written all of make -j hfst-tokenize && echo doavtter gr?dakursa|./hfst-tokenize --gtd tokeniser-gramcheck-gt-desc.pmhfst and want that to execute every time you :w in vim (or C-xC-s in Emacs), just hit and it'll turn into while true; do ( make -j hfst-tokenize && e doavtter gr?dakursa|./hfst-tokenize --gtd tokeniser-gramcheck-gt-desc.pmhfst ); inotifywait -q -e modify -e close_write *; done with the cursor right before the ')'. Hit enter, and it'll run on each save. Requires the package inotify-tools installed. Show Sample Output

    echo '"\e\C-i": "\C-awhile true; do ( \C-e ); inotifywait -q -e modify -e close_write *; done\e51\C-b"' >>~/.inputrc
    unhammer · 2016-06-10 08:06:50 0
  • Say you're started "xzcat bigdata.xz | complicated-processing-program >summary" an hour ago, and you of course forgot to enable progress output (you could've just put "awk 'NR%1000==0{print NR>"/dev/stderr"}{print}'" in the pipeline but it's too late for that now). But you really want some idea of how far along your program is. Then you can run the above command to see how many % along xzcat is in reading the file. Note that this is for the GNU/Linux version of lsof; the one found on e.g. Darwin has slightly different output so the awk part may need some tweaks. Show Sample Output

    f=bigdata.xz; calc "round($(lsof -o0 -o "$f"|awk '{o=substr($7,3)}END{print o}')/$(stat -c %s "$f")*100)"
    unhammer · 2015-09-19 18:27:12 4
  • rsync by itself doesn't support copying between two remote hosts, but if you use sshfs you can pretend one of them is local. If you have a passphrase-less ssh-key, you can even put this script into a cron job. A faster alternative is to run ssh-keygen on remote1 and put the pubkey into remote2:~/.ssh/authorized_keys, running rsync on remote1 (or vice versa), but the problem with that is that now a hacker on remote1 can access remote2 at any time. The above method ensures your local computer stays the weak link. Show Sample Output

    mkdir r1 && sshfs remote1:/home/user r1 && rsync r1/stuff remote2:~/backups/
    unhammer · 2013-01-11 14:12:22 0
  • Can't see it here, but the non-breaking space is highlighted :) Of course, cat -t -e achieves something similar, but less colourful. Could add more code points from Show Sample Output

    hl-nonprinting () { local C=$(printf '\033[0;36m') B=$(printf '\033[0;46m') R=$(printf '\033[0m') np=$(env printf "\u00A0\uFEFF"); sed -e "s/\t/${C}▹&$R/g" -e "s/$/${C}⁋$R/" -e "s/[$np]/${B}& $R/g";}
    unhammer · 2012-11-07 10:09:40 1
  • I don't think it's possible to give a (background) colour to the tab itself, since a tab is, IIUC, simply a command to the terminal to move to the right. Nevertheless, this "highlighting" can be helpful when working with tab-separated files. Show Sample Output

    hl-nonprinting () { local C=$(printf '\033[0;36m') R=$(printf '\033[0m'); sed -e "s/\t/${C}▹&$R/g" -e "s/$/${C}⁋$R/";}
    unhammer · 2012-11-07 09:55:48 0
  • Assumes you've cd'd to the folder in which all your git repos reside; you could run it from ~ without -maxdepth, although that might make find take quite a while longer. If you have several processor cores, but not that much ram, you might want to run git config --global pack.threads 1 first, since gc-ing can eat lots of ram. Show Sample Output

    find . -maxdepth 2 -type d -name '.git' -print0 | while read -d ''; do (cd "$REPLY"; git gc); done
    unhammer · 2012-11-07 08:38:33 0
  • basically create a .pot file from a po-file, ready for translating

    msgfilter --keep-header -i input.po -o empty.po awk -e '{}'
    unhammer · 2012-01-14 13:29:26 2
  • This will extract the differing CSS entries of two files. I've left the initial character (plus or space) in output to show the real differing line, remove the initial character to get a working CSS file. The output CSS file is usable by either adding it in a below the to original.css, or by only using the output but adding @import url("original.css"); in the beginning. This is very useful for converting Wordpress theme copies into real Wordpress child themes. Could exclude common lines within entries too, I guess, but that might not be worth the complexity. Show Sample Output

    diff -U99999 original.css modified.css | awk '/^-/{next} {f=f"\n"$0} /^\+.*[^ ]/{yes=1} /}/ {if(yes){print f} f="";yes=0}'
    unhammer · 2012-01-12 07:57:22 1
  • Requires consolekit (works in e.g. Ubuntu). Here x11-display is DISPLAY Show Sample Output

    unhammer · 2012-01-02 08:53:41 0

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

Get a list of IP Addresses that have failed to login via SSH
This command shows a sorted list of the IP addresses from which there have been authentication errors via SSH (possible script kiddies trying to gain access to your server), it eliminates duplicates so it's easier to read, but you can remove the "uniq" command at the end, or even do a "uniq -c" to have a count of how many times each IP address shows in the log (the path to the log may vary from system to system)

Selecting a random file/folder of a folder
Also looks in subfolders

Monitor logs in Linux using Tail
Works in Ubuntu, I hope it will work on all Linux machines. For Unixes, tail should be capable of handling more than one file with '-f' option. This command line simply take log files which are text files, and not ending with a number, and it will continuously monitor those files. Putting one alias in .profile will be more useful.

Recursive cat - concatenate files (filtered by extension) across multiple subdirectories into one file
Useful if you have to put together multiple files into one and they are scattered across subdirectories. For example: You need to combine all .sql files into one .sql file that would be sent to DBAs as a batch script. You do get a warning if you create a file by the same extension as the ones your searching for. find . -type f -name *.sql -exec cat {} > BatchFile.txt \;

Get the current svn branch/tag (Good for PS1/PROMPT_COMMAND cases)
Get the svn info, grep for the "URL" of the repository, pull out the tag/branch/trunk, and then just show the helpful/meaningful bit.

April Fools' Day Prank
Add this to a fiend's .bashrc. PROMPT_COMMAND will run just before a prompt is drawn. RANDOM will be between 0 and 32768; in this case, it'll run about 1/10th of the time. \033 is the escape character. I'll call it \e for short. \e7 -- save cursor position. \e[%d;%dH -- move cursor to absolute position \e[4%dm \e[m -- draw a random color at that point \e8 -- restore position.

Exit mc with 2 keystrokes
For those who like to hit instead of typing "exit" to leave the shell and find it annoying that it doesn't work in Midnight Commander, just press to switch to the subshell and now you can leave with

Get a list of Mageia Linux mirrors providing rsync connectivity for Mageia 4 release
Need to find a Mageia Linux mirror server providing Mageia 4 via rsync? Modify the "url=" string for the version you want. This shows i586 which is the 32bit version. If you want the 64bit version it is: url=; wget -q ${url} -O - | grep rsync:

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Output Detailed Process Tree for any User
An easy function to get a process tree listing (very detailed) for all the processes of any gived user. This function is also in my

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: