Something I do a lot is extract columns from some input where cut is not suitable because the columns are separated by not a single character but multiple spaces or tabs. So I often do things like: ... | awk '{print $7, $8}' ... which is a lot of typing, additionally slowed down when typing symbols like '{}$ ... Using the simple one-line function above makes it easier and faster: ... | col 7 8 How it works: The one-liner defines a new function with name col The function will execute awk, and it expects standard input (coming from a pipe or input redirection) The function arguments are processed with sed to use them with awk: replace all spaces with ,$ so that for example 1 2 3 becomes 1,$2,$3, which is inserted into the awk command to become the well formatted shell command: awk '{print $1,$2,$3}' Allows negative indexes to extract columns relative to the end of the line. Credit: http://www.bashoneliners.com/oneliners/oneliner/144/ Show Sample Output
Show If Someone Is Connected To The Android Device On And Get Their IP Address
Original command: cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100 This is a waste of multiple cats and greps, esp when awk is being used
The AWK part of the code will "collate" the fields from 2nd to Nth field (this is to handle any svn directories that may have spaces in them - typical when working with code that is interchangeably used with windows environment - for example, documentation teams) - the output is passed to "ls -ld" - the -d option to ls will tell ls to handle directories itself, rather than do ls on the directory. The '-p' option is just for pretty printing directories, links and executables (for added readability). Finally, the entire "constructed" command will be passed onto sh for shell execution. Show Sample Output
Accepts multiple files via logs...
. Substitute "text to grep" for your search string.
If you want to alias this, you could do something like this:
alias parse-logs='awk "/$1/{print \$1}" ${@[@]:1} | sort -n | uniq -c | sort -rn | head -n 100'
Replace "APIKEY" with your public apikey Show Sample Output
I just use this to see my ip on the server I'm working on Show Sample Output
Gets the Hardware UUID of the current machine using system_profiler. Show Sample Output
Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative.
Recently in Debian Wheezy the dpkg command refuses to work with wildcards, so this is the one-liner alternative. (alternative to #13614)
Great for moves, re-installs etc since it is not version specific yet is architecture specific. Centos yum list is well know for wrapping lines . Show Sample Output
Downloads a CRL file, determines the expiration time, and checks when it will expire Show Sample Output
This command makes a small graph with the histogram of size blocks (5MB in this example), not individual files. Fine tune the 4+5*int($1/5) block for your own size jumps : jump-1+jump*($1/jump) Also in the hist=hist-5 part, tune for bigger or smaller graphs Show Sample Output
Thx Mass1 for the sharing
Reduced to only one command. :)
Caution: distructive overwrite of filenames Useful for concatenating pdfs in date order using pdftk
Monitoring system in one line : DISK : disk space MEM: memory ( mem , swap, Total) CPU : all information about cpu activity LOAD : load average Show Sample Output
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.
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
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: