Too often I figure out how to do this or that on Linux systems and in my haste to complete whatever task I've been assigned this "How To" knowledge gets lost. So here, I will begin posting little odds and ends in hopes of not needing to re-research past efforts for Linux tips, tricks, hacks, and other good to know things. If you find yourself here and know of smaller, faster, better ways of doing any of this please let me know - only through cooperation can we all get better.
Wednesday, October 28, 2009
Start, stop, restart MySql - Ubuntu 9.04 Jaunty
~Fin
Monday, October 26, 2009
Reset root password for MySql 5.* - Ubuntu 9.04 Jaunty
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
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
The following command will shred a file, "zero" it (to hide shredding) and then remove it.
user@machine:~$ shred -zuv sensative.file
~Fin
Wednesday, October 21, 2009
Have more visual fun - Ubuntu 9.04 Jaunty
Then open in:
System --> Preferences --> CompizConfig Settings Manager
Then:
- Draw fire on the desktop
- Use the desktop cube
- Animate maximize, minimize, and other actions.
- Other fun stuff I've yet to play with! w00t!
Monday, October 19, 2009
Find files larger than a given size in Linux - Ubuntu 9.04 Jaunty
user@machine:~$ find /path/to/directory -type f -size +1024k
This will search for files larger than 1MB (1024k). Obviously you can adjust this number to suite your search requirements.
~Fin
Wednesday, October 14, 2009
How to Create & Extract tar.gz and tar.bz2 Files in Linux - Ubuntu 9.04 Jaunty
In order to create a compressed tar.gz archive from a folder/file we need to run the following tar command:
tar czf new-tar-file-name.tar.gz file-or-folder-to-archive
Here is the command explanation:
* tar - the tar command.
* c - create new archive.
* z - compress the archive using gzip.
* f - use archive file.
* new-tar-file-name.tar.gz - the name of the tar.gz to create.
* file-or-folder-to-archive - the name of the folder we want to archive.
How to create a compressed tar.gz file from multiple files and folders in Linux?
In order to create a compressed tar.gz file from multiple files or/and folders we need to run the same tar command we used when we archived a single file/folder and to append the rest of the files/folders' names to it.
tar -czf new-tar-file-name.tar.gz file1 file2 folder1 folder2
How to extract a compressed tar.gz file in Linux?
tar -xzf tar-file-name.tar.gz
Here is the command explanation:
* tar - the tar command.
* x - extract the archive.
* z - uncompress the archive using gzip.
* f - use archive file.
* tar-file-name.tar.gz - the name of the tar.gz to extract.
The tar command will extract all the files/folders in the archive to the current directory.
How to extract a compressed tar.bz2 file in Linux?
Extracting tar.bz2 (bzip2 file) is very similar to the way you extract tar.gz file. Instead of using the -z flag you need to use the -j flag for the bzip2 format
tar -xjf tar-file-name.tar.gz
Here is the command explanation:
* tar - the tar command.
* x - extract the archive.
* j - filter the archive through bzip2
* f - use archive file.
* tar-file-name.tar.gz - the name of the tar.gz to create.
The tar command will extract all the files/folders in the archive to the current directory.
~Fin
Monday, October 12, 2009
Show line numbers in VI - Ubuntu Linux 9.04 Jaunty/Mac OS X
Update - verified to work also with Mac OS X
From within VI
:set number
To make this behaviour the default:
user@machine:~$ cd ~
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc
Add the following line to the file:
set number
user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt
Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set number"
Save .exrc
Source .exrc
Test to verify function.
Update (as I've had to look this up twice now...)
To turn off line numbers from withing VI
:set nonumber
~Fin
Recursive grep on directory - Ubuntu Linux 9.04 Jaunty
Doing some work on Solaris where the "-r" flag is not an option. To do this on Solaris:
/usr/bin/find . | /usr/bin/xargs /usr/bin/grep "patternToSearchFor"
or if your paths are defined simply:
find . | xargs grep "patternToSearchFor"
~Fin
How to start, stop, & restart samba - Ubuntu Linux 9.04 Jaunty
sudo /ect/init.d/samba start
sudo /ect/init.d/samba restart
~Fin
Thursday, October 8, 2009
How to execute a .bin file - Ubuntu Linux 9.04 Jaunty
-rw-r--r-- 1 brad brad 108008954 2009-10-08 08:15 fileToBeExecuted.bin
user@machine:~$ chmod +x fileToBeExecuted.bin
user@machine:~$ ll
-rwxr-xr-x 1 brad brad 108008954 2009-10-08 08:15 fileToBeExecuted.bin
user@machine:~$ sudo ./fileToBeExecuted.bin
[sudo] password for user:
user@machine:~$
~Fin