Commands by pcholt (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

Apply, in parallel, a bc expression to CSV
Define a function that applies bc, the *nix calculator, with the specified expression to all rows of the input CSV. The first column is mapped to {1}, second one to {2}, and so forth. See sample output for an example. This function uses all available cores thanks to GNU Parallel. Requires GNU Parallel

Find brute force attempts on SSHd
Searches the /var/log/secure log file for Failed and/or invalid user log in attempts.

Get duration of an audio file in seconds.
This is an alternative to #9131. ffmpeg didn't work on my .au files, though it did on the .wav ones. Also useful if you don't have ffmpeg but do have sox. Handily, sox already reports in seconds (decimal).

Print permanent subtitles on a video
It prints subtitle files in myvideo.avi, saving it in myvideo_subtitled.avi

Convert JSON to YAML (unicode safe)
If you tried the other Python version of Convert JSON to YAML and you end up with lines that has "!!python/unicode", this version of the command is for you.

Install pip with Proxy
Installs pip packages defining a proxy

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Watch the progress of 'dd'
The previously-posted one-liner didn't work for me for whatever reason, so I ended up doing this instead.

Randomize lines in a file
Works in sort (GNU coreutils) 7.4, don't know when it was implemented but sometime the last 6 years.

format txt as table not joining empty columns
-n switch keeps empty columns If your distribution does not ship with a recent column version that supports -n you can use this alternative: perl -pe 's/(^|;);/$1 ;/g' file.csv | column -ts\; | less -S Change the delimiter to your liking.

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: