Commands by jnash (12)

  • It uses curl --url-encode to encode long URLs *properly* and parses XML with xmlstarlet. If ~/.bitlyrc were to contain login:apikey then a script could read the apiKey and login from ~/.bitlyrc like so: login=$(sed 's/:.*//' < $HOME/.bitlyrc) apikey=$(sed 's/[^:]*://' < $HOME/.bitlyrc) curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line Show Sample Output


    0
    curl -s --data-urlencode 'longUrl='$1 --data-urlencode 'login='$login --data-urlencode 'apiKey='$apikey 'http://api.bit.ly/shorten?version=2.0.1&format=xml' | xmlstarlet sel -T -t -m "//shortUrl" -v "." | line
    jnash · 2010-01-02 11:32:42 3
  • If you are behind a restrictive proxy/firewall that blocks port 22 connections but allows SSL on 443 (like most do) then you can still push changes to your github repository. Your .ssh/config file should contain: Host * ForwardX11 no TCPKeepAlive yes ProtocolKeepAlives 30 ProxyCommand /usr/local/bin/proxytunnel -v -p -d %h:443 Host User git Hostname ssh.github.com ChallengeResponseAuthentication yes IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes Basically proxytunnel "tunnels" your ssh connection through port 443. You could also use corkscrew or some other tunneling program that is available in your distro's repository. PS: I generally use "github.com" as the SSH-HOST so that urls of the kind git@github.com:USER/REPO.git work transparently :) You


    3
    git remote add origin git@SSH-HOST:<USER>/<REPOSITORY>.git
    jnash · 2009-11-19 06:57:50 8
  • I know this has been beaten to death but finding video files using mime types and printing the "hours of video" for each directory is (IMHO) easier to parse than just a single total. Output is in minutes. Among the other niceties is that it omits printing of non-video files/folders PS: Barely managed to fit it within the 255 character limit :D Show Sample Output


    0
    for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$'
    jnash · 2009-11-19 06:28:15 3
  • Uses mime-type of files rather than relying on file extensions to find files of a certain type. This can obviously be extended to finding files of any other type as well.. like plain text files, audio, etc.. In reference to displaying the total hours of video (which was earlier posted in command line fu, but relied on the user having to supply all possible video file formats) we can now do better: find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'


    1
    find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1
    jnash · 2009-11-19 06:05:36 6
  • enlubtsqyuse cat /tmp/out subsequently Show Sample Output


    1
    shuf -n1 /usr/share/dict/words | tee >(sed -e 's/./&\n/g' | shuf | tr -d '\n' | line) > /tmp/out
    jnash · 2009-04-05 05:29:06 7
  • Does that count as a win for bzip2? Show Sample Output


    -2
    < /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
    jnash · 2009-04-04 13:23:01 11
  • Are there any creative pieces of music that can be created using beep and the shell? I'd love to hear it!


    5
    man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
    jnash · 2009-04-01 06:48:48 10
  • http://en.wikipedia.org/wiki/Year_2038_problem Some other notable dates that have passed: date -d@1234567890 date -d@1000000000 Show Sample Output


    1
    date -d @$(echo $((2 ** 31 - 1)))
    jnash · 2009-03-30 19:42:20 4
  • Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage. This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed. find -L ./ -type l -delete And then removing empty directories find ./ -type d -exec rmdir 2>/dev/null {} \; **Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)


    0
    find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
    jnash · 2009-03-29 09:25:12 23
  • Might be more useful if you were able to print it in Days HH:MM:SS format as: perl -e '@p=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);' But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)


    0
    watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
    jnash · 2009-03-29 06:53:09 9
  • Python comments begin with a #. Modify to suit other languages. Other uses: Instead of m0 use m$ for end of file or d for deleting all comments.


    4
    :g:^\s*#.*:m0
    jnash · 2009-03-27 18:56:36 12
  • Extensible to other ugly extensions like *.JPG, *.Jpg etc.. Leave out the last pipe to sh to perform a dry run.


    -1
    find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
    jnash · 2009-03-27 13:42:40 11

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

Create Encrypted WordPress MySQL Backup without any DB details, just the wp-config.php
The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info. I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function.

set wallpaper on windowmaker in one line
set directly the wallpaper on windowmaker , use this command with display of imagemagick :)

Give to anyone a command to immediatly find a particular part of a man.
Example : $ LC_ALL=C man less | less +/ppattern

Unlock your KDE4 session remotely (for boxes locked by KDE lock utility)
Do the unlock KDE screen saver locked session with lightdm display manager used in Kubuntu 12.10 +

Decrypt passwords from Google Chrome and Chromium.
Read this before you down voting and comment that it is not working -> Wont work on latest versions ~75> since database file is locked and has to be decrypted. This is useful if you have an old hdd with a chrome installation and want to decrypt your old passwords fast.

Simultaneously running different Firefox profiles
After running $ firefox -ProfileManager and creating several different profiles, use this command to run multiple Firefox profiles simultaneously.

Prints new content of files
Useful to e.g. keep an eye on several logfiles.

Shorten any Url using bit.ly API, using your API Key which enables you to Track Clicks
Shorten any Url using bit.ly API, using your API Key which enables you to Track Clicks I have it as a Function in my .bash_aliases [code] shorten () { longUrl=$1; curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=LONG_URL_YOU_WANT_SHORTENED&login=rungss&apiKey=" } [/code] Here is an Output showing the Function Detail.. [konsole] bijay@bijay:$ type shorten shorten is a function shorten () { longUrl=$1; curl "http://api.bit.ly/shorten?version=2.0.1&longUrl=$longUrl&login=rungss&apiKey=R_48d7e0b40835b09e3861bd455f7abec7" } [/konsole]

scping files with streamlines compression (tar gzip)
it compresses the files and folders to stdout, secure copies it to the server's stdin and runs tar there to extract the input and output to whatever destination using -C. if you emit "-C /destination", it will extract it to the home folder of the user, much like `scp file user@server:`. the "v" in the tar command can be removed for no verbosity.

convert wav into mp3 using lame


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: