How linux works

From Club Ubuntu

Jump to: navigation, search

Contents


Background and History

An Operating System has two major parts - the kernel, or the part of the system that can talk directly to the hardware, and everything else, which can only interact with the kernel. The kernel also makes sure that the various other programs running on the operating system play nice with each other and share the hardware resources. See the wikipedia article for more information.

Linux and GNU

Linux is, strictly speaking, only a kernel. It can't do much of anything on its own without being told to do so by other programs. GNU is, on the other hand, a collection of programs and utilities needed to make up a basic operating system(and some more advanced programs that aren't strictly needed). Without a kernel such as Linux, GNU is mostly useless, and without systems utilities like GNU, Linux is also useless. In this way both GNU and Linux complement each other, which is why you may hear such a system referred to as GNU/Linux.

GNU/Linux Basics

Basic Commands

The most basic way of interacting with a Linux system is through a command line. A command line environment is provided by a shell, usually Bash by default. Most of the commands you will use are either built in to the shell, meaning the shell interprets the commands directly, or contained in a packaged called GNU coreutils. If the shell sees a command it doesn't have a builtin for it will look for a program with the name of the command in the current PATH. Some of the most popular commands are listed below.

Key:

  • Arguments enclosed in angle brackets (<>) are required for the command to run
  • Arguments enclosed in square brackets ([]) are optional

uname

Displays basic system information.

uname -a

cat

Concatenate a file with another file. By default the second file is stdout (your terminal screen). Accepts an infinite amount of arguments

cat <first file> [second file] [etc...]

You can output a text file using cat. EX:

cat <file>

To combine two text files:

cat foo bar > new

cp

The "cp" command copies files. Similar to "copy and paste" in a GUI file manager. Accepts an infinite amount of source files to copy, but if you have more than one file, it must be copied to a directory, not a file

cp <source> <destination> [destination] [etc...]

man

Display a manual page. Different types of pages appear in different sections, but if you don't specify it will find The Right One.

man [section] <page>

mv

mv has 2 functions: move and rename. It will rename files on the same partition (Renaming in this context isn't just changing the filename, but moving it without actually moving things from drive to drive), and it will physically move destinations on another partition via copying to the other partition, then deleting from the first partition.

mv <file> <destination>

rm

rm deletes a file. Note that you can delete an infinite amount of files using one command (just keep piling more files into the argument list)

rm <file> [file1] [etc...]

To delete a directory:

rm -r <directory>

ls

ls lists files within a directory. It also can be used to check if a file exists, because it will return the path to the file if it encounters a non-directory. Note that, as rm, it will accept an infinite amount of arguments.

ls [directory or file] [etc...]

mkdir

mkdir creates a folder within the active directory. Mkdir accepts as many arguments as you want.

mkdir <directory> [etc...]

less

less views text files in a separate program. You can use PgUp and PgDn to navigate. To quit, use q.

less <file>

echo

echo prints text to somewhere. To print text to the screen:

echo "Hello"

To append "Hello" to file foo:

echo "Hello" >> foo

ln

ln provide the possibility to add symlinks or hardlinks in linuxsystems:

To create a symlink:

ln -s [src] [dest]

Example:

ln -s ~/Desktop/MyFolder /usr/bin/link-my-folder-here

Directory Structure

/

Root, or the top of the directory structure. Every other directory is a child of this one.

/bin

Basic system utilities usable by users and administrators. Things like ls and cat are here.

/sbin

Basic system utilities only usable by administrators, which means they usually require root access to run. Things like filesystem maintenance(fsck) and network(ifconfig) utilities are here.

/etc

Configuration files.

/usr

System-added files. Whenever you install something with a package manager such as apt it usually goes here. Things contained here are generally not needed for the system to run, but provide useful things like X11.

Note on filesystem layout

Traditionally /usr was placed on a separate partition/drive from the rest of the filesystem, like /bin and /sbin. This is why system-critical utilities are placed directly under / in /bin and /sbin, so that if the drive with /usr ever goes offline basic diagnostics can still be performed.

"Everything is a file"

/dev, /proc and /sys

FUSE

X11

Graphics Drivers

OpenGL

Advanced Topics

Kernel Modules

Shared Libraries

Memory Management

Personal tools
community