Tricks of the trade

I had to remind myself the other day that I’ve been using Arch Linux for more than eight years. I did my first trial installs early in 2006, and while I cut my teeth on Ubuntu, as time wore on, Arch eventually became more like home.

With the exception of strict i586 machines, I’m more likely to install Arch on any given computer, with Linux Mint coming in a close second. The logic there is that I can get it running faster with Arch, but there are some features that I use so rarely that I’d rather a distro like Mint take care of them — things like CD burning or encrypted file systems.

I can do those things in Arch, but it’s rare that I need them, and Mint usually sets them up quicker and better than I do.

Over the years I’ve jotted down a few minor notes on one-shot commands or quick-step loops to tackle oddball tasks. I keep them in a flat text file called “tricks,” and when I need to get to one of them, I just grep through it until the command I want appears. Adjust for minor differences or filenames, fire, and forget.

For example, a while back I found a command to list all the packages that are installed on your system, in alphabetical groups. I modified it a little bit, to:

for i in {a..z} ; do echo -e $(pacman -Qq | grep ^${i}) >> packages.txt ; echo >> packages.txt ; done ; fmt -w $(tput cols) packages.txt

The original post (which I don’t have a link to any more😦 ) split them out differently, and words broke at the end of the line, sometimes making them hard to read. I solved that with fmt, which is more than happy to wrap text like a word processor, but likes to run together lines. Hence the extra echo. Oh, and it doesn’t seem to like to have text piped into it, so the external file was necessary.

I think the original post caught some flak for 26 iterations of pacman, but I don’t have a problem with that. Might was well put the system to use for a little bit. If it annoys you, feel free to adjust it.

Some of the “tricks” were my own creation. Back in September I got the (stupid) idea that I would dump all the executables from bsd-games, util-linux, coreutils and even binutils into my list of text-based software, just to be sure I hadn’t missed any hidden gems.πŸ™„

It turned out to be a real hassle, and the results of it were one of my biggest lists of oddball commands in the history of that blog or this. In any case, this was the command that got me in trouble:

for j in {util-linux,binutils,coreutils,bsd-games} ; do LEN=$(echo ${j} | wc -c) ; for i in $(yaourt -Ql "${j}" | grep bin | cut -c$(($LEN+10))- ) ; do echo "${j}" >> temp/"${i}".wiki ; done ; done

Most of that was done to trim off the extra stuff that appears with grep’s output; since the length of the name of each package was different, I had to check where the title ended and the actual binary name began. wc takes care of that, with the -c flag. And to keep this from polluting my home directory, it dumps everything into temp/. The .wiki suffix is just for the benefit of vimwiki.πŸ˜‰

Not everything is Arch-specific in that file. Here’s one that I use more often than I thought I would: Taking a folder of files, and moving each one to prepend the original name with its date stamp:

for i in * ; do mv "${i}" "$(stat -c %y "${i}" | cut -d' ' -f1)-${i}" ; done

stat comes through this time, as a way of generating the timestamp of the file. cut that down to the first field only — the date — and voila, moved to a new name, listed by date. Suddenly your folder has organization.

I use yaourt on a daily basis, and with good reason. With such an abysmally slow Internet connection, I have a tendency to hoard software packages, which is not generally an advisable habit with Arch. Occasionally I make a mistake and wipe out my cache, or just slip after a failed upgrade, and need to pull in a fresh copy.

And so … download a new copy of everything that’s installed on your computer. This one took on a new meaning when I realized you could pipe yes through another program, if you wanted to automatically feed it a positive response:

yes | yaourt -Sw $(yaourt -Q | grep -v local | cut -d'/' -f2 | cut -d' ' -f1 | tr '\n' ' ')

Get a full list of packages from yaourt, which will be preceded by repo names. Filter out anything from “local,” since that’s built and not just downloaded. First cut off the repository name at the slash, then cut off the version at the space. Finally, tr substitutes every carriage return for a space, so we can give one giant command to the outermost yaourt, which will download the entire list. Better leave that one overnight.😐

If you don’t use yaourt, you’ll need to adjust that a little bit, since pacman -Q does not show group names. It also means your “local” packages will be mixed in with your downloadables. Just so you know.

Since we’re on the topic, yaourt lets you do some funky things with your cached packages, and also with the materials it downloads to build local software. If you look in /etc/yaourtrc, you’ll find:

EXPORT=2           # Export to 1: EXPORTDIR or PKGDEST
                   # 2: pacman cache (as root)
EXPORTSRC=1        # Need EXPORT>0 to be used
#EXPORTDIR=""      # If empty, use makepkg's connfiguration (see makepkg.conf)

I’ve adjusted those values to do a few things.

First, EXPORT=2 will send the built package to pacman’s cache, which is a wise move if you ask me. By default yaourt builds everything in /tmp, and it evaporates when you’re not looking. I’ve lost more than one hard-built package by not moving the final product out of that directory.πŸ˜₯

EXPORTSRC=1 does the same thing for the source files and git trees that it downloads. This too can be a lifesaver if you lose the completed package. EXPORTSRC will send everything to EXPORTDIR, or in the absence of that, to the destinations listed in /etc/makepkg.conf. And what are those?

#-- Destination: specify a fixed directory where all packages will be placed
#-- Source cache: specify a fixed directory where source files will be cached
#-- Source packages: specify a fixed directory where all src packages will be placed

By default, all those folders are commented out, so makepkg’s configuration leaves everything in the same folder where it was made. Change those values above, and it will shuffle packages and source files to those directions. It will also create a symlink to the package it just built, so you’re not wasting space.

Let yaourt use those directories, and it will follow those rules, and tar up its $srcdir as well, before sending it off to that destination. In that case, yaourt will tidy up its efforts and leave you all the pieces you need to do it all over again.

And yaourt is generally smart enough to check those directories for source files before re-downloading them. Or so it seems, in most cases.:\

Two more smaller non-secrets I should share:

yaourt -G pkgname

will create a folder named “pkgname,” download its PKGBUILD and all the patches or installation scripts for that package, ready for building. It’s another reason I use yaourt, to be honest. And:


It’s not often that your pacman database will need optimizing, but I can vouch for it on slower machines as a way to speed up searching and filtering. Again, just so you know.πŸ˜‰

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s