Author Archives: computerlamp

About computerlamp

The author of this blog has over 20 years of experience with Linux and loves the command line and the flexibility it gives. The author's nephew is invaluable for his help with pop culture references and explaining concepts.

Linux® and Files

 

Everything in Linux® is treated as if it were a file. Directories, hardware, memory, network, you name it, Linux at the core, treats it like a file. Even software that runs is treated like a file. Why a file? Well, files can be written to, can be read from, can be appended to, can be removed, can be created, can be modified… in other words, you can do a lot of things to a file. You can also enforce some standardization and rules about the files. So, files. Files files files.

That being said, there are three important files that Linux® has. They’re called:

  • standard in (stdin)
  • standard out (stdout)
  • standard error (stderr)

These are all created for you by Linux®, you don’t have to do a thing to make them work. You just have to use them.

  •  Standard in
    This is the file that is set up for all input into processes by default. In other words, it’s read directly from the keyboard. If you start a process and it wants you to type, it’s reading from the standard in file.
  • Standard out
    This is the default file for output from a process. If you start a process from the command line, it’s going to print output into the terminal that you started it from. Now, not everything writes output of any sort, but by default, they put it to standard out.
  • Standard error
    Not everything goes as planned… which means not every process runs as planned. Whether by user error or computer error… errors happen. The errors are sent to a different stream than standard out. But to make things confusing, on a basic terminal that means they’re printed to the same place standard out goes to.

So you want to run some commands…

Well, we’ve talked about what the command line is…

…so what can you do with it?
Well, given the name, you can do ‘commands’.

There’s lots of built in commands, but we’ll start with a simple one. Open a terminal session (I’ll leave it up to you to find the one particular to your version of Linux®. It generally has the word ‘term’ in the name.)

The terminal has a ‘prompt’, which is a place to type your commands. They usually combine the name of the computer with your username. So it could look like:

  
 Alpha:~ computerlamp$_

So for our first command, we’re going to try echo. This is a fun command, it repeats any words or sentences you give it to the terminal.

Alpha:~ computerlamp$ echo Hi There
Hi There

Alpha:~ computerlamp$ echo How now brown cow.
How now brown cow.

Alpha:~ computerlamp$ echo Star Wars Rocks!
Star Wars Rocks!

Another fun command is rev. If I type it at the terminal, it looks like:

Alpha:~ computerlamp$ rev

Type any string you want and hit enter. You’ll see the reverse of that string show up. For example:

Alpha:~ computerlamp$ rev
abcdef
fedcba

So now it seems you’re stuck in a loop. You need to get out the rev and back to the prompt. You can do this one of two ways, you can hold down control and hit C or D.

Linux® and Running Things

So when you run a program on a Linux® system, it creates what’s called a process. This is a record of what is running, who started it, what files it has open, is it talking on the network, is it listening to the network, is it playing music, is it making a pretty picture… in other words, what is this thing doing that affects the system at large.
These processes are kept in a table called… the process table. This imaginatively named table contains records of all the processes that are running on the system. Each one has an ID number that’s called (again, so imaginatively) the process ID. This number is what we can use to identify the process in the process table.
Another interesting fact about processes is that there are parent processes and child processes. A parent process is what creates a child process (see what I said about imaginative?). So if you’re at the Linux® screen and you click on a game to start it, then the process that’s identified with you is the parent and that game is the child. To put it succinctly, that game is the child of you.

Some processes are started by the operating system. In fact, the mother of all processes, the init process, is the first process started. It has the process ID of 1. If we were drawing our processes out like a genealogy, it would be the origin of the family. Your process might be the great great grandchild of init, making your game the great great great grandchild.

A zombie process is one that’s finished but hasn’t quite left the process table. So it’s alive when it should be dead, ergo, zombie.  It’s not the kind of zombie that eats brains… or other processes. It’s the kind that hangs around until it just fades away.  That could be very interesting, if it ate other processes.  It’d also make for unstable processes, and Linux® doesn’t like those.

Introduction to Computer Lamp

This blog is going to cover the ins and outs of using Linux® from the
command line.

So before we talk about Linux®, we have to first ask…

…what is Linux®?

Linux® is an operating system. An operating system is the thing that
makes a computer workable. Without it, the computer would be unable to
do anything. No internet access, no games, no nothing. The operating
system is the framework that allows the computer to actually do things.
Without one, you’ve really got an expensive machine that can turn on the
fan and make beeps, but do nothing else.

Unix is an operating system that was created back in the mid 1960s to
run on a new type of computer. It has a long and convoluted
history, but it boils down to ‘new computer system fast and spiffy’.
It was so spiffy various people made it so that it could run on other
types of machines.

And that’s where Linux® comes in. Linus Torvalds wrote a version that
would run on the personal computer systems that we know and love today.
It is free to download and install and has been made available to a
number of hardware specifications. This means it can run on laptops,
netbooks, desktops, smartphones, PDAs, and more. Basically if it has a chip
in it, someone tried (and probably succeeded) to make Linux® run on it.

So this blog is going to talk about Linux® and also how to use various commands and make things work.  And do spiffy things, while we’re at it.

Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.

What is a command line?

So you’ve logged into a Linux® system… or a Windows system.. or a Mac.

You’re presented with a screen with icons on it that represent programs. You can run each of these programs by double clicking on them with your mouse, named Fred. Why Fred? Well, it seems like a mousy name.

So you’ve double clicked on a program and it started up. It isn’t quite running how you want, which isn’t Fred’s fault, but you have to use Fred to find the properties in the program to change them around so that it is working how you want it to.

Which means quite a bit of time with Fred. You can usually preset your program to run the way you want it to, but what about the times when you want it to run slightly different? Well, back to Fred. Fred is a friendly mouse, but all the time with Fred means less time with your keyboard.

So the solution to less time with Fred and more time with the keyboard is the command line. The command line is actually a program in Linux® called the ‘terminal’. Or the ‘xterm’ or the ‘gnome terminal’ or… it all depends on how your Linux is set up.

In the old days, it was the only way to communicate with the computer. Now we have Fred and icons to click, but occasionally, the command line is useful. It has many names, you can read more about the history at Wikipedia.

Back to the command line. With it we can start a program and give it precisely the options we want so that it’ll run the way we want it to. We can start a game, a word processor, a web browser, a pdf viewer… Anything that can be opened with the click of the mouse can be opened by typing a command in the command line, which explains the name.

So in summary, icons are like concrete, command line is like balsa wood.