Linux distribution – complete software system containing the Linux kernel as well as user programs from many different sources. Most distributions have an aim, e.g.,
The GNU Project – started in the 1980s by Richard Stallman project of creating an operating system with open and free source code
Project started with writing free clones of popular Unix tools, leaving creating the kernel for later. The GNU kernel (Hurd) is barely working even today, but many user programs were created, often better than originals. These are used by most Linux distrubutions. That’s why we call them GNU/Linux.
Linux itself is not a part of the GNU Project.
GNU General Public License – free software license. It gives the user of a program the right to get get the program’s source code from the authors for free. The user can further modify and distribute it, but only under GPL.
Moreover, if a program is derived from a GPL licensed work (legally a very grey area), the whole program has to be GPL-licensed (GPL is viral)
Virtual machine is a program that simulates a computer. It allows to install an operating system (guest) without worries about damaging the installed system (host). VirtualBox is a very good free virtual machine. We will install Manjaro KDE. Installation media can be download from here.
Guidelines for Unix programmers:
This means that the system exposes devices and interfaces as special types of files, for which normal operation have special meaning, e.g.,
/procdirectory – allows getting statistics and information from a running system by reading text files
/proc/sysdirectory – allows to change some parameters of a running kernel
Shell — command line interpreter, usually run at the last stage of logging into a system (unless a graphical shell was requested). It waits for user commands and runs requested programs with given arguments.
Historically important shells:
The first character (
$) is the so called prompt. Under default settings it is displayed by the shell. We use the convention that
$ means the command is to be entered as ordinary user (nothing prevents to use them as root). When the command is preceded by
# it means that it should be entered as root (and probably won’t work otherwise).
<command> is looked up in the following order
The search is case sensitive. If a command is not found, shell returns an error.
Arguments are arbitrary strings separated by spaces (or other whitespace). The meaning of the arguments depends on specific command. In most programming languages arguments are passed as an array of strings during execution. In principle the order of arguments matters.
Besides arguments a running command also gets implicitly a list of so-called environment variables. User can change them at will and they can also influence how a program works. We will explore this mechanism later.
The following program in C prints its arguments and environment variables:
Sometimes we want to pass an argument that itself contains a space. We can’t do it like this:
bash not to split arguments on a space we can use any of the following methods:
Of course typing all the commands can be frustrating and is error-prone. Thankfully shell can complete commands and filenames in arguments. We use Tab for completion. If the completion is ambiguous, using Tab twice gives all the possibilities:
Completion mechanism is flexible and extendable. For some commands (unfortunately not for all) there are completion scheme that do more than filenames.
A very useful function allows for searching in commands that have already be entered. Just type Ctrl+R for the magic to happen. Repeat to go back in history. Press Enter to confirm, press Ctrl+C to abort.
Shell is very good when working with multiple files. The globbing mechanism allows to easily operate on them with out typing. Globs are strings that contain metacharacters.
Bash understands the following metacharacters:
*– stands for any string, even an empty one
?– stands for any one character
– stands for any indicated character
*.txt– all files with names ending with
a*b?c– all files with names starting with a, ending with b, any single character nad c
?.py– all files with four character names of which last three are .py
[abc]*– all files with names starting with a, b or c
When shell encounters a glob it replaces it with a list of files that match it, as if we typed it ourselves. Otherwise it leaves the glob as is.
Authors of command line tools make sure that there is no need to type a lot. That’s why some sensible defaults are usually in place. The most common way to change the default action chosen by the programmer are options. The POSIX standard defines functions (
getopt_long) which are widely used in command line programs and hence give a uniform mechanism for processing options.
-l -Ris equivalent to
-vvfor even more details).
As we have already seen many commands give a short help with options
Pager is a program that helps when we want to display more text than possible on one screen. The most often used is called
less. Its basic usage should be intuitive, more can be learned from the help (press h to view it). to quit
less press q.
man displays the pages of the so-called manual. In most cases it is enough to just search for the command that we are interested in. We will also find manual pages for the C library functions and Unix system function (for programmers). Sometimes more than one page matches the query, then one can add the manual section to refine the search. We can search the text using /, we close the manual using q and we can get more help by pressing h.
To search the manual (keywords only, not full-text) you can use
It can be useful if we have only a rough idea about what are we looking for.
A series weaknes of
man is the necessity to write all the help in one document, which leads to some very long manual pages (e.g.,
info program displayes a documentation that can resemble a book, not a page. In particular it can be divided into chapters and can follow hyperlinks.
info is a bit more complicated than
man, mainly because it has to allow to navigate the text:
n– previous page
p– next page
l– go back
H– display short help
The shell keeps track of the so-called current directory (also: current working directory), i.e., the specific directory in the filesystem it believes to be in any moment. This corresponds to the directory displayed in a window of a graphical file manager. This is the directory used by relative paths.
Absolute path is the filename together with all the directories from the root of the hierarchy, e.g.,
Under Linux there is no direct equivalent of the windows drives
D: etc., all drives are mounted in a single directory tree rooted at
/. This means that different directories may in fact live on different drives (even over the network).
Relative path is a path starting in the current directory.
Dropbox/Adiunkt/Dydaktyka/DSOP-EN/Lectures/lecture02.md DSOP-EN/Lectures/lecture02.md ./DSOP-EN/Lectures/lecture02.md ../DSOP-EN/Lectures/lecture02.md
The special directories
.. present in any directory mean: this directory and the parent directory, respectively.
To change the current directory use the built-in
To display the current directory you can use the
pwd command (usually a shell built-in):
popd manage the directory stack. It allows to go back in the history of current directories (like in a browser).
To list the content of a directory you can use the
-R– list subdirectories recursively
-l– print more information
-a– show also hidden files (i.e., starting with .)
-h– use the suffixes K, M, G when displaying size
To copy a file or directory we use the
-R– copy directories recursively
-v– print the names of the files that are being copied
-n– do not overwrite existing files
-i– ask before overwriting
To move a file or directory we use the
-n– do not overwrite existing files
-i– ask before overwriting
To delete a file we use the
There is no trash. All files are deleted permanently.
-r– remove directories recursively
-f– do not ask, igonore nonexisting files
-d– remove empty directories
-i– ask before every removal
To create a new directory we use the
-p– create parent directories if necessary
To remove an empty directory one can use
rmdir, in practice more often one would use
rm -d or
To create a new links we use the
-s– create soft (symbolic) links
Every file under Linux is owned by a user and by a group. We have three groups of permissions: for the owner, for the group and for everybody else. In each group there are three permissions:
read – possibility to read the contents of a file, listing a directory
write – possibility to change the contents of a file, adding/deleting files in a directory
xecute – possibility to run a file as a program, accessing files in a directory
Execute is tricky for directories. If
r is set but
x is not, then one can get names of files in a directory but no other info about the files (size, owner etc.).
Permissions are not additive. For each access only one group of permissions is taken into account. E.g., if the owner tries to read a file and owner is not permitted to read, then access is denied even though everybody else can read the file.
Besides symbolic notation (
rwx) it is common to use octal notation. We get permissions in octal by adding 4, 2 and 1 depending on whether the given file has the read, write, execute permissions respectively. Three octal digits give permission for owner, group and everybody else.
rwx for the owner,
r-- for the group and
-wx for everybody else.
chmod command in symbolic notation allows to add or remove specific permissions:
Using the octal notation
chmod can just fix permissions:
touch command allows to change the last access and modification time for file (default to the current time). It will be useful for us, as nonexistent files are created.
The tool is useful when using
make if we want to force recompilation of a file without changing its contents.