Monday, August 2, 2010

View output in console and write to file using tee - Mac OS X 10.6.4

Use tee to send output to the console and to a file:

machine:dir user$ ./some_program | tee output_file.txt

Executing the above command will display the output of some_program immediately in the console and write the same contents to output_file.txt.

I use this command mostly for diffs against svn, saves a step. Also, though I'm posting this as a Mac OS X terminal option, I first discovered this on Ubuntu 8.04 though I sure the history or this command is much older. I recall from the documentation to think of this in plumbing terms: Send your output down a pipe to a "T" essentially sending the same stream/flow to two different places.

~Fin

Friday, January 15, 2010

Recursive SVN Directory Removal - Ubuntu 9.10 Karmic

From time to time it can be handy to remove subversion references from code that is sitting on the file system. The following command will remove all '.svn' directories from the current directory on down:

user@machine:~/dev/sample1$ rm -rf `find . -type d -name .svn`

(Please note those are grave accent quotes - below the tilde on the key left of the one(1) key.)

This command should work for all flavours of Unix.

~Fin

Tuesday, January 12, 2010

Create a symbolic link - Ubuntu 9.10 Karmic

ln -s /path/to/real/file /path/to/non-existant/file

So you could do like:

user@machine:~/devtools/jdk$ ll
drwxr-xr-x 10 root root 4096 2010-01-12 11:11 jdk-1.6.0
user@machine:~/devtools/jdk$ ln -s jdk-1.6.0/ current
user@machine:~/devtools/jdk$ ll
lrwxrwxrwx 1 brad brad 10 2010-01-12 11:25 current -> jdk-1.6.0/
drwxr-xr-x 10 root root 4096 2010-01-12 11:11 jdk-1.6.0
user@machine:~/devtools/jdk$

~Fin

Wednesday, October 28, 2009

Start, stop, restart MySql - Ubuntu 9.04 Jaunty

user@machine:~$ sudo /etc/init.d/mysql [start, stop, restart]

~Fin

Monday, October 26, 2009

Reset root password for MySql 5.* - Ubuntu 9.04 Jaunty

user@computer:~$ sudo dpkg-reconfigure mysql-server-5.0

This will pop a "dialog" in your terminal and advise you to set a root password. Verify, tab to <OK> and try logging in again:

user@computer:~$ mysql -uroot -p<password_you_just_set>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.0.75-0ubuntu10.2 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>


~Fin

Thursday, October 22, 2009

Using Tabs in the terminal - Ubuntu 9.04 Jaunty

Using tabs in the terminal to avoid having several terminals opens saves space and time (how did I not know about this earlier!).

Open a terminal and create a new tab using:

<shift> + <ctrl> + T

To switch between tabs using the keyboard:

<ctrl> + <page down>
(Moves one tab right - will loop through all tabs from left to right.)

<ctrl> + <page up>
(Moves one tab left - will loop through all tabs from right to left.)

~Fin

shred a File - Ubuntu 9.04 Jaunty

Computer files containing sensitive information should also be 'shredded'. There is a command line utility on Linux systems called 'shred' that overwrites the file multiple times with random output. If you simply erase a file with 'rm', this only tells the operating system that this part of your hard disk is free for use, but the information still exists until that space is overwritten. Information from a file that has been deleted can still be recovered unless it has been 'shred', making it nearly impossible to recover.

The following command will shred a file, "zero" it (to hide shredding) and then remove it.

user@machine:~$ shred -zuv sensative.file

~Fin