Here’s a quick tip for finding files over 100M on Linux.

# find /home/adam/ -size +100M -exec ls -lh {} \; | awk '{print $5 , $8}'

Note that if you change 100M in the command you can find files with any size.   Also, replace /home/adam with any directory you wish.

How To Backup Your iPod Music on Linux

As an iPod owner and Linux user, there are a few options I have on Linux for managing my iPod music library. In my opinion, the best option available is gtkpod. One great option of gtkpod is the ability to backup your iPod music to your hard drive for free. The purpose of this guide is to explain a little about gtkpod and show you how to backup your iPod to your hard drive on Linux. I am using Ubuntu to back up my iPod music with gtkpod. gtkpod is available for any Linux distribution that is running gnome libraries and has X installed.

About gtkpod

gtkpod is a platform independent Graphical User Interface for Apple’s iPod using GTK2. It supports the first to fifth Generation including the iPod mini, iPod Photo, iPod Shuffle, iPod nano, and iPod Video.

What can gtkpod do?

  • Read your existing iTunesDB (i.e. import the existing contents of your iPod including playcounts, ratings and on-the-go playlists).
  • Add MP3, WAV, M4A (non-protected AAC), M4B (audio book), podcasts, and various video files (single files, directories or existing playlists) to the iPod. You need a third party product to download podcasts, like ‘bashpodder’ or ‘gpodder’
  • View, add and modify Cover Art
  • Browse the contents of your local harddisk by album/artist/genre by adding all your songs to the ‘local’ database. From there the tracks can be dragged over to the iPod/Shuffle easily.
  • Create and modify playlists, including smart playlists.
  • You can choose the charset the ID3 tags are encoded in from within gtkpod. The default is the charset currently used by your locale setting.
  • Extract tag information (artist, album, title…) from the filename if you supply a template.
  • Detect duplicates when adding songs (optional).
  • Remove and export tracks from your iPod.
  • Modify ID3 tags — changes are also updated in the original file (optional).
  • Refresh ID3 tags from file (if you have changed the tags in the original file).
  • Sync directories.
  • Normalize the volume of your tracks (uses mp3gain or the replay-gain tag)
  • Write the updated iTunesDB and added songs to your iPod.
  • Work offline and synchronize your new playlists / songs with the iPod at a later time.
  • Export your korganizer/kaddressbook/thunderbird/evocalendar/evolution/webcalendar… data to the iPod (scripts for other programs can be added).

Go here to download gtkpod directly. For installation instructions on Ubuntu, see below.

Installing and Configuring gtkpod on Ubuntu

# sudo apt-get install gtkpod

Next, open gtkpod by navigating to the Applications > Sound & Video menu and selecting gtkpod.

Select gtkpod from Gnome Menu


Now with gtkpod open, plug in your iPod via USB to your computer and power on the iPod. gtkpod should load your iPod automatically.

Screenshot of gtkpod main screen

Next, select what tracks you would like to back up to your computer by highlighting the tracks.

Once you have selected the tracks (note: you can select All then highlight all of your music if you want to back up your entire iPod) select File > Export Tracks From Database > Selected Tracks

gtkpod Export tracks from database

You then will be prompted to select where you would like to save the tracks. Choose a directory and click Save.

Now sit back and let gtkpod back up your iPod music.

Heres a quick tip on how to find out what ports are open on your Linux computer without using a port scanner.

# netstat -anp --tcp --udp | grep LISTEN

Cheers!

Here is how to change the PostgreSQL root password from the Linux command line. Replace “root” with any user name to change any password. It is important to note that PostgreSQL does not have an actual “root” user name. The “postgres” user is the super-user for PostgreSQL.

# su postgres
# psql -d template1
template1=# ALTER USER postgres WITH PASSWORD '${POSTGRESQL_POSTGRES_PASSWORD}';

You can replace “postgres” with any user name.

Quickzi: How To Change MySQL Root Password

Here is how to change the mysql root password from the Linux command line. Replace “root” with any user name to change any mysql user password.

Change MySQL Password

# /etc/init.d/mysql stop
# mysqld --skip-grant-tables
# mysqladmin -u root password 'newpasswd'
# /etc/init.d/mysql start

Cheers!

It has been announced that Security-Enhanced Linux (SELinux) will now be available as an alternative security option to AppArmour in Ubuntu 8.04 “Hardy Heron”.

Security-Enhanced Linux (SELinux) is a Linux feature that provides a variety of security policies, including U.S. Department of Defense style mandatory access controls, through the use of Linux Security Modules (LSM) in the Linux kernel.

Here is How to install SELinux on Ubuntu 8.04 taken from the Ubuntu Wiki:

How To Install SELinux on Ubuntu 8.04 “Hardy Heron”

Installing SELinux in Hardy:

  1. Update /etc/apt/sources.list by appending the following:
  2. Update repo:
    • > apt-get update
  3. Install updated packages:
    • > apt-get upgrade
    • These packages have SELinux support patches:
      • libpam0g
      • openssh-server
      • grub
      • login
  4. Install selinux:
    • > apt-get install selinux
    • These packages will be removed:
      • apparmor
      • apparmor-utils
  5. Reboot

If using aptitude instead of apt-get, you will need to manually remove apparmor and apparmor-utils, deselect selinux-policy-dummy, and then choose selinux-policy-refpolicy.

If you are a hard core systems administrator or Linux engineer you’ll probably recognize most of these Linux command line tricks. The following Linux command line tips are not typically used by your everyday Linux user.

Quickly Find a PID with pgrep

pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout.

pgrep ssh

This will list all PIDs associated with the ssh process.

Execute The Last Executed Command

The heading sounds a bit confusing but it’s exactly what it does.

!!

This will execute the last command you used on the command line.

Execute The Last Command Starting With..

If you want to execute a command a command from history starting with the letter S you can use the following:

!s

This will execute the last command used on the command line that started with s.

Run a Command Repeatedly and Display the Output

watch runs command repeatedly, displaying its output (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds. watch is very similar to tail.

watch -d ls -l

This will watch the current directory for any file changes and highlight the change when it occurs.

Save Quickly in VI/VIM

If you’re in a hurry, you can save and quit the file you’re editing in vi by exiting insert mode, holding shift, and hitting z twice.

Quickly Log Out of a Terminal

You can quickly log out of a terminal session by using: CTRL+D

Navigate to the Last Directory You Were In

cd - will take you to the last directory you were in.

Make Parent Directories the Smart Way

mkdir -p /home/adam/make/all/of/these/directories/ will create all directories as needed even if they do not exist. Why waste time doing something silly like: mkdir make ; cd make ; mkdir all ; cd all ; mkdir of ; cd of … you get the point. Use mkdir -p!

Delete the Entire Line

If you’ve just typed a long string of commands that you don’t need to enter anymore, delete the entire line by using: CTRL+U.

Set the Time stamp of a File

touch -c -t 0801010800 filename.c will show the time stamp as 2008-01-01 8:00. The format is (YYMMDDhhmm).

Can you think of any other Linux commands that are less known to the general Linux community?

Subscribe to my RSS feed here.

How To Speed Up Linux

The Wired How-To Wiki has some great tips on how to speed up Linux.

Most of the tips covered in this article involve using the command line and editing system files. Therefore, it goes without saying that you should be fairly comfortable with your command line skills before attempting any of these tweaks. However, if you’re new to Linux, these system tweaks can serve as excellent feet-wetting exercises.

The tips for speeding up Linux are broken down into the following categories:

  • Get Rid of Unnecessary Processes
  • Swap Less Often
  • Speed Up Your Applications
  • Things That Probably Won’t Help

Read more

The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her password.

Example:

adam@desktop:~$ sudo chage -l adam
Last password change : Mar 02, 2008
Password expires : Apr 11, 2008
Password inactive : never
Account expires : Mar 30, 2009
Minimum number of days between password change : 20
Maximum number of days between password change : 40
Number of days of warning before password expires : 7
adam@desktop:~$

Read the man page of chage here.

10 Good UNIX Usage Habits

Michael Stutz has a very nice article on IBM that covers 10 Good UNIX Usage Habits for the command line.

Adopt 10 good habits that improve your UNIX® command line efficiency — and break away from bad usage patterns in the process. This article takes you step-by-step through several good, but too often neglected, techniques for command-line operations. Learn about common errors and how to overcome them, so you can learn exactly why these UNIX habits are worth picking up.

Here is an example:

Make directory trees in a single swipe

Listing 1 illustrates one of the most common bad UNIX habits around: defining directory trees one at a time.

Listing 1. Example of bad habit #1: Defining directory trees individually

~ $ mkdir tmp
~ $ cd tmp
~/tmp $ mkdir a
~/tmp $ cd a
~/tmp/a $ mkdir b
~/tmp/a $cd b
~/tmp/a/b/ $mkdir c
~/tmp/a/b/ $ cd c
~/tmp/a/b/c $

It is so much quicker to use the -p option to mkdir and make all parent directories along with their children in a single command. But even administrators who know about this option are still caught stepping through the subdirectories as they make them on the command line. It is worth your time to conscientiously pick up the good habit:

Listing 2. Example of good habit #1: Defining directory trees with one command

~ $ mkdir -p tmp/a/b/c

You can use this option to make entire complex directory trees, which are great to use inside scripts; not just simple hierarchies. For example:

Listing 3. Another example of good habit #1: Defining complex directory trees with one command

~ $ mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}

In the past, the only excuse to define directories individually was that your mkdir implementation did not support this option, but this is no longer true on most systems. IBM, AIX®, mkdir, GNU mkdir, and others that conform to the Single UNIX Specification now have this option.

For the few systems that still lack the capability, use the mkdirhier script (see Resources), which is a wrapper for mkdir that does the same function:
~ $ mkdirhier project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}

Read more..