Broaden your knowledge of the utilities available to you in no particular order whatsoever! Then use that knowledge to create more nifty one-liners that you can post here. =p Takes a random number modulo the number of files in $dir, prints the filename corresponding to that number, and passes it as an argument to man.
BASH: Print shell variable into AWK
This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines. Show Sample Output
This will, for an application that has already been removed but had its configuration left behind, purge that configuration from the system. To test it out first, you can remove the last -y, and it will show you what it will purge without actually doing it. I mean it never hurts to check first, "just in case." ;)
I use this command to select a random movie from my movie collection.. Show Sample Output
After this command you can review doit.sh file before executing it. If it looks good, execute: `. doit.sh`
Useful for removes a package and its depends, for example to remove the gnome desktop environment, also configuration files will be removed, you should be carefully and sure that you want to do this. Show Sample Output
This command might not be useful for most of us, I just wanted to share it to show power of command line. Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination. This command removes numbers and single characters from count. I'm sure you can write a shorter version. Show Sample Output
Build an awk array with all commands and then select a random one at the end. This avoids spawning extra processes for counting with wc or generating random numbers. Explicitly call /bin/ls to avoid interactions with aliases.
Quick and dirty one-liner to get the average ping(1) time from a server. Show Sample Output
Ok so it's rellay useless line and I sorry for that, furthermore that's nothing optimized at all... At the beginning I didn't managed by using netstat -p to print out which process was handling that open port 4444, I realize at the end I was not root and security restrictions applied ;p It's nevertheless a (good ?) way to see how ps(tree) works, as it acts exactly the same way by reading in /proc So for a specific port, this line returns the calling command line of every thread that handle the associated socket
only take the first field on each row to compute the fibo on this number Show Sample Output
Tail is much faster than sed, awk because it doesn't check for regular expressions. Show Sample Output
the f is for file and - stdout, This way little shorter. I Like copy-directory function It does the job but looks like SH**, and this doesn't understand folders with whitespaces and can only handle full path, but otherwise fine, function copy-directory () { ; FrDir="$(echo $1 | sed 's:/: :g' | awk '/ / {print $NF}')" ; SiZe="$(du -sb $1 | awk '{print $1}')" ; (cd $1 ; cd .. ; tar c $FrDir/ )|pv -s $SiZe|(cd $2 ; tar x ) ; } Show Sample Output
( IFS=:; for i in $PATH; do echo $i; done; ) echo $PATH|sed -e 's/:/\n/g' # but the tr one is even better of course echo $PATH|xargs -d: -i echo {} # but this comes up with an extra blank line; can't figure out why and don't have the time :( echo $PATH|cut -d: --output-delimiter=' ' -f1-99 # note -- you have to hit ENTER after the first QUOTE, then type the second one. Sneaky, huh? echo $PATH | perl -l -0x3a -pe 1 # same darn extra new line; again no time to investigate echo $PATH|perl -pe 's/:/\n/g' # too obvious; clearly I'm running out of ideas :-)
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: