Commands by KoRoVaMiLK (9)

  • These are my favourite switches on pwgen: -B Don't include ambiguous characters in the password -n Include at least one number in the password -y Include at least one special symbol in the password -c Include at least one capital letter in the password It just works! Add a number to set password length, add another to set how many password to output. Example: pwgen -Bnyc 12 20 this will output 20 password of 12 chars length. Show Sample Output


    5
    pwgen -Bnyc
    KoRoVaMiLK · 2012-03-15 14:38:15 4
  • Used to verify if Network Time Protocol daemon is working properly. Show Sample Output


    4
    ntpq -p
    KoRoVaMiLK · 2010-09-14 07:39:20 4
  • Shows useful informations about file descriptors in Squid web proxy Show Sample Output


    -1
    squidclient mgr:info | grep "file desc"
    KoRoVaMiLK · 2010-07-29 17:35:20 4
  • On-the-fly conversion of Unix Time to human-readable in Squid's access.log Show Sample Output


    1
    perl -p -e 's/^([0-9]*)/"[".localtime($1)."]"/e' < /var/log/squid/access.log
    KoRoVaMiLK · 2010-06-22 08:42:40 4
  • Actually 'firefox' is a script that then launches the 'firefox-bin' executable. You need to specify the 'no-remote' option in order to launch remote firefox instead of your local one (this drove me crazy time ago)


    5
    ssh -fY user@REMOTESERVER firefox -no-remote
    KoRoVaMiLK · 2010-06-03 07:24:07 5
  • Useful since "export http_proxy=blahblah:8080" doesn't seem to work with pear Show Sample Output


    -1
    pear config-set http_proxy http://myusername:mypassword@corporateproxy:8080
    KoRoVaMiLK · 2010-05-13 14:44:03 30
  • Simple way to backup your LDAP entries: put this line on your crontab. The -n switch identifies the dbnum you want to backup (alternatively you can use -b suffix. Check man slapcat for your personal switches)


    1
    slapcat -n 1 > /backup/`date "+%Y%m%d"`.ldif
    KoRoVaMiLK · 2010-05-07 15:52:39 6
  • Prints current runlevel and system start time. On older systems it also shows the last init state. Pretty useful on remote systems, pretty useless on local ones :) Show Sample Output


    5
    who -r
    KoRoVaMiLK · 2010-05-05 12:58:09 4
  • This allows you to skip the banner (usually /etc/issue.net) on ssh connections. Useful to avoid banners outputted to your mail by rsync cronjobs.


    1
    ssh -q user@server
    KoRoVaMiLK · 2010-03-24 12:02:55 4

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

back up your commandlinefu contributed commands
Use `zless` to read the content of your *rss.gz file: $ zless commandlinefu-contribs-backup-2009-08-10-07.40.39.rss.gz

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

Let's make screen and ssh-agent friends
When you start screen as `ssh-agent screen`, agent will die after detatch. If you don't want to take care about files when stored agent's pid/socket/etc, you have to use this command.

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"

Find the package that installed a command

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

Get the size of all the directories in current directory (Sorted Human Readable)
This allows the output to be sorted from largest to smallest in human readable format.

Remove spaces from filenames - through a whole directory tree.
An example of zsh glob qualifiers.

Recursively grep for string and format output for vi(m)
This is a big time saver for me. I often grep source code and need to edit the findings. A single highlight of the mouse and middle mouse click (in gnome terminal) and I'm editing the exact line I just found. The color highlighting helps interpret the data.

Unite pdf files
pdfunite is a part of the poppler-utils. poppler-utils package is only 150KB. The alternative - pdftk package is 14MB! Install poppler-utils if you need simple pdf operation commands like unite, separate, info, text/html conversions


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: