Commands by IF_Rock (3)

  • Sorts blank line delimited paragraphs. '-i' -- case insensitivity option -- removes redundant paragraphs in a case insensitive way, and then sorts in a case insensitive way. If you search CommandLineFu with multiple anded terms searches, redundancy can ensue. This sorts the retrieved text (among other kinds of data), and removes the redundancy. Show Sample Output


    0
    gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i")IGNORECASE=1;ARGC=1}{if (IGNORECASE)Text[tolower($0)]=$0;else Text[$0]=$0 };END {N=asort(Text);for(i=1;i<=N;i++)printf "%s\n\n",Text[i]}' -i<Test.txt
    IF_Rock · 2011-05-11 01:03:30 3
  • Among other things, this allows the sorting of comment descriptions and command lines retrieved as text from CommandLineFu.com. Show Sample Output


    0
    gawk 'BEGIN {RS="\n\n"; if (ARGV[1]=="-i"){IGNORECASE=1; ARGC=1}};{Text[NR]=$0};END {asort(Text);for (i=1;i<=NR;i++) printf "%s\n\n",Text[i] }' -i<Zip.txt
    IF_Rock · 2011-05-10 19:08:27 5
  • { ... } vs ( ... ) reduces the process count, I believe. Typically, I use this logic to redirect a series of commands to a pipe -- { command1 args1 ; command2 args2}|less -- or file -- { command1 args1 ; command2 args2}>foo -- or to spawn the series as a background process -- { ... } & .


    0
    { command1 args1 ; command2 args2 ; ... }
    IF_Rock · 2011-04-12 20:01:51 3

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

save date and time for each command in history
Date-time format: YYYY-MM-DD HH:MM:SS

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

create a simple version of ls with extended output
create a short alias for 'ls' with multi-column (-C), file type syntax additions (slashes after directories, @ for symlinks, etc... (-F), long format (-l), including hidden directories (all ./, ../, .svn, etc) (-a), show file-system blocks actually in use (-s), human readable file sizes (-h)

List detailed information about a ZIP archive
list zipfile info in long Unix ``ls -l'' format.

Recursively remove .svn directories from the current location

check open ports without netstat or lsof

Create a zip file ignoring .svn files

Launch firefox on a remote linux server
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)

list directories only

Monitor open connections for httpd including listen, count and sort it per IP
It's not my code, but I found it useful to know how many open connections per request I have on a machine to debug connections without opening another http connection for it. You can also decide to sort things out differently then the way it appears in here.


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: