Linux Basics

Linux is inspired by the Unix operating system which first appeared in 1969, and has been in continous use and development ever since. Many of the design conventions behind Unix also exist in Linux and are central to understanding the basics of the system.

Unix was primarily oriented towards the command line interface, and that legacy is carried on in Linux. Thus, the graphical user interface with its windows, icons and menus are built on top of a basic command line interface. Furthermore, this means that the Linux file system is structured to be easily manageable and accessible from the command line.

Directories and File Systems

Linux and Unix file systems are organised in a hierarchical, tree-like structure. The highest level of the file system is the / or root directory. In the Unix and Linux design philosophy, everything is considered a file - including hard disks, partitions and removable media. This means that all other files and directories (including other disks and partitions) exist under the root directory.

For example, /home/jebediah/cheeses.odt shows the correct full path to the cheeses.odt file that exists in the jebediah directory which is under the home directory, which in turn, is under the root (/) directory.

Underneath the root (/) directory, there is a set of important system directories that are common across most Linux distributions that are used. The following is a listing of common directories that are directly under the root (/) directory:

  • /bin - important binary applications

  • /boot - boot configuration files

  • /dev - the device files

  • /etc - configuration files, startup scripts, etc...

  • /home - local users' home directories

  • /lib - system libraries

  • /lost+found - provides a lost+found system for files that exist under the root (/) directory

  • /media - mounted (loaded) removable media such as CDs, digital cameras, etc...

  • /mnt - mounted filesystems

  • /opt - provides a location for optional applications to be installed

  • /proc - special dynamic directory that maintains information about the state of the system, including currently running processes

  • /root - root user home directory, pronounced 'slash-root'

  • /sbin - important system binaries

  • /sys - system files

  • /tmp - temporary files

  • /usr - applications and files that are mostly available for all users to access

  • /var - variable files such as logs and databases

Permissions

All of the files on a Linux system have permissions that allow or prevent others from viewing, modifying or executing. The super user "root" has the ability to access any file on the system. Each file has access restrictions, user restrictions and have an owner/group association.

Every file is secured by the following three sets of permissions, in order of importance:

  • user

    applies to the user who is the owner of the file

  • group

    applies to the group that is associated with the file

  • other

    applies to all other users

Inside each of the three sets of permissions are the actual permissons. The permissions, along with the way they apply differently to files and directories, are outlined below:

  • read

    files can be displayed/opened

    directory contents can be displayed

  • write

    files can be edited or deleted

    directory contents can be modified

  • execute

    executable files can be run as a program

    directories can be entered

To view and edit the permissions on files and directories, open the ApplicationsAccessoriesHome Folder and right-click on a file or directory. Then select Properties. The permissions exist under the Permissions tab and allow for the editing of all permission levels, if you are the owner of the file.

To learn more about file permissions in Linux, read the file permissions page in the Ubuntu Wiki.

Terminals

Working at the command line is not as daunting a task as you would think. There is no special knowledge needed to know how to use the command line, it is a program like everything else. Most things in Linux can be done using the command line, although there are graphical tools for most programs, sometimes they are just not enough. This is where the command line comes in handy.

The Terminal is located in ApplicationsTerminal . The terminal is often called the command prompt or the shell. In days gone by, this was the way the user interacted with the computer, however Linux users have found that the use of the shell can be quicker than a graphical method and still holds some merit today. Here you will learn how to use the terminal.

The original use of the terminal was a file browser and indeed it is still used as a file browser, in the event of the graphical environment failing. You can use the terminal as a file browser to navigate your files and undo the changes that have been made.

Common Commands

View Directories: - ls

The ls (LiSt) lists files in different colors with full formatted text

Create Directories: - mkdir (directory name)

The mkdir (MaKeDIRectory) command will create a directory.

Change Directories: - cd (/directory/location)

The cd (ChangeDirectory) command will change from your current directory to any directory you specify.

Copy Files/Directories: - cp (file or directory name) (to directory or filename)

The cp (CoPy) command will copy any files you specify. The cp -r command will copy any directories you specify.

Remove Files/Directories: - rm (file or directory name)

The rm (ReMove) command will delete any filename you specify. The rm -rf command will remove any directory you specify.

Rename Files/Directories: - mv (file or directory name)

The mv (MoVe) command will rename/move any file or directory you specify.

Find Files/Directories: - locate (file or directory name)

The locate command will search your computer for any filename you specify. It uses an index of the files on your system to work quickly: to update this index run the command updatedb. This command is run automatically each day, if you leave your computer on. It needs to be run with administrative privileges (see the section called “Root And Sudo”).

You can also use wildcards to match one or more files, such as "*" (for all files) or "?" (to match one character).

For a more thorough introduction to the Linux command line, please read the command line introduction on the Ubuntu wiki.

Text Editing

All of the configurations and settings in Linux are saved in text files. Even though you most often can edit configurations through the graphical interface, you may occasionally have to edit them by hand. Mousepad is the default Xubuntu text editor, which you can launch by clicking ApplicationsAccessoriesMousepad on the desktop menu system.

At times in this guide, Mousepad is run from the command line using gksudo, which runs Mousepad with administrative privileges, in order to modify configuration files.

If you need to use a text editor from the command line, you can use nano, which is a simple to use text editor. When running it from the command line, always use the following command, which ensures that the editor will not introduce line breaks:

nano -w

For more information about how to use nano, refer to the guide on the wiki.

There are also quite a few other terminal-based editors available in Ubuntu, popular ones include VIM and Emacs (the pros and cons of each are cause for much friendly debate within the Linux community). These are often more complex to use than nano, but are also more powerful.

Root And Sudo

The root user in GNU/Linux is the user which has administrative access to your system. Normal users do not have this access for security reasons. However, Ubuntu does not include the root user. Instead, administrative access is given to individual users, who may use the "sudo" application to perform administrative tasks. The first user account you created on your system during installation will, by default, have access to sudo. You can restrict and enable sudo access to users with the Users and Groups application (see the section called “Managing Users and Groups” for more information).

When you run an application that requires root privileges, sudo will ask you to input your normal user password. This ensures that rogue applications cannot damage your system, and serves as a reminder that you are about to perform administrative actions which require you to be careful!

To use sudo when using the command line, simply type "sudo" before the command you wish to run. Sudo will then prompt you for your password.

Sudo will remember your password for a set amount of time. This feature was designed to allow users to perform multiple administrative tasks without being asked for a password each time.

[Note]

Be careful when doing administrative tasks, you might damage your system!

Some other tips to using sudo include:

  • To use a "root" terminal, type "sudo -i" at the command line.

  • The entire group of default graphical configuration tools in Ubuntu already use sudo, so they will prompt you for your password if needed.

  • When starting graphical tools with "sudo", run it with "gksudo" instead. This will open a small graphical window that prompts the user for his password. "gksudo" is convenient if you want to set up a launcher for Synaptic on your panel, or something similar, where you would normaly not have the possiblity to enter your password.

  • For more information on the sudo program and the absence of a root user in Ubuntu, read the sudo page on the Ubuntu wiki.

More Help

An incredible amount of information about Linux is available on the Internet. To get started, I recommend the excellent and comprehensive tutorial Getting Started with Linux.

For people who already know the basics, the tutorial Intermediate Level User Linux Course is a good read.