Particularly useful if you're mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting. Show Sample Output
-n switch keeps empty columns If your distribution does not ship with a recent column version that supports -n you can use this alternative: perl -pe 's/(^|;);/$1 ;/g' file.csv | column -ts\; | less -S Change the delimiter to your liking.
If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command.
# creating a date-based ssh-key for askapache.github.com
ssh-keygen -f ~/.ssh/`date +git-$USER@$HOSTNAME-%m-%d-%g` -C 'webmaster@askapache.com'
# /home/gpl/.ssh/git-gplnet@askapache.github.com-04-22-10
# create a tar+gzip backup of the current directory
tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g' <<< $PWD`.tgz) .
# tar -czf /home/gpl/.backups/04-22-10-01:13-#home#gpl#.rr#src.tgz .
I personally find myself having to reference
date --help
quite a bit as a result. So this nice alias saves me a lot of time. This is one bdash mofo. Works in sh and bash (posix), but will likely need to be changed for other shells due to the parameter substitution going on.. Just extend the sed command, I prefer sed to pretty much everything anyways.. but it's always preferable to put in the extra effort to go for as much builtin use as you can. Otherwise it's not a top one-liner, it's a lazyboy recliner.
Here's the old version:
alias dateh='date --help|sed "/^ *%%/,/^ *%Z/!d;s/ \+/ /g"|while read l;do date "+ %${l/% */}_${l/% */}_${l#* }";done|column -s_ -t'
This trick from my [ http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html bash_profile ]
Show Sample Output
-P uses the POSIX output format, which makes information on each file system always printed on exactly one line. "column -t" makes a table from the input. Show Sample Output
Splits the input based on commas and prints it in a nice column format. This would not work for CSV rows that have "," between quotes or with newline characters. Use only simple simple csv files. Show Sample Output
since fuse mounts do not appear in /etc/mtab (fuse can't write there, dunno if it would if it could) this is propably a better way.
I like the other three versions but one uses nested loops and another prints every color on a separate line. Both versions fail to reset colors before giving the prompt back. This version uses the column command to print a table so all the colors fit on one screen. It also resets colors back to normal before as a last step.
The -W switch of netstat makes it print complete URL of the connections, which otherwise by default is truncated to fit its default column size. Now to compensate for irregular column sizes, pipe the output to column (-t switch of column prints in tabular form). The only downside to this part is that the very first row, the header, goes pear shape. Show Sample Output
Prints out an ascii chart using builtin bash! Then formats using cat -t and column.
The best part is:
echo -e "${p: -3} \\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))";
From: http://www.askapache.com/linux/ascii-codes-and-reference.html
Show Sample Output
ifconfig can't properly display interface's name longer 9 symbols,also it can't show IPs added thru ip command, so 'ip' should be used instead. This alias properly shows long names, bond interfaces and all interface aliases. loopback interface is ignored, since its IP is obvious Show Sample Output
This one-liner will output installed packages sorted by size in Kilobytes. Show Sample Output
The multiplication table for math study Show Sample Output
Using the --table-truncate ( -T ) option, you can specify the columns you will allow to be truncated. This helps when you have some columns that are unusually long, or a small terminal window. In this example we will print out the /etc/passwd file in columns. We are using a colon as our separator ( -s: ), defining that we want table output ( -t ), defining the column names ( -N ) and allowing the column NAME to be truncated ( -T ). Show Sample Output
Using column to format a directory listing Show Sample Output
Prints a log of phonecalls placed from/to an asterisk server, formated into an easily readable table. You can use partial number/queue matches, or use .* to match everything. Show Sample Output
Once you get into advanced/optimized scripts, functions, or cli usage, you will use the sort command alot. The options are difficult to master/memorize however, and when you use sort commands as much as I do (some examples below), it's useful to have the help available with a simple alias. I love this alias as I never seem to remember all the options for sort, and I use sort like crazy (much better than uniq for example).
# Sorts by file permissions
find . -maxdepth 1 -printf '%.5m %10M %p\n' | sort -k1 -r -g -bS 20%
00761 drwxrw---x ./tmp
00755 drwxr-xr-x .
00701 drwx-----x ./askapache-m
00644 -rw-r--r-- ./.htaccess
# Shows uniq history fast
history 1000 | sed 's/^[0-9 ]*//' | sort -fubdS 50%
exec bash -lxv
export TERM=putty-256color
Taken from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Show Sample Output
This shows every bit of information that stat can get for any file, dir, fifo, etc. It's great because it also shows the format and explains it for each format option.
If you just want stat help, create this handy alias 'stath' to display all format options with explanations.
alias stath="stat --h|sed '/Th/,/NO/!d;/%/!d'"
To display on 2 lines:
( F=/etc/screenrc N=c IFS=$'\n'; for L in $(sed 's/%Z./%Z\n/'<<<`stat --h|sed -n '/^ *%/s/^ *%\(.\).*$/\1:%\1/p'`); do G=$(echo "stat -$N '$L' \"$F\""); eval $G; N=fc;done; )
For a similarly powerful stat-like function optimized for pretty output (and can sort by any field), check out the "lll" function
http://www.commandlinefu.com/commands/view/5815/advanced-ls-output-using-find-for-formattedsortable-file-stat-info
From my .bash_profile ->
http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Show Sample Output
Just an alternative with more advanced formating for readability purpose. It now uses colors (too much for me but it's a kind of proof-of-concept), and adjust columns. Show Sample Output
Spits out table that shows your Host->HostName aliases in ~/.ssh/config
This command could seem pretty pointless especially when you can get the same result more easily using the rpm builtin queryformat, like:
rpm -qa --qf "%{NAME} %{VERSION} %{RELEASE}.%{ARCH}\n" | sort | column -t
but nonetheless I've learned that sometimes it can be quite interesting trying to explore alternative ways to accomplish the same task (as Perl folks like to say: There's more than one way to do it!)
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: