Organizing your $HOME

Marcel Gagné

Issue #76, August 2000

I have files I don't even recognize. And yet, I am afraid to delete them.

François, move those boxes down into the wine cellar, please. While you are down there, give the “Dom” a quarter turn as well. Oh, and bring up the '78 La Tache when you come back up. After all this re-arranging and straightening up, I think I will need to relax a bit.

Mon Dieu! Mes amis, I had not realized you were here. Forgive me and forgive this mess. With all the work that has been going on around here, I had not noticed it was opening time. Please, sit down. I will call down to François and have him bring something special from the cellar. On the house!

François! We have guests. A case of Dom Perignon for our friends!

You know, mes amis, when we cook with Linux, we can get a little carried away. After many experiments in the kitchen of your processor, your $HOME can become quite the mess, non? I have files I don't even recognize. And yet, I am afraid to delete them. What if they are important? What if I need them?

One solution is to move. Moving a user to a new directory is child's play with Linux. For instance, if I had a user called “natika” with a home directory of /home/natika, and I somehow felt that Natika would be better served in a new directory called /home/boullabaise, I would issue a command like this:

# usermod -d /home/boullabaise -m natika

The “-d” specifies the new directory, while the “-m” tells usermod to move everything from /home/natika to /home/boullabaise for the userid “natika”. If the directory does not already exist, it will be created. The problem is that everything is moved, and any clutter you may have had will follow you to your new $HOME.

Speaking of clutter ... were you ever curious about the vast array of .jpg files you've scattered across your system? Finding them in order to better organize them can be done with the find command.

# find / -name "*.jpg" -print

Do you want to time that command, mes amis? Depending on the power of your system, this can take awhile and you are likely to get a lot of “permission denied” messages (particularly as you traverse /proc) or when running as a non-privileged user. Luckily, there is a faster way. On most Linux systems, you have a process that runs once a day. That process builds a database of all the files on your system for quick and easy searching. The command is called locate or slocate. The process that runs on your system is located in /etc/cron.daily and called slocate.cron. If your system is not up 24 hours (it is a Linux system, non?), you can build the slocate database by running the cron script manually, or with the command updatedb. Let us try to find those .jpg files again.

# slocate jpg
Amazing, is it not? I should tell you that the find command is quite a bit more powerful than slocate, but if you need to lay your hands on a file quickly and you have no idea where it has gone, try slocate. However, if what you are trying to do is locate old files or particularly large files, then you should definitely use the find command. Here's an example where I look for anything I have not modified (the -mtime parameter) or accessed (the -atime parameter) in the last twelve months.
# find /data1/Marcel -size +1024 \
\( -mtime +365 -o -atime +365 \) -ls
The backslashes are escape characters, there to make sure our shell does not interpret them in ways we do not want it to, in this case, the open and close parentheses on the second line. The first line also has a backslash at the end. This is to indicate a line break, as the whole command will not fit neatly on one line of this page. Were you to type it exactly as shown without any backslashes, it would not work; however, the backslashes in line two are essential. Ah, but there is something else I have not told you. The above command also searches for files that are greater than 500KB in size. That is what the “-size +1024”, means, since the “1024” refers to 512-byte blocks. The -ls at the end of the command tells the system to do a “long” listing of any files it finds that fit my search criteria. You may want to pipe this output to your printer in order to better examine the results. Another option is to redirect it to a file, which you can later peruse and decide on what course of action to take.

Earlier, I mentioned that I'm afraid to delete any of these files because I don't always know what they are. While your humble chef may have been exaggerating a tiny bit, I can tell you how you can improve that search to help you uncover the secrets behind those files. Your system contains a command called file which can deliver useful information on files and what they are. If I modify the find command by adding a -exec clause, I can yield even more information.

# find /data1/Marcel -size +1024  \
\( -mtime +365 -o -atime +365 \) -ls -exec file {} \;

The open and close braces that follow -exec file means that the list of files generated should be passed to whatever command follows the -exec option. The backslash followed by a semicolon at the end is required in this case.

find is a wonderful command in other ways. For instance, I can use it to look for SUID or GUID files, which is extremely useful for security reasons. It is simply a good idea to check your system for files that are set to execute as root and decide whether they should be there or not. I also use find to locate core files and editor temp files, those strange little files with the tilde (~) at the end of the file name. And, of course, working so much in the Linux kitchen means I have source files for hundreds of applications I have tried and tested for you, mes amis. Have a look at the following sample script which I have written to take all these ideas into consideration.

#!/bin/bash
#
# Locate files and report to me.
# Marcel Gagné, 2000
# search_log=/tmp/foundfiles
rm -f $search_log
touch $search_log
#
echo
"------------------------------- " >> $search_log
echo "Looking for big old files . . . " >> $search_log
echo "------------------------------- " >> $search_log
#
find /data1 -size +2048 \( -mtime +180 -o -atime +180
\)  \
   -ls -exec file {} \; >> $search_log
#
echo "------------------------------- " >> $search_log
echo "Looking SUID / GUID files . . . " >> $search_log
echo "------------------------------- " >> $search_log
#
find / -type f \( -perm -2000 -o -perm -4000 \) -ls >> $search_log
#
echo "------------------------------------------------ " >> $search_log echo
"Looking for core files or old editor files . . . " >> $search_log echo
"------------------------------------------------ " >> $search_log
#
find / \( -name core -o -name "*~" \) -print >> $search_log
#
echo "------------------------------- " >> $search_log
echo "All done!" >> $search_log

Of course, my $HOME (or my whole system, for that matter) is not the only place that needs organization. There are so many things to keep track of these days that Chef Marcel needs additional, Linux-style help. How about some electronic sticky notes? You already have 40 or 50 covering your monitor, cubicle wall or desktop (the wooden one, as opposed to the virtual one on your monitor). Why not transport the concept to your Linux desktop? KDE comes with a little program called knotes. You can find it under the Utilities menu, or just type knotes from a terminal window. Unlike your classic paper sticky, you can also set alarms with these notes and they do not use up paper.

Yellow sticky notes are fine and quite frankly, I have found them to be extremely useful on a number of occasions. Unfortunately, they do not offer the flexibility of a planner or calendar. Once again, with your Linux system, you are ready and able to better start planning your life. If you are running GNOME, you can use the program gnomecal to keep yourself organized. KDE users have korganizer to keep them focused. We focus a great deal on both KDE and GNOME users, since desktop applications tend to be designed with ease of use in mind. However, GNOME and KDE are not the only alternatives, and many people use lighter, faster desktops. (For this article, I have been using Window Maker as my window manager.) To those looking for a nice cross-desktop alternative, I recommend ical, a clean, simple X window calendar program.

Figure 1. The ical Program

While not the most powerful calendaring software, ical stands on par with gnomecal mentioned earlier. This little program is likely already installed, and almost definitely on your CD-ROM distribution disk. Start the program by typing ical. The initial screen is a month-view calendar, a to-do list and a single-page day planner view. You can also share calendars with other members of your office by clicking on “File” and “Include calendar”.

Some time ago, your humble chef admitted he needed even more help than ical alone (or electronic yellow stickies, for that matter) could provide. He needed something portable, something that followed him everywhere. That help comes in the shape of his Palm Pilot. While the friendly folks at 3Com were good enough to create this little wonder, they did not provide Linux software for backups and hot-syncs. Luckily, the Linux community of talented developers have come through to help your humble restauranteur stay organized as well as backed up.

Each and every tool I mention from here on requires the pilot-link suite of utilities. You should not have to go hunting for this package, since it is likely already installed on your system. If not, check your distribution CD. One sure way to find out is to try the command read-ical. read-ical is an interface program that will read your Palm Pilot information and load it into a calendar file that can be used by ical. Here's the format for the command.

read-ical /dev/pilot calendar_filename

In the case of my system, /dev/pilot is a symbolic link to /dev/ttyS0. I created that link with this command:

ln -s /dev/ttyS0 /dev/pilot
After issuing the read-ical command, you should click on the “hot-sync” button on your Palm Pilot's cradle. Be warned, mes amis. This process is not a true hot-sync. Each time you execute this command, the calendar file name you specified above is overwritten. For this reason, you should use a different file than your normal everyday calendar file (or your company-wide file). I used a file I called pilotcal. To use it with ical, I simply clicked “File”, then “Include Calendar”. I specified the file named “pilotcal”, and suddenly, all my appointments and to-do items were available.

Before I move on to what I think of as “Super Stickies”, I should mention that the KDE Korganizer program also allows you the means of sync'ing with your Palm, as does another cool KDE program called Kpilot. I have used Kpilot for quite some time now, but lately I've discovered another player in this field, something called J-Pilot. This one won't be on your CD, so you will have to visit the web site (see Resources). Looking very much like its inspiration, the Palm desktop software distributed for that other OS, J-Pilot mimics what is already a familiar interface for users of the Palm Pilot. Written by Judd Montgomery, J-Pilot is available as a source tarball or an RPM (Red Hat, Caldera, Slackware 7).

But what about combining the venerable yellow sticky with the flexibility of the Palm Pilot? Is there nowhere to turn? Luckily, Michael J. Hammel (of Graphics Muse fame and a frequent contributor to this magazine) has written XNotesPlus. This is a nifty little package that extends the power of the sticky well beyond that afforded by knotes.

You can pick up the source, a GTK version or a Motif/LessTif version from the Graphics Muse web site. I picked up the GTK version, which at the time of this writing was version 3.2.2. Installation of XNotesPlus is a breeze. After untarring and unzipping the distribution, simply run the install script from the distribution directory. The steps are as follows:

tar -xzvf XNotesPlus-v3.2.2-Linux-gtk.tar.gz
cd xnotes
./install

The script will confirm with you the location of your xnotes database, as well as the path name to the executable. You will also get instructions to add the following lines to your .bash_profile so that you can sync with your Palm Pilot.

export PILOTPORT=/dev/pilot
export PILOTRATE=57600
To use XNotesPlus, issue the command xnotes+.

Figure 2. Setting an Alarm with XNotesPlus

C'est vrai. There is a plus sign at the end of that command. The application appears with a nice little Window Maker-like icon which you right-click to do various things (it has a little swirl that looks sort of like a galaxy). Among the features you'll find (other than covering your virtual desktop in yellow) is a Palm Pilot sync utility, the ability to print envelopes from your address book, set alarms with little musical reminders, e-mail notes, or, if you really don't want to clutter your desktop, you can even hide the notes.

Before I leave XNotesPlus, I should point out that while it is free software and source is provided, it is not GPL'ed. Read the accompanying “COPYING” file for license details.

Well, mes amis, it is that time once again, when we must part. Next time you visit, I hope to be a little more organized. While it is good for you to sip free champagne, it is not so good for me, non? Never mind; enjoy. In fact, have François pour you a final glass before we close the door. When next we meet, your table will be ready here at Chez Marcel.

A vôtre santé! Bon appétit!

Resources

email: mggagne@salmar.com

Marcel Gagné (mggagne@salmar.com) lives in Mississauga, Ontario. In real life, he is president of Salmar Consulting Inc., a systems integration and network consulting firm. He is also a pilot, writes science fiction and fantasy and edits TransVersions, a science fiction, fantasy and horror magazine. He loves Linux and all flavors of UNIX and will even admit it in public. You can discover much from his web site at http://www.salmar.com/.