Commands by Zath (2)

  • Improved google text-to-speech function. Allows to specify language, plays sound in terminal. Automatically removes downloaded file after successfully processing. Usage: say LANGUAGE TEXT Examples: say en "This is a test." say pl "To jest test"


    2
    function say { wget -q -U Mozilla -O google-tts.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=$1&q=$2" open google-tts.mp3 &>/dev/null || mplayer google-tts.mp3 &>/dev/null; rm google-tts.mp3; }
    Zath · 2014-08-01 23:43:16 17
  • Change current working directory with root permissions. Place this snippet in your .bashrc to add a new "sudocd" command: function sudocd { sudo bash -c "cd $1;bash" } Usage: sudocd DIRECTORY Please note that if you will use this command to cd into directories with the permissions allowing only root to be in them, you will have to use sudo as a prefix to every command that changes/does something in that directory (yes, even ls).


    0
    sudo bash -c "cd /PATH/TO/THE/DIRECTORY;bash"
    Zath · 2014-07-28 20:20:04 37

What's this?

commandlinefu.com 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 a file in less without wrapping long lines

Add Password Protection to a file your editing in vim.
While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format. For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption

Multi line grep using sed and specifying open/close tags
This line does not include your closing tag in the output.

Kill multiple instances of a running process

Display a block of text: multi-line grep with perl
-n reads input, line by line, in a loop sending to $_ Equivalent to while () { mycode } -e execute the following quoted string (i.e. do the following on the same line as the perl command) the elipses .. operator behaves like a range, remembering the state from line to line.

Convert PDF to JPEG using Ghostscript
Converting your PDF file to JPEG images. You can set resolution by -r option (default: 72dpi).

run a command whenever a file is touched
This is useful if you'd like to see the output of a script while you edit it. Each time you save the file the command is executed. I thought for sure something like this already exists - and it probably does. I'm on an older system and tend to be missing some useful things. Examples: $ ontouchdo yourscript 'clear; yourscript somefiletoparse' Edit yourscript in a separate window and see new results each time you save. $ ontouchdo crufty.html 'clear; xmllint --noout crufty.html 2>&1 | head' Keep editing krufty.html until the xmllint window is empty. Note: Mac/bsd users should use stat -f%m. If you don't have stat, you can use perl -e '$f=shift; @s=stat($f); print "$s[9]\n";' $1

Run a long job and notify me when it's finished
You will need libnotify-bin for this to work: $ sudo aptitude install libnotify-bin

Runs a command without hangups.
puts command in background and sends its output to nohup.out file it will not die if you log out fromyour shell session ;-)

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" }


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: