Commands by pingiun (1)

  • First the find command finds all files in your current directory (.). This is piped to xargs to be able to run the next shell pipeline in parallel. The xargs -P argument specifies how many processes you want to run in parallel, you can set this higher than your core count as the duration reading is mainly IO bound. The -print0 and -0 arguments of find and xargs respectively are used to easily handle files with spaces or other special characters. A subshell is executed by xargs to have a shell pipeline for each file that is found by find. This pipeline extracts the duration and converts it to a format easily parsed by awk. ffmpeg reads the file and prints a lot of information about it, grep extracts the duration line. cut and sed cut out the time information, and tr converts the last . to a : to make it easier to split by awk. awk is a specialized programming language for use in shell scripts. Here we use it to split the time elements in 4 variables and add them up. Show Sample Output

    find . -print0 | xargs -0 -P 40 -n 1 sh -c 'ffmpeg -i "$1" 2>&1 | grep "Duration:" | cut -d " " -f 4 | sed "s/.$//" | tr "." ":"' - | awk -F ':' '{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4 } END { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 }'
    pingiun · 2019-03-01 20:21:48 3

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

Show the power of the home row on the Dvorak Keyboard layout
Quick and dirty command that counts how many words can be typed just using the home row on the Dvorak Simplified Keyboard layout from a dictionary file, in this case /usr/share/dict/words. According to the regular expression supplied, each word must contain all the keys on the Dvorak home row, and no other characters. For comparison, I've shown how many words are installed in my dictionary, how many can be typed with just the Dvorak home row and how many can be typed with just the QWERTY home row in the sample output. Nearly 10 times the amount. If you want to see the words, remove the -c switch, and each word will be printed out.

unrar all part1 files in a directory

Rips CDs (Playstation, etc.) and names the files the same as the volume name

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Ext3 format Terabytes in Seconds

Exclude inserting a table from a sql import
Starting with a large MySQL dump file (*.sql) remove any lines that have inserts for the specified table. Sometimes one or two tables are very large and uneeded, eg. log tables. To exclude multiple tables you can get fancy with sed, or just run the command again on subsequently generated files.

Use all the cores or CPUs when compiling
Force make command to create as many compile processes as specified (4 in the example), so that each one goes into one core or CPU and compilation happens in parallel. This reduces the time required to compile a program by up to a half in the case of CPUs with 2 cores, one fourth in the case of quad cores... and so on.

ssh and attach to a screen in one line.
If you know the benefits of screen, then this might come in handy for you. Instead of ssh'ing into a machine and then running a screen command, this can all be done on one line instead. Just have the person on the machine your ssh'ing into run something like $ screen -S debug Then you would run $ ssh -t [email protected] screen -x debug and be attached to the same screen session.

Get IPv4 of eth0 for use with scripts
I've been using it in a script to build from scratch proxy servers.

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: