I’ve been using Linux casually for a number of years now running several Ubuntu variants, and I would put myself firmly in the category of self-taught user. I’m comfortable using the command line, and there are a number of tasks that I would rather use it for than go through a GUI. There are also some tasks I perform regularly at work that require me to use the command line, and I rarely flinch at diving into commands if that’s what I need to do to get a job done, but some of the more advanced things I’m doing I’ve learned by rote memorization.
I read the man pages a lot when I want to figure out how to do something, but those don’t always have examples, and sometimes there are things that a command can do that I didn’t know about.
I know about wildcards insofar as I know they exist, and most of the time I can remember that * means any character (including no characters at all), but ask me what ? means or how to use square brackets, and I may just plead the fifth.
So. The ? wildcard. It stands in for any one character. Given a list of files:
rm butts?.rtf would match
butts3.rtf but wouldn’t touch
butts.txt, walrus.jpg, or
The  wildcard matches a set of single characters (for example
) or a range of characters separated by a hyphen (such as
If I wanted to get at those other files without touching the rich-text files, I could use
rm [a-z].* where the
[a-z] will get any lowercase words not separated by capital letters, underscores, hyphens, etc. The
. is just that–there’s nothing special, it just means that after that sequence of lower-case characters, the next expected thing is a dot. After that, there’s the
* wildcard, which means anything. In the above example, then,
butts1.rtf et al won’t be touched because after the string of letters, the next thing expected is a dot, not a number.
It’s worth noting that in the above example, if there had been a file named
tricky.example_7.txt in the same directory,
rm would have gotten that one, too, because of that
* wildcard, which says “anything is game.”
Some Switches for
Recursion. If you’ve ever take a programming class, you’ve probably encountered the term before. For the
ls command, recursion, signified by the
-R switch, not only lists all files in a given directory, but also lists all files in every subdirectory and so on down the line. Turtles all the way down!
The other useful switch I want to talk about, because it’s one that I just recently came to fully understand, is the
-l switch (that’s a lowercase L, not a one–that does something different), which lists, among other things, file permissions and ownership. Let’s look at a couple of examples from life, shall we? Below are a couple of examples of the output from running
ls -l on a directory on my closest Linux box.
drwxrwxr-x 4 hilary hilary 4096 Sep 12 15:29 A+
-rw-rw-r-- 1 hilary hilary 1580414 Mar 8 2012 LFS-BOOK-7.1.pdf
There’s a lot of stuff going on there, right? Let’s start from the right and move left, just to be contrary. On the far right, we have the name of the file (on Linux systems, everything is a file, even directories). Next, we get the time and date that it was last modified. Moving left again, we see the size of the file in bytes. Since the top entry is a directory, we see how much space is taken up by the list of files the directory points to, in the bottom entry, we see that it’s a large PDF document. Left of that we have (moving from right to left still) the file’s group and its owner. Following that, we have a number. In the case of directories, this number tells you how many items the directory contains, and in the case of files, the number of hard links that exist for that file (I’ll cover hard links at a later time when I have a better understanding of them myself). Finally, we have a possibly confusing string of letters that tell you about the file’s type and permissions. Starting from the left of that string, the first character tells us what the file is. Regular files and executables are both indicated by
d tells you that it’s a directory,
l is for link,
s for socket,
b for block device,
c for character device, and
p for named pipe.
After that information, you get the permissions for, from left to right, the file’s owner, the file’s group, and everyone else on the system. In the case of
A+ we see that it’s a directory, and I, the owner, have
w write, and
x execute permissions. The file’s group has the same permissions, and everyone else in the world of this system has read and execute, but not write. Given the above information, you should be able to suss out that the bottom file is a regular file to which the owner and group have read and write permissions, and everyone else has read only.
So what does it mean to have execute permissions on a directory? For directories, the execute permission means that a given user has the ability to access files within that directory for the purpose of running commands that access or otherwise use them.
That’s it for this time. Check back in next time for who knows what.