Monthly Archives: September 2016

Finding Commands

Suppose you made a directory that you thought you needed called penguin. As it turns out, you don’t need penguin at all, but due to a brief brain fart you’ve forgotten how to remove directories. Unfortunately, we haven’t yet progressed to the point where you can tell your computer ‘remove that directory’. We have to know what command to type.

Luckily for us, Linux® has a command that will help us find the command we need. It is called apropros. If we try:

Alpha:~ computerlamp$  apropros directory

That gives us a list of every man page on the system that has something to do with directory. Luckily for us, the command uses the more or less command for the output of apropros so we can look through the results and find the command that will remove the directory. Which, as we know from a previous post, is rmdir.

As Linux® always has another way to do things, there is another way to search through man pages. In this case, it is a flag for man, man -k. It will give the same results as apropros.

Alpha:~ computerlamp$  man -k directory

Sometimes apropos finds nothing. Try

Alpha:~ computerlamp$ apropos penguin

Learning about MORE FLAGS

In the last post we discussed how flags can change the behavior of a command. Now comes the big question: How do we know what flags a command has? We can’t use the flags if we don’t know what they are.

The first way to find what flags a command has is to ask the command for help. We can use the flags -h or –help. Many commands have one or both built in to give you a list of flags and a brief explanation of what each command does.

Unfortunately, not every command has this built in. Try ls -h and you’ll see.

So we need another way to find out the flags. This requires using another command called man. man, short for manual, describes the command and lists all possible flags. It also can include examples of using the command and pointers to similar commands. For example:

Alpha:~ computerlamp$ man ls

The results from this command are called man pages. The man pages can be really long in a lot of cases, luckily the results are put through the more command so you can page through and not try to read the resuts as it scrolls by. What happens if you try to read a man page that doesn’t exist? Try it!

Alpha:~ computerlamp$ man sith
No manual entry for sith

So according to the man pages, there are no sith… At least, this computer doesn’t know about sith.  I assume that means it doesn’t know about the force…

Alpha:~ computerlamp$ man force
No manual entry for force

Flags

These aren’t the flags you wave from a flag pole.  Ever heard of semaphores?  Those are the flags that sailors used to use to send signals between ships in the days before radio and cell phones and all those other ways we have to communicate now.   So these are flags that can be used to send a signal to a command that you want it to operate differently.

In our previous posts, we’ve used several commands like file, cat, more, echo, and ls. Let’s look at ls some more. If we execute:

Alpha:~ computerlamp$ ls /usr

then we see the directory contents of the usr directory. Now suppose we want to know which of these is a directory and which isn’t. We could cd into that directory and then try each one at a time to find out which one is a directory, but that’s the long way around. As luck would have it, there’s something that will allow us to see what is a directory and what isn’t. We can run:

Alpha:~ computerlamp$ ls -F /usr

Each directory in that listing ends with a ‘/’. Try that command on other directories and see what happens. For example, we made a directory called Sith in a previous post. What happens if you do that on the Sith? The -F is called a command flag or just a flag.  It’s a semaphore that doesn’t involve picking up and waving flags to that command.  It lets us change the output of ls so we can see different things.

Try that command on other directories and see what happens. For example, we made a directory called Sith in a previous post. What happens if you do that on the Sith?

With ls we can change what we see in the output of the command. It’s part of what makes the command line so powerful. With the mouse (remember Fred the mouse?) you can’t add flags to commands and change how it operates.  You can just click on icons.  I mean, I suppose you could add actual flags to the icons, but that won’t change how it operates.

And most commands have flags, so you can customize them to do exactly what you want.

What are these files?

So in a previous post we talked about the more command. We also saw how if we tried to look at a binary file, we saw

"/usr/bin/more" may be a binary file.  See it anyway?

So now we have a question: Is there a way to find out if a file is a plain text file versus a binary file? Well, this being Linux®… of course there is! It’s called the file command. It uses various tests to try to find out what kind of data is contained within the file. Remember the blog1.txt file from the other post? If we run

Alpha:~ computerlamp$ file blog1.txt

We get:

blog1.txt: ASCII English text

So that means it’s a file we can use the more command on. What if it is a file that ends with .pdf and is still a text file? Well, that’s the magic of the file command. It doesn’t pay attention to the extension (that’s the letters after the dot) but tests the file itself. We can use the file command on any kind of file. Go ahead, try it on anything on your system, see what you get. It just identifies the file, it doesn’t do anything to it.