Professional Documents
Culture Documents
Latest Version Here: Here Ubuntu Introductory Guides
Latest Version Here: Here Ubuntu Introductory Guides
What Is GNU/Linux?
GNU/Linux is an operating system comprising of the Linux kernel, GNU tools
and utilities, eventually a graphical desktop environment like KDE or GNOME,
and all other user applications and games. A Linux distribution like Ubuntu,
Mint or Fedora takes all these parts, puts them together and further provides
CD/DVDs, ISO images, support and a package management system for installing
and removing applications. There are several big distributions out there upon
which other projects build on. For example, there is Debian, on which Ubuntu is
based. Mint is another growing distribution which is based on Ubuntu. You can
read the Introduction to Linux and Ubuntu for a more in-depth information
about Linux and distributions using it.
What Is a Shell?
A shell is a command interpreter which allows you to interact with the
computer. The way things work is pretty simple: you type in commands, the
shell reads them, performs the tasks it was asked to do, and nally it sends the
results to the standard output, which is usually the screen. Here is an example
output of the ls command, which lists the les in a directory:
mintuser@mint:~ > ls
Desktop Documents Downloads
Music
Pictures
Projects
Videos
This is a list of les inside the the home directory. The home directory contains
all your personal les and folders, as well as conguration settings for installed
applications, downloads, music and so on.
1 of 7
2 of 7
3 of 7
The rst argument is the command itself (like ls or echo), the second
argument can be an option or a list of options to pass to the command (for
example to show or hide hidden les), while the third is a lename upon which
the command may make changes. For example:
mintuser@mint:~ > ls -l /
total 96
drwxr-xr-x
2 root
root
drwxr-xr-x
3 root
root
drwxr-xr-x 15 root
root
drwxr-xr-x 159 root
root
4096
4096
4380
12288
Will list all the les inside the / directory (also called root directory), using the
long listing format (which was specied by the -l option).
A command may or may not have arguments. An argument can be an option or
a lename. Here is another example:
[embryo@mint] ~$ echo -e "Hello, world\n"
Hello, world
[embryo@mint] ~$
This will output the text Hello, world, followed by a newline character. The -e
switch tells the echo command to interpret escaped characters, like the
trailing \n, which will add a newline after the text inside the double-quotes.
Without the -e switch, the output would have been this:
[embryo@mint] ~$ echo "Hello, world\n"
Hello, world\n
Now let's proceed and type in some basic commands to become familiar with
the shell environment.
Moving Around Using cd and pwd
Usually when you start a terminal the default starting location (called the
current working directory) is your home folder, /home/USER, where USER
4 of 7
The cd command is used to change the current directory. And now let's list all
the les inside this folder:
[embryo@mint] /$ ls /
bin
dev floyd initrd.img
boot etc home
initrd.img.old
[embryo@mint] /$
lib
lost+found
media
mnt
opt
proc
root
run
sbin
selinux
srv
sys
tmp
usr
var
vmlinuz
28
28
28
28
28
28
05:13
05:12
05:12
05:12
05:12
05:12
baseq3
COPYING
demoq3
id_patch_pk3s_Q3A_EULA.txt
ioq3ded.i386
ioquake3
You can also group options. For example, ls -l -h -G /usr/bin can be written as
ls -lhG /usr/bin and it will list all les inside the /usr/bin directory, using
detailed, long listing format (-l), showing sizes in human readable format (-h)
and supressing the group details (-G):
[embryo@mint] ~$ ls -lhG /usr/bin
total 433M
5 of 7
vmlinuz.o
-rwxr-xr-x
lrwxrwxrwx
-rwxr-xr-x
-rwxr-xr-x
...
1
1
1
1
root
root
root
root
38K
8
39
40
ian 17 2013 [
sep 9 18:39 2to3 -> 2to3-2.7
feb 17 2012 7z
feb 17 2012 7za
Another useful argument is -a, which will also show hidden les (les that start
with a dot like .bashrc). Try it in your home directory!
Absolute and Relative Paths
An absolute path is a complete path to a given point, and it always starts with
the root directory (the forward slash: /). Examples of absolute paths: /usr/bin,
/etc/apt/cache, /home/USER. As you can see, they are all absolute paths since
they specify the complete path up to a certain point.
On the other hand, a relative path will not start with the forward slash, and it
will always take into consideration the current working directory. For example,
if the current directory is /home and you would like to change it to
/home/USER/Downloads, you could do it like this using an absolute path:
cd /home/USER/Downloads
In this example we specied the full path to the Downloads diretory, or the
absolute path. Notice the leading forward slash for root. To do it using a relative
path we would issue this command:
cd USER/Downloads
Notice that the forward slash is missing, and the shell will prex the path
specied by cd with the path of the current working directory, which is /home,
thus resulting /home/USER/Downloads. When specifying a relative path, the
shell takes into consideration the current directory, and starts the search for the
specied le or directory from there.
The . and .. Files
These are virtual les, the single dot meaning the current working directory,
while the double dot means the parent directory of the current working
directory. These may seem strange, but they are actually very useful when
working in a shell. For example if you are inside your home directory and you
want to copy a le from some location to the current working directory you
could do something like:
6 of 7
cp /etc/apt/sources.list /home/USER
As you can notice, you specify your current working directory. Still, this can be
done by typing less text, like this:
cp /etc/apt/sources.list .
Notice how the . tells cp to copy the sources.list le inside the current working
directory.
Use .. to go up one level in the hierarchy, to the parent directory. For example, if
you are inside /etc/apt/sources.list.d and you would like to go to /etc/apt, you
could use:
cd ..
This concludes the introductory chapter on shell basics. The next chapter will
focus on showing and explaining some useful general-purpose commands,
including copying and removing les, creating les and directories, showing the
date and time, viewing les with cat, head and tail, searching for les and
getting help.
Resources
This tutorial is based on this guide, written a while ago. This version further
details several aspects of the shell, as well as adding new commands and
explanations for some Bash features.
LinuxCommand.org - Easy to understand, must-read guide designed for
beginners about the Linux command-line
Introduction to Linux by Machtelt Garrels - Very good introduction to Linux
command-line, with real-life examples
The UNIX Programming Environment by Mark Burgess - Introduction to
UNIX, including Bash and Perl programming guides
7 of 7