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

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Create a mirror of a local folder, on a remote server
Create a exact mirror of the local folder "/root/files", on remote server 'remote_server' using SSH command (listening on port 22) (all files & folders on destination server/folder will be deleted)

Remove ( color / special / escape / ANSI ) codes, from text, with sed
Remove ( color / special / escape / ANSI ) codes, from text, with sed Credit to the original folks who I've copied this command from. The diff here is: Theirs: [m|K] Theirs is supposed to remove \E[NUMBERS;NUMBERS[m OR K] This statement is incorrect in 2 ways. 1. The letters m and K are two of more than 20+ possible letters that can end these sequences. 2. Inside []'s , OR is already assumed, so they are also looking for sequences ending with | which is not correct. This : [a-zA-Z] This resolves the "OR" issue noted above, and takes care of all sequences, as they all end with a lower or upper cased letter. This ensures 100% of any escape code 'mess' is removed.

Remove everything except that file
Remove everything except that file with shell tricks inside a subshell to avoid changes in the environment. $ help shopt

Find the package that installed a command

Probably, most frequent use of diff
This form is used in patches, svn, git etc. And I've created an alias for it: alias diff='diff -Naur --strip-trailing-cr' The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like $ svn diff --diff-cmd 'diff --strip-trailing-cr'...

Insert the last argument of the previous command

random xkcd comic as xml

Deleting Files from svn which are missing

disable caps lock
a quick one-line way to disable caps lock while running X.

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: