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

Friday, November 30, 2012

Arbitrary screen capture in KDE


A nice post at floatingsun, explains how to get screen capture functionality in KDE similar to what you get with the Compiz screenshot plugin. Basically you set up shortcut and have it run the previously unknown to me application
kbackgroundsnapshot -region 

If you copy and paste from the linked website you will need to replace the hyphen with a "minus sign". Anyway, this command lets you select any screen region and puts a .png on your desktop.

In arch I had to install the kdegraphics-ksnapshot package.

It also locked up on me when I tried to press escape to exit without selecting anything, I had to CTRL+ALT+F1 and kill it from command line.

But that's one of the key things I've been missing from Compiz.

Monday, November 26, 2012

Sorting "find" results by date

I have been meaning to look this up for a while now. Sometimes I save a file, but I'm not sure in which folder. I use "ls -ltrh" all the time to sort contents of a folder by reverse time so the most recently modified items appear at the bottom (very useful example is ls -ltrh /var/log to find most recently modified log files).

The following command will use the results of  the find command to do the same thing over multiple folders. Its too complex to type all the time, so I put it in a script in my personal script folder. Another good idea would be to alias it.


    find . -type f -printf '%T@ %p\n' | sort -k 1nr | sed 's/^[^ ]* //' | head -n 10

This example shows only the 10 most recent files (head -n 10) and doesn't filter filenames in any way. It also only examines normal files, not folders or other.

MPRIS players in KDE


I've switched to Arch Linux and a KDE desktop. I love cairo-dock/compiz but it seems like its hard to get compiz to work consistently any more due to gnome etc... loading their own compositing tools that keep trying to take control.

So far I like Arch a lot, and I'm surprised to find that applications tend to run significantly quicker and use less RAM. Notably Windows in VirtualBox and Office 2010 under WINE which were both pretty slug like in Ubuntu.

Anyway, one of the issues is getting the play/pause button on my keyboard to work with Pithos, its assigned only for Amarok by default under KDE. This post gives a method of creating scripts for play/pause, stop, next, previous and reassigning multimedia keys to run them.

Sunday, November 25, 2012

Kile's 1024 character line limit

For some reason Kile (and Kate?)has a configurable line length limit.
When editing .tex documents its easy to exceed the default of 1024 characters and if you open a file with lines longer than the default it gives an error and sets the document to read only.

Go into settings->Configure Kile and select Editor->Open/Save set the line length limit to 0 and there will be no limit.

Wednesday, November 14, 2012

Maximize Minimize button discovery

I just found something by accident after all these years (well it may be a new feature...).

Right clicking on the maximize button maximizes a window only in the width direction.
Middle click maximizes in only the height direction.
Clicking either a second time restores back to original.

Tuesday, November 13, 2012

Using the script command

For years I've wondered why the script command gives no output in Ubuntu. I still don't know the answer, but I just found that by using the "-q" option it works!

-q is supposed to be for "quiet" mode, which I guess turns off the little messages like "script started". But it causes script to actually produce a script.
$ script -q <filename>