Wednesday, December 19, 2012

30 Aliases

Man, I added a bunch of these already: http://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

I also discovered the column command from this, to format things into columns, for instance:

mount | column -t
I also found from the comments on this page that BASH has functions that can be used like aliases:

function f {
 arg_path=$1 && shift
 find $arg_path -wholename "*/path-to-ignore/*" -prune -o $* -print
}
Can be called with
~$ f

Monday, December 17, 2012

Find changes for a subversion commit

In subversion it can be surprisingly difficult to figure out what actually changed for a given revision.

This line will show you the files that were modified for a revision:
svn log -qv -r r101
Compare differences between two versions (show only files changed):
svn diff -r 101:102 --summarize
Where  "r101" is whatever revision you are interested in.

Importing a database (.sql file) into MySQL

No real trick, but I don't do this often enough to remember:

First log in to mysql and create the database named DB-NAME, then run the following from command line:
$ mysql -u root DB-NAME < filename.sql

Thursday, December 13, 2012

Highlighting grep results

Speaking of highlighting, to highlight grep results add "--color".

To preserve the color when piping through less, two things: To grep add "--color=always" and to less add "-R"

I added aliases to .bashrc
alias less='less -R'
alias grep='grep --color=always'

$ grep if *java|less


Colorizing man pages


This is awesome, just stumbled across it at http://www.tuxarena.com/2012/04/tutorial-colored-man-pages-how-it-works/.

Add these lines to .bashrc and man pages take on syntax style highlighting:


export LESS_TERMCAP_mb=$(printf '\e[01;31m') # enter blinking mode - red
export LESS_TERMCAP_md=$(printf '\e[01;35m') # enter double-bright mode - bold, magenta
export LESS_TERMCAP_me=$(printf '\e[0m') # turn off all appearance modes (mb, md, so, us)
export LESS_TERMCAP_se=$(printf '\e[0m') # leave standout mode
export LESS_TERMCAP_so=$(printf '\e[01;33m') # enter standout mode - yellow
export LESS_TERMCAP_ue=$(printf '\e[0m') # leave underline mode
export LESS_TERMCAP_us=$(printf '\e[04;36m') # enter underline mode - cyan
The linked article offers a second color scheme as well.


Monday, December 10, 2012

Revert bad SVN commit

Found this, which works. seems like a strange way to revert to a previous version, but I guess that's how SVN works.
svn merge -r [current_version]:[previous_version] [repository_url]
svn commit -m "Reverting back to revision [previous_version]."
Thought it looks a bit scary, I tried it and it worked.

Thursday, December 6, 2012

Find and delete empty files/folders

Find can find empty files and/or folders and even remove them (scary).

# Find all empty files and/or folders recursively
find -depth  -empty 
# Find all empty folders, only recurse two levels  
find -maxdepth 2 -depth  -empty -type d 
# Delete what you find 
find -maxdepth 2 -depth  -empty -type d  -delete