paint-brush
The Basics of Debian GNU/Linuxby@goerzenandothman

The Basics of Debian GNU/Linux

by Goerzen & OthmanOctober 26th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

It’s now time to explore the system in more detail. You’ve seen how to log in and shut down the system. In this chapter, we explore the Linux comand line, how Linux deals with files and directories, and some basics on identifying yourself to others. 5.1 The Command Line and Man Pages We’ve already discussed the command line—that is, commands you type after the shell prompt. This section describes the structure of more complicated command lines. A minimal command line contains just a command name, such as whoami. But other things are possible. For example, you might type: man whoami. This command requests the online manual for the whoami program (you may have to press the space bar to scroll through the documentation or press q to quit). A more complicated example is man -k PostScript. This command line has three parts. It begins with the command name, man. Then it has an option or switch, -k, followed by an argument, PostScript. Some people refer to everything except the command name as the parameters of the command. So, options and arguments are both parameters. Options change the behavior of a command, switching on particular features or functionality. They usually have a - before them. The GNU utilities also have “long forms” for the options; the long form of -k is -apropos. You can enter man -h or man -help to get a full list of options for the man command. Every command will have its own set of options, though most have -help and -version options. Some commands, such as tar, do not require the “-” before their options for historical reasons. Anything that isn’t an option and isn’t the command name is an argument (in this case, PostScript). Arguments can serve many purposes; most commonly, they are filenames that the command should operate on. In this case, PostScript is the word you want man to search for. In the case of man whoami, the argument was the command you wanted information about.
featured image - The Basics of Debian GNU/Linux
Goerzen & Othman HackerNoon profile picture

Debian GNU/Linux: Guide to Installation and Usage" by John Goerzen and Ossama Othman is part of the HackerNoon Books Series. You can jump to any chapter in this book here. The Basics

5. The Basics

It’s now time to explore the system in more detail. You’ve seen how to log in and shut down the system. In this chapter, we explore the Linux comand line, how Linux deals with files and directories, and some basics on identifying yourself to others.

5.1 The Command Line and Man Pages

We’ve already discussed the command line—that is, commands you type after the shell prompt. This section describes the structure of more complicated command lines.


A minimal command line contains just a command name, such as whoami. But other things are possible. For example, you might type: man whoami. This command requests the online manual for the whoami program (you may have to press the space bar to scroll through the documentation or press q to quit). A more complicated example is man -k PostScript. This command line has three parts. It begins with the command name, man. Then it has an option or switch, -k, followed by an argument, PostScript. Some people refer to everything except the command name as the parameters of the command. So, options and arguments are both parameters.


Options change the behavior of a command, switching on particular features or functionality. They usually have a - before them. The GNU utilities also have “long forms” for the options; the long form of -k is -apropos. You can enter man -h or man -help to get a full list of options for the man command. Every command will have its own set of options, though most have -help and -version options. Some commands, such as tar, do not require the “-” before their options for historical reasons.


Anything that isn’t an option and isn’t the command name is an argument (in this case, PostScript). Arguments can serve many purposes; most commonly, they are filenames that the command should operate on. In this case, PostScript is the word you want man to search for. In the case of man whoami, the argument was the command you wanted information about.


Here’s a breakdown of the man -k PostScript command line:


man. The command name, tells the computer to look at the manual pages. These provide documentation for commands. For example, man whoami will give you documentation on the whoami command.


-k. The option, changes the behavior of man. Normally man expects a command name, such as whoami, for an argument and looks for documentation of that command. But with the -k or -apropos option, it expects the argument to be a keyword. It then gives a list of all manual pages with that keyword in their description.


PostScript. is the argument; because we used the -k option, it’s the keyword to search for.


-k and PostScript are both parameters.


Go ahead and type man -k PostScript, and you will see a list of all the manual pages on your system that have something to do with PostScript. If you haven’t installed much software, you might see the message PostScript: nothing appropriate instead.

5.1.1 Describing the Command Line

Note: You can skip this section if you want to move on.


There’s a traditional, concise way of describing command syntax. Syntax means the correct ways to combine various options and arguments. For example, if you type man man to get the manual page about man, you’ll see several syntax descriptions beginning with the command name man. One of them will look like this: man -k [-M path] keyword ...


Anything in brackets ([]) is an optional unit. In this case you don’t have to use the -M option, but if you do, you must use a path argument. You must use the -k option and the keyword argument. The ... means that you could have more of whatever came before it, so you could look up several keywords.


Let’s look at one of the more complex descriptions from the man manual page:


man [-c|-w|-tZT device] [-adhu7V] [-m system[,...]] [-L locale] [-p string] [-M path] [-P pager] [-r prompt] [-S list] [-e extension] [[section] page ...] ...


There’s no need to go through all of this (and don’t worry about what it all means), but do pay attention to the organization of the description.


First, clusters of options usually mean you can use one or more of them in different combinations, so -adhu7V means you can also use -h. However, you can’t always use all combinations; this description doesn’t make that clear. For example, -h is incompatible with other options, but you could do man -du. Unfortunately, the description’s format does not make this clear.


Second, the | symbol means “or.” So you can use the -c, the -w, or the -tZT option, followed by a device argument.


Third, notice that you can nest the brackets, because they indicate optional units. So if you have a section, you must also have a page, because e page is not optional within the [[section] page] unit.


There’s no need to memorize any of this, just refer to this section as you read documentation.

5.2 Files and Directories

Files are a facility for storing and organizing information, analogous to paper documents. They’re organized into directories, which are called folders on some other systems. Let’s look at the organization of files on a Debian system:


/. A simple / represents the root directory. All other files and directories are contained in the root directory. If you are coming from the DOS/Windows world, / is very similar to what C:is for DOS, that is the root of the filesystem. A notable difference between DOS and Linux however, is that DOS keeps several filesystems: C: (first hard disk), A: (first floppy disk), and D: (either CD-ROM or second hard disk), whereas Linux has all its files organized above the same / root.


/home/janeq. This is the home directory of user “janeq.” Reading left to right, to get to this directory you start in the root directory, enter directory home, and then enter directory janeq.


/etc/X11/XF86Config. This is the configuration file for the X Window system. It resides in the X11 subdirectory of the /etc directory. /etc is in turn a subdirectory of the root directory, /.


Things to note:


◼ Filenames are case-sensitive. That is, MYFILE and MyFile are different files.

◼ The root directory is referred to as simply /. Don’t confuse this “root” with the root user, the user on your system with “super powers.”

◼ Every directory has a name, which can contain any letters or symbols except /. The root directory is an exception; its name is / (pronounced “slash” or “the root directory”), and it cannot be renamed.

◼ While you can use almost any letters or symbols in a filename, in practice it’s a bad idea. It is better to avoid characters that often have special meanings on the command line, including: { } ( ) [ ] ’ ‘ " / > < | ; ! # & ^ * %

◼ Also avoid putting spaces in filenames. If you want to separate words in a name, good choices are the period, hyphen, and underscore. You could also capitalize each word, LikeThis.

◼ Each file or directory is designated by a fully-qualified filename, absolute filename, or path, giving the sequence of directories which must be passed through to reach it. The three terms are synonymous. All absolute filenames begin with the / directory, and there’s a / before each directory or file in the filename. The first / is the name of a directory, but the others are simply separators to distinguish the parts of the filename.

◼ The words used here can be confusing. Take the following example:


/usr/share/keytables/us.map.gz. This is a fully-qualified filename; some people call it a path. However, people will also refer to us.map.gz alone as a filename.

◼ There is also another use for the word “path.” The intended meaning is usually clear from the context.

◼ Directories are arranged in a tree structure. All absolute filenames start with the root directory. The root directory has a number of branches, such as /etc and /usr. These subdirectories in turn branch into still more subdirectories, such as /etc/init.d and /usr/local. The whole thing together is called the “directory tree.”

◼ You can think of an absolute filename as a route from the base of the tree (/) to the end of some branch (a file). You’ll also hear people talk about the directory tree as if it were a family tree: Thus subdirectories have “parent,” and a path shows the complete ancestry of a file.

◼ There are also relative paths that begin somewhere other than the root directory. More on this later.

◼ No directory corresponds to a physical device, such as your hard disk. This differs from DOS and Windows, in which all paths begin with a device name such as C:. The directory tree is meant to be an abstraction of the physical hardware, so you can use the system without knowing what the hardware is. All your files could be on one disk—or you could have 20 disks, some of them connected to a different computer elsewhere on the network. You can’t tell just by looking at the directory tree, and nearly all commands work just the same way no matter what physical device(s) your files are really on.


Don’t worry if all this isn’t completely clear yet. There are many examples to come.

5.2.1 Using Files: A Tutorial

To use your system, you’ll have to know how to create, move, rename, and delete files and directories. This section describes how to do so with the standard Debian commands.


The best way to learn is to try things. As long as you aren’t root (and haven’t yet created any important personal files), you cannot mess up too seriously. Jump in—type each of these commands at the prompt and press Enter.


pwd


One directory is always considered the current working directory for the shell you’re using. You can view this directory with the pwd command, which stands for Print Working Directory. pwd prints the name of the directory you’re working in—probably /home/yourname.


ls


ls stands for “list,” as in “list files.” When you type ls, the system displays a list of all the files in your current working directory. If you’ve just installed Debian, your home directory may well be empty. If your working directory is empty, ls produces no output, because there are no files to list.


cd /


cd means “change directory.” In this case, you’ve asked to change to the root directory.


pwd


This verifies that you’re working in the root directory.


ls


Lets you see what’s in /.


cd


Typing cd with no arguments selects your home directory— /home/ yourname —as the current working directory. Try pwd to verify this.


Before continuing, you should know that there are actually two different kinds of filenames. Some of them begin with /, the root directory, such as /etc/profile. These are called absolute filenames because they refer to the same file no matter what your current directory is. The other kind of filename is relative.


Two directory names are used only in relative filenames: . and ... The directory . refers to the current directory, and .. is the parent directory. These are “shortcut” directories. They exist in every directory. Even the root directory has a parent directory—it’s its own parent!


So filenames that include . or .. are relative, because their meaning depends on the current directory. If I’m in /usr/bin and type ../etc, I’m referring to /usr/etc. If I’m in /var and type ../etc, I’m referring to /etc. Note that a filename without the root directory at the front implicitly has ./ at the front. So you can type local/bin, or ./local/bin and it means the same thing.


A final handy tip: The tilde ~ is equivalent to your home directory. So typing cd ~ is the same as typing cd with no arguments. Also, you can type things like cd ~/practice/mysubdirectory to change to the directory /home/yourname/practice/mysubdirectory. In a similar way, ~myuser is equivalent to the home directory of the user “myuser,” which is probably something like /home/myuser; so ~myuser/docs/debian.ps is equivalent to /home/myuser/doc/debian.ps.


Here are some more file commands to try out, now that you know about relative filenames. cd to your home directory before you begin.


mkdir practice


In your home directory, make a directory called practice. You’ll use this directory to try out some other commands. You might type ls to verify that your new directory exists.


cd practice


Changes the directory to practice.


mkdir mysubdirectory


Creates a subdirectory of practice.


cp /etc/profile .


cp is short for “copy.” /etc/profile is just a random file on your system, don’t worry about what it is for now. We’ve copied it to . (recall that . just means “the directory I’m in now,” or the current working directory). So this creates a copy of /etc/profile and puts it in your practice directory. Try typing ls to verify that there’s indeed a file called profile in your working directory, alongside the new mysubdirectory.


more profile


This lets you view the contents of the file profile. more is used to view the contents of text files. It’s called more because it shows one screenful of the file at a time, and you press the space bar to see more. more will exit when you get to the end of the file, or when you press q (quit).


more /etc/profile


Verifies that the original looks just like the copy you made.


mv profile mysubdirectory


mv stands for “move.” You’ve moved the file profile from the current directory into the subdirectory you created earlier.


ls


Verifies that profile is no longer in the current directory.


ls mysubdirectory


Verifies that profile has moved to mysubdirectory.


cd mysubdirectory


Changes to the subdirectory.


mv profile myprofile


Note that unlike some operating systems, there is no difference between moving a file and renaming it. Thus there’s no separate rename command. Note that the second argument to mv can be a directory to move the file or directory into, or it can be a new filename. cp works the same way.


As usual, you can type ls to see the result of mv.


mv myprofile ..


Just as . means “the directory I’m in now,” .. means “parent of the current directory,” in this case the practice directory you created earlier. Use ls to verify that that’s where myprofile is now.


cd ..


Changes directories to the parent directory—in this case practice, where you just put myprofile.


rm myprofile


rm means “remove,” so this deletes myprofile. Be careful! Deleting a file on a GNU/Linux system is permanent—there is no undelete. If you rm it, it’s gone, forever. Be careful! To repeat, deleting a file on a GNU/Linux system is permanent—there is no undelete. If you rm it, it’s gone, forever.


rmdir mysubdirectory


rmdir is just like rm, only it’s for directories. Notice that rmdir only works on empty directories. If the directory contains files, you must delete those files first, or alternatively you can use rm -r in place of rmdir.


cd ..


This moves out of the current directory, and into its parent directory. Now you can type the following:


rmdir practice


This will delete the last remnants of your practice session.


So now you know how to create, copy, move, rename, and delete files and directories. You also learned some shortcuts, like typing simply cd to jump to your home directory, and how . and .. refer to the current directory and its parent, respectively. You should also remember the concept of the root directory, or /, and the alias ~ for your home directory.

5.2.2 Dot Files and ls -a

When you type ls, files beginning with a dot are not listed. Traditionally, files that contain configuration information, user preferences, and so on begin with a dot; these are hidden and out of your way while you do your day-to-day work. Sample dot files are ~/.emacs, ~/.newsrc, ~/.bashrc, ~/.xsession, and ~/.fvwmrc. These are used by Emacs, news readers, the Bash shell, the X Window system, and the fvwm window manager, respectively. It is conventional to end the dot filename with rc, but some programs don’t. There are also directories beginning with a dot, such as ~/.gimp and ~/.netscape, which store preferences for the Gimp and Netscape.


Sometimes a program will create a dot file automatically; for example, Netscape allows you to edit your preferences with a graphical dialog box and then it saves your choices. Other times you will create them yourself using a text editor; this is the traditional way to do it, but you have to learn the peculiar format of each file—inconvenient at first, but it can give you a lot of power.


To see dot files, you must use the -a option to ls. The long form of -a is -all, if you find that easier to remember. You can also use -A or -almost-all, which displays all dot files except . and ... Remember that . is the current directory, and .. is the parent of the current directory; because these are guaranteed to be in every directory, there is no real reason to list them with ls. You already know they are there.

5.3 Processes

We mentioned before that GNU/Linux is a multitasking system. It can do many tasks at once. Each of these tasks is called a process. The best way to get a sense of this is to type top at the shell prompt. You’ll get a list of processes, sorted according to how much of the computer’s processing time they’re using. The order will continuously change before your eyes. At the top of the display, there’s some information about the system: how many users are logged in, how many total processes there are, how much memory you have and how much you’re using.


In the far left column, you’ll see the user owning each process. The far right column shows which command invoked the process. You’ll probably notice that top itself, invoked by you, is near the top of the list (because anytime top checks on CPU usage, it will be active and using CPU to do the check).


Note that in all the commands ending in “d” —such as kflushd and inetd —the “d” stands for daemon.


Daemon originally meant Disks And Extensions MONitor. A daemon is a non-interactive process, that is, it’s run by the system and users never have to worry about it. Daemons provide services like Internet connectivity, printing, or e-mail.


Now press u and give top your username when it asks. The u command asks to see only those processes belonging to you; it allows you to ignore all the daemons and whatever other people are doing. You might notice bash, the name of your shell. You’ll pretty much always be running bash.


Note that column two of the top display shows you the PID, or Process IDentification number. Each process is assigned a unique PID. You can use the PID to control individual processes (more on that later). Another useful trick is to press ? to get a list of top commands.


You may wonder about the difference between a “process” and a “program.” In practice, people use the terms interchangeably. Technically, the program is the set of instructions written by a programmer and kept on disk. The process is the working instantiation of the program kept in memory by Linux. But it’s not that important to keep the terms straight.


Much of your interaction with a computer involves controlling processes. You’ll want to start them, stop them, and see what they’re up to. Your primary tool for this is the shell.

5.4 The Shell

The shell is a program that allows you to interact with your computer. It’s called a shell because it provides an environment for you to work in—sort of a little electronic home for you as you compute. (Think hermit crab.)


The simplest function of the shell is to launch other programs. You type the name of the program you want to run, followed by the arguments you want, and the shell asks the system to run the program for you.


Of course, graphical windowing systems also fill this need. Technically, Windows 95 provides a graphical shell, and the X Window system is another kind of graphical shell. But “shell” is commonly used to mean “command-line shell.”


Needless to say, the hackers who work on shells aren’t satisfied with simply launching commands. Your shell has a bewildering number of convenient and powerful features if you would like to take advantage of them.


There are countless different shells available; most are based on either the Bourne shell or the C shell, two of the oldest shells. The original Bourne shell’s program name is sh, while csh is the C shell. Bourne shell variants include the Bourne Again Shell from the GNU project (bash, the Debian default), the Korn shell (ksh), and the Z shell (zsh). There is also ash, a traditional implementation of the Bourne shell. The most common C shell variant is tcsh (the t pays tribute to the TENEX and TOPS-20 operating systems, which inspired some of tcsh’s improvements over csh).


bash is probably the best choice for new users. It is the default and has all the features you’re likely to need. But all the shells have loyal followings; if you want to experiment, install some different shell packages and change your shell with the chsh command. Just type chsh, supply a password when asked, and choose a shell. When you next log in, you’ll be using the new shell.

5.5 Managing Processes with bash

Debian is a multitasking system, so you need a way to do more than one thing at once. Graphical environments like X provide a natural way to do this; they allow multiple windows on the screen at any one time. Naturally, bash (or any other shell) provides similar facilities.


Earlier you used top to look at the different processes on the system. Your shell provides some convenient ways to keep track of only those processes you’ve started from the command line. Each command line starts a job (also called a process group) to be carried out by the shell. A job can consist of a single process or a set of processes in a pipeline (more on pipelines later).


Entering a command line will start a job. Try typing man cp, and the cp manual page will appear on the screen. The shell will go into the background and return when you finish reading the manual page (or you can press q to quit rather than scrolling through the whole thing).


But say you’re reading the manual page, and you want to do something else for a minute. No problem. Press Ctrl-z while you’re reading to suspend the current foreground job and put the shell in the foreground. When you suspend a job, bash will first give you some information on it, followed by a shell prompt. You will see something like this on the screen:


NAME cp - copy files SYNOPSIS cp [options] source --More-- [1]+ Stopped man cp $


Note the last two lines. The next to last is the job information, and then you have a shell prompt.


bash assigns a job number to each command line you run from the shell. This allows you to refer to the process easily. In this case, man cp is job number 1, displayed as [1]. The + means that this is the last job you had in the foreground. bash also tells you the current state of the job—Stopped—and the job’s command line.


There are many things you can do with jobs. With man cp still suspended, try the following commands:


man ls


Starts a new job.


Ctrl-z


Suspends the man ls job; you should see its job information.


man mv


Starts yet another job.


Ctrl-z


Suspends it.


jobs


Asks bash for a display of current jobs. The result looks like this:


{$} jobs [1] Stopped man cp [2]- Stopped man ls [3]+ Stopped man mv {$}


Notice the - and +, denoting respectively the next to last and last foreground jobs.


fg


Places the last foreground job (man mv, the one with the +) in the foreground again. If you press the space bar, the man page will continue scrolling.


Ctrl-z


Re-suspends man mv.


fg %1


You can refer to any job by placing a % in front of its number. If you use fg without specifying a job, the last active one is assumed.


Ctrl-z


Re-suspends man cp.


kill %1


Kills off job 1. bash will report the job information, which will look like this:


$ kill %1 [1]- Terminated man cp $


bash is only asking the job to quit, and sometimes a job will not want to do so. If the job doesn’t terminate, you can add the -KILL[1] option to kill to stop asking and start demanding. For example:


[1] Many people use the signal number -9 instead of the signal name -KILL. However, it’s technically more portable to use the signal name.


$ kill -KILL %1 [1]- Killed man mv $


The -KILL option forcibly and unconditionally kills off the job.


In technical terms, kill simply sends a signal. By default, it sends a signal that requests termination (TERM, or signal 15) but you can also specify a signal, and signal 9 (KILL) is the signal that forces termination. The command name kill is not necessarily appropriate to the signal sent; for example, sending the TSTP (terminal stop) signal suspends the process but allows it to be continued later.


top


This brings the top display back up. Give the u command in top to see only your processes. Look in the right-hand column for the man ls and man mv commands. man cp won’t be there because you killed it. top is showing you the system processes corresponding to your jobs; notice that the PID on the left of the screen does not correspond to the job number.


You may not be able to find your processes because they’re off the bottom of the screen; if you’re using X (see Chapter 9 on page [*]), you can resize the xterm to solve this problem.


Even these simple jobs actually consist of multiple processes, including the man process and the pager more, which handles scrolling one page at a time. You may notice the more processes are also visible in top.


You can probably figure out how to clean up the remaining two jobs. You can either kill them (with the kill command) or foreground each one (with fg) and exit it. Remember that the jobs command gives you a list of existing jobs and their status.


One final note: The documentation for bash is quite good, but it is found in the Info help system rather than the man pages. To read it, type info bash. See section A.1.1 for instructions on using the info program. bash also contains a very good summary of its commands accessible by the help command. help displays a list of available topics; more information about each of them is accessible with the command help topic name. Try typing help cd, for example. This will give you details on the -P and -L arguments recognized by cd.

5.6 A Few bash Features

This section mentions just a few of the most commonly used Bash features; for a more complete discussion see Chapter 6.

5.6.1 Tab Completion

The bash shell can guess what filename or command you are trying to type and automatically finish typing it for you. Just type the beginning of a command or filename and press Tab. If bash finds a single unique completion, it will finish the word and put a space after it. If it finds multiple possible completions, it will fill out the part all completions have in common and beep. You can then enter enough of the word to make it unique and press Tab again. If it finds no completions, it will simply beep.

5.7 Managing Your Identity

Unix-like systems are multiuser, and so you have your own electronic identity as a user on the system. Type finger yourusername to look at some of the information about you that’s publically available. To change the name and shell listed there, you can use the commands chfn and chsh. Only the superuser can change your login (username) and directory. You’ll notice that it says “No plan.” A “plan” is just some information you can make available to others. To create a plan, you put whatever information you want people to see in a file called .plan. To do this you’ll use a text editor; see section 8.2 on page [*]. Then finger yourself to see your plan. Others can finger you to see your plan and to check whether you’ve received new mail or read your mail.


Note that this finger information is available to the entire Internet by default. If you don’t want this, read about configuring inetd and the file /etc/services. Eventually the installation manual will describe this configuration, but for now you might try the man pages or just put nonsense in for your finger information.




About HackerNoon Book Series: We bring you the most important technical, scientific, and insightful public domain books.


This book is part of the public domain. John Goerzen and Ossama Othman (2004). Debian GNU/Linux : Guide to Installation and Usage. Urbana, Illinois: Project Gutenberg. Retrieved https://www.gutenberg.org/cache/epub/6527/pg6527-images.html


This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org, located at https://www.gutenberg.org/policy/license.html.