Tag Archives: linux

10 Quick Tips

I would not agree that these are usage habits, or even unix specific. But they are nifty.

  • Make directory trees in a single swipe.
  • Change the path; do not move the archive.
  • Combine your commands with control operators.
  • Quote variables with caution.
  • Use escape sequences to manage long input.
  • Group your commands together in a list.
  • Use xargs outside of find .
  • Know when grep should do the counting — and when it should step aside.
  • Match certain fields in output, not just lines.
  • Stop piping cats.

http://www.ibm.com/developerworks/aix/library/au-badunixhabits.html?ca=lnxw01GoodUnixHabits

Where Is My Next Generation File System?

I read a good article over at LWN.net entitled, Why filesystems are hard. I am not going to summarize it for you. Too many netizens (net citizens) are reliant on quick fixes and blurbs. But this is a rant for another post. Go read it, it is not a waste of time.

But what I will discus are my thoughts on the article.

Every since I downloaded my first linux distribution (8th grade), there has been ext3. All of my countless builds and rebuilds across multiple distros (fedora, debian, ubuntu) I pretty much stuck with ext3. It was the default and it worked. It wasn’t until one of my college classes we covered the nitty gritty of filesystems and even then I remember it being covered in just 2 sessions. Still every build I just built using the default fs (although by this time I had at least setup RAID). It wasn’t really until I got a job where I started interacting with various filesystems. And while we use XFS for its speed (no one wants to fsck a 2TB journaled filesystem), again the majority are on a ext3. There has been talk about switching to ZFS or EXT4, but this definitely won’t happen until they are quite a bit mature.

Now that Ubuntu 9.10 Karmic Koala is out and its default fs is EXT4, there will be a lot more people testing it out. They will find those very infrequent and rare bugs, and eventually EXT4 will be everyone’s default.

Linux Run Levels

Back in the day ( I’m being facetious) there were 6 run levels.

0 System Halted
1 Single User Mode
2 Multi User No Networking
3 Multi User No X
4 Not Defined (special use cases)
5 Multi User with X
6 Reboot

These days Ubuntu is the distribution of choice. Unlike its predecessors, it does not have as complicated a scheme. In Ubuntu (and Debian as a base) there is no distinction between runlevels 2-5. 1 is still single user mode and 6 is still reboot. On top of this wild and crazy scheme, Ubuntu has gotten rid of inittab. Prior to 9.04 entries were put in /etc/event.d but with 9.10 even that is gone. They call their system and it can now be found in /etc/init . For administrators moving from an older distro, it can take some getting used to.

Which shell do you use?

We had a discussion at work today about which shell everyone uses.Everyone has their preferences. There are quiet a few to choose from: sh, bash, zsh, csh, tcsh, and ksh to name just a few. I use BASH and I don’t have a reason better than it’s the default and I have gotten used to it. One feature I love is

sudo !! #this will repeat your previous command as root

Which do you use and why?

I can never remember…

There are some Linux commands that I can never for the life of me remember. Maybe documenting them here will give me a place to come back to when I find myself at a loss.

Deleting files using find:

find . -mtime +3 -exec rm -rf {} \;
#dl all files in cur dir that have not been mod in 3 days

Test for a null string in bash?

if [ -z $VAR ]; then #returns true if the string is empty
 
if [ -n $VAR]; then #returns true if the string is NOT empty
 
if [ $VAR ]; then #returns true is variable exists

Backing up Your Delicious Bookmarks

New technologies can offer a lot, but the mortal sin of users is not backing up. You should backup everything important to 2 places, somewhere local (within your own home network), and somewhere not local (Amazon S3, Mozy, your parent’s house).

Here is another trick for backing up. This script backups Delicious bookmarks. Delicious is a social bookmarking site. Almost no one backs up their local bookmarks (use Xwords!) so Delicious is also good as a place to have a semi-permanent location for those links you just can’t lose.

curl -k --user username:passwd \
-o /path/to/file/delicious_backup.xml  \
-O 'https://api.del.icio.us/v1/posts/all'

Backing Up MySQL

Databases don’t take up a ton of space and compress very well. Here is a quick way to backup all your databases and paired with the email script I posted earlier, you can quickly backup your MySQL data.

#!/bin/bash
 
mysqldump --all-databases -uroot -pPASSWD > /directory/path/all_databases.sql
echo $(date) $0 >>; /var/log/sqldump_backup.log

Quick and Easy Backup

With Google mail offering all that space, it begs to be used as a an alternate backup location. The following script will tar then bzip2 a directory and email it to you as an attachment. Set this up in cron and forget. Probably not a good idea for pictures, but it has saved my butt a couple of times for config files and scripts.

1
2
3
4
5
6
7
8
#!/bin/bash
tar -P --create --file=/path/to/archive/file.tar \
/etc/somewhere/
bzip2 -f /path/to/archive/file.tar
 
sendEmail -f backup@servername.com \
-t destination@address.com -u "backup" \
-a /path/to/archive/file.tar.bz2 -m blank