You are on page 1of 27

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/312970940

Linux System For Telecom Networks

Chapter · January 2017

CITATIONS READS

0 1,768

1 author:

Boualem Merabet
University Mustapha Stambouli of Mascara
62 PUBLICATIONS   143 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

semiconductors materials and laser View project

speech classification for children with ASD View project

All content following this page was uploaded by Boualem Merabet on 27 January 2017.

The user has requested enhancement of the downloaded file.


Understanding Linux operating System
History
 Linux is a member of the UNIX family of operating systems. Linux system as it exists today is the
GNU project and the development of the Linux kernel.
 In 1969, the same year that Linus Torvalds was born, the 1st UNIX implementation was developed
by Ken Thompson at Bell Labs, a division of the Telephone corporation, AT&T.
 UNIX as a name was a pun on Multiplexed Information and Computing Service, the name of an
earlier operating system project in which AT&T collaborated with Massachusetts Institute of Technology
and General Electric.
 In 1970, UNIX was rewritten in assembly language for a newly acquired Digital PDP-11 mini-
computer, then a new and powerful machine.
 Dennis Ritchie, one of Thompson’s colleagues at Bell Labs and an early collaborator on UNIX, a
short time later, designed and implemented the C programming language.
 By 1973, C had matured to a point where the UNIX kernel could be almost entirely rewritten in
the new language. The C genesis explains why it, and its descendant C++, have come to be used so widely
as system programming languages today.
 Previous widely used languages were designed with other purposes in mind: FORTRAN for
mathematical tasks performed by engineers and scientists; COBOL for commercial systems processing
streams of record-oriented data.
 UNIX First through Sixth editions Between 1969 and 1979, UNIX went through a number of
releases (editions). These releases were essentially snapshots of the evolving development version at AT&T.
In 1994, Salus notes the following dates for the first six editions of UNIX.
 "Linux" is a term commonly used to refer to the entire UNIX-like operating system of which the
Linux kernel forms a part. However, this is something of a misnomer, since many of the key components
contained within a typical commercial Linux distribution actually originate from a project that predates
the inception of Linux by several years.
 In 1984, Richard Stallman, an exceptionally talented programmer who had been working at MIT,
set to work on creating a “free” UNIX implementation: 'GNU Project'. Stallman’s outlook was a moral one,
and free was defined in a legal sense, rather than a financial sense.
 In 1985, He founded the Free Software Foundation, a nonprofit organization to support the GNU
project as well as development of free software in general.
 By the early 1990s, GNU project had produced a system that was virtually complete, except for one

1
important component: a working UNIX kernel. The GNU project had started work on an ambitious kernel
design, known as the GNU/HURD, based on the Mach microkernel.
 In 1991, Linus Torvalds, a Finnish student (University of Helsinki) was inspired to write an opera-
ting system for his Intel 80386 PC. In his studies' course, He had come into contact with Minix, a small
UNIX-like operating system kernel developed in the mid-1980s by A. Tanenbaum, a university Prof. in
Holland.
 The earliest distributions of Linux appeared in 1992, and included Manchester Computing Centre
(UK) Interim Linux, Texas A&M University, and Soft Landing Linux System.
 In 1993, 'Slackware' the oldest surviving commercial distribution appeared; the noncommercial
Debian distribution appeared at ~ the same time, and SUSE and Red Hat soon followed.
 In 2004, the currently very popular Ubuntu distribution first appeared.
 Nowadays, many distribution companies also employ programmers who actively contribute to
existing free software projects or initiate new projects.
 In 2008, a less wide-ranging revision of the standard was completed, yielding the combined POSIX
1003.1-2008 and SUSv4 standard. Unlike most commercial UNIX implementations, Linux separates
implementation from distribution: no single “official” Linux distribution. Each Linux distributor’s offering
consists of a snapshot of the current stable kernel, with various patches applied. LSB develops and
promotes a set of standards for Linux systems to ensure binary application compatibility across Linux
distributions, so that compiled applications should be able to run on any LSB-conformant system running
on the same hardware.

Installing Ubuntu (Setup)


A strong effort has been undertaken to make Ubuntu easy to use, so even novice computer users should
have little trouble using it. There are many different guides on the web about how to install Ubuntu but
installing as a virtual machine on our current computer is recommended, see separate documentation for
instructions. The Ubuntu Linux distribution is generally easy to use and it is updated (for free) every 6
months. At the time of writing, the current version of Ubuntu is 16.04.1 LTS "Xenial Xerus. To do the
setup, we will be instructed to do 3 things :
Do some things in our shell (command line, Terminal, PowerShell); Learn about what we just did;
Do more on our own. First we'll be expected to get our Terminal open and working. Get our Terminal,
shell, or PowerShell working so we can access it quickly and know that it works. Hold down the
command key and hit the spacebar. In the top right the blue "search bar" will pop up. Type: terminal.
Click on the Terminal application that looks kind of like a black box. This will open Terminal. We can
now go to our dock and CTRL-click to pull up the menu, then select Options->Keep In dock.

2
Now we have our Terminal open and it's in our dock so we can get to it.
* Look through the menu for our Win manager for anything named "Shell" or "Terminal."
On Win we're going to use PowerShell; people used to work with a program called cmd.exe, but it's not
nearly as usable as PowerShell.
*If we have Win7, Click Start. Type: powershell in "Search programs and files". Hit Enter. *If we don't
have Win7, we should seriously consider upgrading, or try installing it from Microsoft's download center.
Search online 'powershell downloads' for our version of Win.
A lot of documentation is installed on the machine itself: we can access this by moving the mouse towards
Ubuntu Desktop at the top left of the screen and clicking on the help menu that appears. the name of the
program we are currently using is displayed at the top-left of the screen and moving the mouse to top of
the screen will reveal the programs menus in a similar fashion to how they are displayed on the Mac.
*To get help, click on the circular symbol (a stylised picture of three people holding hands) at the top left
of the screen and type help in the search box that appears. For better names, refer to the people-holding-
hands button as the Ubuntu.
* how to get an open terminal? 'Bash' is the most important thing we must learn on Linux.
*'zsh' will give us 30 more IQ points and win us millions in the stock market: Right! but, our goal is to
get capable enough and at this level it doesn't matter which shell we use.
"rm -rf /" is a classic command that we must never type. If we need help, make sure we get it from
someone we trust and not from random idiots on the internet.

# usually after this symbol a comment (on an ex.) start.


Bold & Italic texts are what to type in at the command-line, & a reply from computer to what was typed in
cd # ensure that we are in the home directory. for the present work directory, type
pwd
/home/merabet # merabet is the user's name
Download & unpack examples when it's needed wget -O - 'http://tinyurl.com/32a2gbk/unix.tgz' | tar -zx
*A free equivalent exist for most software we might use and we can browse those available by clicking on
the 'Ubuntu Software Centre', which s just a starting point, whose icon at the left of the screen looks like
a shopping bag full of goodies. There are prepackage software & source code that will require compi-ling.
Unix has traditionally been more mouse centered with the left mouse button used to highlight text and
the middle button used to copy it. *Starting applications from icons, opening folders, etc... only requires a
single click, rather than the double click required on Win, making the action of pressing buttons and
selecting things from menus more consistent with each other. double clicking will generally result in an
action being done twice.
* While Ubuntu has all the graphical tools we might expect in a modern operating system, so new users
rarely need to deal with its Unix foundations, we will be working with the command-line. But, why the
command-line is still the main way of interacting with Unix? Because the origins of Unix predate the
development of graphical interfaces; this is what all tools & programs have evolved from. the command-
3
line remains popular is that it is an extremely efficient way to interact with computer. *If something
complex enough to be done is wanted that there isn't a handy button for it, graphical interfaces force us
to go through many menus and manually perform a task that could have been automated. Unix is built
around many little tools designed to work together. Each program does one task well & returns its output
in a form easily understood by other programs & these properties allow simple programs to be combined
together to produce complex results. Unix is reported as :
– Make each program do one thing well. To do a new job, build afresh rather than complicate old
programs by adding new features.
– Expect the output of every program to become the input to another, as yet unknown, program. Don't
clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't
insist on interactive input.
– Design and build software, even operating systems, to be tried early, ideally within weeks. Don't
hesitate to throw away the clumsy parts and rebuild them.
– Use tools in preference to unskilled help to lighten a programming task, even if we have to detour to
build the tools and expect to throw some of them out after we've finished using them." The terminal
program can be found by clicking on Ubuntu button & typing terminal in the search box, as shown below:

*
"prompt" is the command-line showing that the computer is ready to accept commands. prompt is text of
the form user@computer:directory$ : tim in the directory ~ on a computer called 'coffee-grinder'.
"prompt" is configurable and may vary between computers.

4
* pwd does not agree with the command prompt, instead printing /home/merabet. This is because ~ is a
synonym for /home/merabet
Basical Unix Commands
* whoami Our username
* uname Operating system (uname -a for the full details).
* pwd : print working directory
* hostname : my computer's network name (Name of machine being used)
* mkdir : make directory
* cd : change directory
* ls : list directory
* rmdir : remove directoryenv
* pushd : push directory
* popd : pop directory
* cp : copy a file or directory
* mv : move a file or directory
* less : page through a file
* cat : print the whole file
* xargs : execute arguments
* find : find files
* grep : find things inside files
* man : read a manual page
* apropos : find what man page is appropriate
* env : look at our environment
* echo : print some arguments
* export : export/set a new environment variable
* exit : exit the shellDANGER! become DANGER!
* sudo : DANGER! become super user root DANGER! pwd
Drill! until we can say such phrases right away when we see that word, & so that we read the phrase and
know what command will do that; we're building our vocabulary by doing this, but don't spend so much
time we go nuts and get bored.

Files and directories in Unix


In Unix, files are arranged in directories represented as tree branches leading from a single trunk “root”,
and may have other branches leading from them, directories inside directories, and individual files are the
leaves of the tree. For ex. :

5
*Where Unix differs from other operating systems is that the filesystem is used much more for organising
different types of files: essential system programs are all in /bin and their shared code (libraries) are in
/lib; similarly user programs are in /usr/bin, with libraries in /usr/lib & manual pages in /usr/share/man.
* How to specify the file or directory location ?
– The absolute path and the relative path from where we currently are (current working directory : pwd)
in the filesystem. The 1st path is one that starts at the root and does not depend on the location of the
current working directory. Starting with a / to signify the root, the path describes all the directories
(branches) we must traverse to get to the file, each directory name separated by a /. For
ex.,/home/user/Music/TheKinks/SunnyAfternoon.mp3
* the paths of web pages are also separated by forward-slashes, revealing their Unix origins as a path to a
file on a remote machine. A few directories have special symbols that are synonyms for them and the
most common are as listed below :
/ root directory (for going to top of pyramid)
. current directory
.. parent directory
~ home directory (a synonym for $home
* A file in the current directory can be referred to by its name, a file in a directory inside our working
directory can be referred to by directory/filename (and so on for files inside of directories inside of
directories inside of our working directory, etc...).
* Such paths are very similar to how we describe absolute paths except that they do not start with /
* Absolute paths are relative paths relative to the root; Initial / could be read as “goto root”

6
* The directory above the current one can be referred to as .. so, if the working directory is /home/user,
then the root directory can be referred to as ../.. (go up one directory, then go up another directory).
* The symbol .. can be freely mixed into paths: the directory 'examples' below the current directory could
have path 'examples/../examples/../examples' (recommended : simply using just 'examples').

Commands in more details


Have the predicable format 'command -flags target', commands are just programs elsewhere on the
computer; entering their name on the command-line runs them, where a :
* Command is the 'program to run's name,
* Flag (being optional) modifies its behavior, and
* Target (often a file's name) is what a command is to operate on, though many commands require
neither flags nor target.
*It's worth mentioning that among directories there are special ones to contain executable programs and
programs within them can be run by typing their name at the command-line. *Generally we will not have
permission to place files in these directories; experienced Unix
users create their own, normally ~/bin/, to place programs they are frequently using.
* Being not in a special directory, a program cannot be run just by typing its name: our computer doesn't
know where to find it even if the program is in the current directory.
* A program not in a special directory can still be run, but one has to include the path to where it can be
found; this can be a program in current directory ./program, to a more complex absolute path to somewh-
ere where shared programs are kept, but we can always use the command-line's auto-completion features,
to reduce the amount of typing needed.
* Creating a directory does not make it special. $PATH is a variable, that is a directories' list in which
computer looks for programs; the 'export PATH=~/bin:$PATH' command appends the new directory to this
list. Such command is often added to the file ~/.bashrc (a list of commands to be run automatically every
time a new terminal is opened).
– something useful :
'Ctrl-a' (move to line beginning); 'Ctrl-e' (move to line end); 'Alt-f'(move forward 1 word); 'Alt-b'(move
backward 1word); 'Ctrl-l'(clear screen, leaving line); 'Tab' auto-complete path.
* Do some things in our shell (command line, Terminal, PowerShell); Learn about what we just did; Do
more on our own. Get our Terminal, shell, or PowerShell working so we can access it quickly and know
that it works.
* On Windows we're going to use PowerShell. People used to work with a program called cmd.exe, but
it's not nearly as usable as PowerShell.
–If we have Win7, we click Start. In 'Search programs and files' type powershell, Hit Enter.
–If we don't have Win7, we should seriously consider upgrading. If we still insist on not upgrading then
we can try installing it from Microsoft's download center. Search online to find "powershell downloads"

7
for our version of Windows. We are on our own, though, since we don't have Windows XP, but hopefully
the PowerShell experience is the same.
* Now, let's practice!
whoiam
merabet
pwd
/home/merabet
ls
Desktop Downloads Pictures Templates Video
Documents examples.desktop Quran Public Unbutu One
# Change to a different directory - don't press Enter yet
cd D
# Pressing tab once has no effect since there are three possible options.
# Pressing tab again lists the three options, note that cd D remains on the
# command-line for further editing.
cd D <tab><tab>
Desktop/ Documents/ Downloads/
# Press e to disambiguate options, and tab again complete.
cd De <tab>
# Gives
cd Desktop/
* 'history' is a command used to list commands we have entered (record kept): 'Ctrl-e' starts a search;
typing 'enter' accepts the current line, typing 'Ctrl-r' again goes to the next match and 'Ctrl-g' cancels
search. History can also be referred to by entry number.
*Many commands for manipulating files are used; these have short names, two or three let-ters; errors
typing can easily have unintended & severe consequences – be careful what we write because Unix rarely
gives we a 2nd chance to correct mistakes (some Unix machines have the sl command to encourage
accurate typing). Most useful commands are in details:
– change the working directory :
cd path # Change working directory to path
cd # Change to home directory
cd - # Change to previous directory
– copy a file from place to another :
cp file1 file2 # copy file1 to file2
cp file1 directory/ # copy file1 into directory. The copy of the file has path directory/file1
cp file1 file2 directory/ # copy file1 and file2 to directory. When copying multiple files, the destination
must be a path to a directory.
– LiSt contents of directory :
ls # List files
ls -a # Also show hidden files (those whose name begins with a period).
8
ls -l # Show more information about each file (permissions, owner, group, time and date of last
modification).
– MaKe (create) a new DIRectory
mkdir path # Make directory described by path
mkdir -p directory1/directory2 # Make the directory described and all directories leading to it (its Parents)
if necessary.
– MoVe (rename) a file: exactly like cp except that the file is moved rather than copied.
mv file1 file2 # Rename file1 to file2
mv file1 directory/ # Move file to directory
mv file1 file2 directory/ # Move files to directory.
– ReMove (delete) a file. Deletion on Unix machines is permanent and instantaneous; no trash
directory to save we from our mistakes exist.
rm file # Remove file
rm directory # Fails, can't remove directories
rm -r directory # Recursively descend into directory and delete everything, including other directories
inside of it (hence the recursively). This will remove the directory
rm -f file # Force (ignore warnings) file's removal; ignoring warning includes read-only files.
– ReMove a DIRectory: Only empty directories can be removed (hidden files included).
rmdir directory
# How to remove files & directories?
pwd
/home/merabet/unix/MoveCopy
# Some files are not read-only (answer "y")
rm read-only
rm: remove write-protected regular empty file 'read-only'? y
# Some files are not ours
rm /dev/null
rm: remove write-protected regular file 'dev/null'? y
rm: cannot remove 'dev/null' : Permission denied
# rm will not delete directories
rm test
rm: cannot remove 'test' : Is a directory
# rmdir will only remove empty directories
rmdir test
rmdir: 'test': Directory not empty
ls test
english
rm test/english
rmdir test
ls tests

9
english subdirectory
# rm -r (-r =“recursive”) deletes everything, including subdirectories
# danger - a mistake using this option can result in a lot of work being
# accidentally deleted
rm -r tests
# How to Escape examples
pwd
/home/merabet/examples/unix/Escaping
ls
my sequences.fasta sequence_directory
# Incorrect version. Space in name treated as command-line argument separator.
# “my” and “sequences.fasta” treated as separate files.
mv my sequences.fasta sequence_directory
mv: cannot stat `my': No such file or directory
# The wrong file has been moved
ls sequence_directory
sequences.fasta
# Correct version, the space is escaped to remove its special meaning.
mv my\ sequences.fasta sequence_directory
ls sequence_directory
my sequences.fasta sequences.fasta
# If we use “tab completion” to complete names, spaces and other characters
# are automatically escaped for us.
* Hidden files are those important for computers or programs, containing configuration information not
intended for users; files that begin with . characters are by default hidden & won't appear in the ls output.
pwd
/home/merabet
# Show ordinary files
ls
doc-samples examples
# Show all files. Note the special directories . and .. are visible.
ls -a
. .bash_history .bashrc .directory .mpd.conf examples
.. .bash_logout .config .kde4 .ssh
.Xauthority .bash_profile .dbus .local doc-samples
# Show only hidden files. For more details, see Dealing with multiple files.
ls -d .*
. .Xauthority .bash_logout .bashrc .dbus .kde4 .mpd.conf
.. .bash_history .bash_profile .config .directory .local .ssh

* How to Read & write permission?


Any file or directory has a permissions' set associated with it, that describes who is allowed to read or

10
write a file. 3 among these are basic: read, write & execute. 3 categories of user exist : owner u, group, &
other; permissions of each file are described as a string of 9 characters, 3 for each user category. Each
category has a triplet which is either a letter 'rwx' if a user in that category has the corresponding
permission or '-' if he don't. rwxr-x--- is a permission string meaning that owners have permission to read,
write or execute, users in the same group have read & execute permission, but other users have no
permissions.
* Let's practice!
pwd
/home/merabet
id
uid=512 (merabet) gid=100(users) groups=6(disk),7(lp),11(floppy), ↩
17(console),27(video),80(cdrw),100(users),512 (merabet),1002(boinc) ↩
,65533(nogroup),65534(nobody)
# User merabet has ID 512, in group users by default (Group ID 100).
# 'd' as an initial means that both 'doc-samples' and 'examples' are directories. The files' owner
is merabet and they are part of the 'users' group.
mkdir test
ls -l
drwxr-xr-x 14 merabet users 352 Mar 22 14:02 doc-samples
drwxr-xr-x 3 merabet users 72 Mar 22 17:42 examples
drwxr-xr-x 2 merabet users 48 Mar 26 14:09 tests
# merabet has read, write and execute permission for both directories; users in the
# group users have read and execute permission, as do any other users.
# Remove execute permission for all users (a means u, g and o)
chmod a-x test
# Now we can't open the directory.
cd test
-bash: cd: test: Permission denied
# Give ourselves permission to enter directory.
chmod u+x test
# This now succeeds but nobody else will be able to enter
cd test
# Make all files in and below a directory read-only. The -R flag means
# recursively
chmod -R a-w test
Remark : As file owners, we can change its permissions to be anything; some programs do automatically
this for us, giving impression that permission has been ignored; by default
rm will prompt to remove write-protected files, but the -f (force) flag turns tells it not to bother asking &
just remove the file; running rm -f is possibly the only time we might run into this behavior.

11
How about multiple files?
It's desirable, especially when running scripts or organizing files, to deal with multiple files at once;
instead of a filename, we give the computer a pattern (just a filename containing symbols that have a
special meaning) rather than typing each file name out explicitly; any filename is checked against the
pattern & it's automatically replaced by a list of matching files before running a command; for ex, * & a*b
match respectively anything & any filename (pattern) beginning with a & ending with b.
The following special symbols (useful for constructing patterns) match......:
* anything, including match “nothing”
\* a '*' character (any symbol here can be prevented from having a special meaning by
“escaping” it with a '\').
? any character exactly once (excludes matching “nothing”)
[abc] exactly one of 'a', 'b' or 'c'
[^abc] or [!abc] any character but 'a', 'b' or 'c'
[c-y] any character between 'c' and 'y'. [-a] is defined to mean a match with '-' or 'a'.
{pattern1,pattern2} combines pattern1 & pattern2 results together; a file matched by both patterns returned twice.
Before a command is run pattern matching occurs; the command never sees patterns, just match results; it
can have unintended consequences, which can be dangerous! Look at this ex.:
pwd
/tmp
Create a file called -rf *
touch -- -rf\ \*
* It will very bad to type rm -rf *, since * matches everything, r means recursively descend down all
directories matched, & f forces deletion even if the file is important or write-protected; other ways exist to
safely delete a file :
rm -- '-rf *': -rf * stop the filename being interpreted as a pattern; -- prevents rm (& most commands) from
interpreting anything after it as a flag, so -rf is just a name not the recursive & force flags.

When multiple programs are run


Unix was first designed to run more than 1 program at once on remote machines & support for this is
integrated into the command-line; between foreground & background jobs, the important distinction is
that the first job replaces temporarily the command-line; we cannot enter new commands until it has
finished (only this job receives input from a keyboard), so interactive programs like PAUP* should be run
as foreground, whereas the second job runs independently & allows us to continue with other tasks; it still
send its output to stdout, our terminal unless we have redirected it somewhere else; this can be confusing
when running multiple background jobs, whose output will be interleaved without any indication of
which line came from which job; let's now have few commands & key combinations for job control
Ctrl-c Cancel (kill) foreground job
Ctrl-z Pause foreground job
jobs List current jobs (started in this command-line)

12
kill %n Kill job number n
killall name Kill all processes called name
ps Show all running processes (distinct from jobs) regardless of how they were started
fg %n Bring job number n to foreground
bg %n Run job number n in background
program & Start program in background
nohup program Run program in background so it will not stop if we log out. stdout & stderr are redirected
to nohup.out file; advanced user might like looking at screen instead.
*The difference between 'jobs' & 'processes' is that a process is a single program running on the machine;
all processes we are running, including the command-line itself, can be listed using ps (or ps -a if we want
to see what all the other users of the machine are doing; a command-line is another process running on a
computer); while a process is the fundamental method of keeping track of what is running on a computer,
a job is things entered on a command-line; many jobs include more than 1 program logically connected
together by pipes to achieve a task, & a command-line splits jobs into several processes & runs them,
possibly simultaneously.
* Unix commands (where possible) written as filters, read from inputs, manipulate data & write outputs.
This enables simple commands to be combined to produce complex results. * All command read from
stdin and write to stdout (by default connected to the current command-line, thus results are displayed on
the screen) and can be redirected; '> filename' redirects stdout to the file specified for later perusal.
* A pipe, rather than redirecting to a file, can be used to connect stdout of 1 command to the stdin of
another, by chaining many simple commands together, thus complex transformations of the input can be
achieved. Let's take ex. below, showing how complex outputs could be achieved using a smaller steps' set :
pwd
/home/merabet/examples/unix/Pipes
cat transcripts.file.gz | gunzip |
grep '^>' |
cut -d '|' -f 1 |
sort | uniq -c > transcript_counts.txt
cat transcripts.file.gz | gunzip | grep '^>' | cut -d '|' -f 1 | ↩
sort | uniq -c > transcript_counts.txt
Before typing commands, comments are provided successively, as follow :
At the command-line, a pipe is represented by the character |. How many transcripts there are for each
gene? first cat reads the file and writes it to stdout, pipe into the decompression program gunzip. Another
pipe into grep, a tool that extracts lines matching a certain pattern (here, those starting with a >).Sequence
names in the file file are of the form >gene_ID|transcript_ID; cut splits a line to bits; use | as delimiter &
we want the first field. Single quotes prevent the '|' being interpreted as a pipe by the command-line. Sort
& count the unique entries (uniq requires sorted input) Output to file transcript-counts.txt. Or on one
line, redirecting stdin in a similar way to how we redirected stdout before. < transcripts.file.gz connects
stdin of gunzip to transcripts.file.gz file rather than using cat to read it and output it into a pipe.

13
Unix basic administration commands [Networking Unix commands–for Telecoms] : ping, ifconfig, ifup,

ifdown, netstat, rlogin, ssh; ping is used a lot to see if a machine in our network is up/down,
In the ex. above ping 192.168.0.1 # 'machine 192.168.0.1' is "up", it sends packets

4 packets transmitted (only), 4 received, and 0% packet loss.

4 packets transmitted, 0 received, and 100% loss

14
ping -c4 192.168.0.1 -q #don't show what's happening, just tell me the result at the end.

result: PING 192.168.0.1 (192.168.0.1) 56(84) of data, thus what happens in between?
ping c4 192.168.0.1 -v

Local loopback address

2 packets transmitted, 0 received, and 100% loss


ifconfig # it shows us the configuration of our interfaces (on our machine)

ifup lo # wireless line interface could be configured, but local loopback address in our offices is not.

We need superuer/password & type ifconfig again, it show us that local loopback is 'up'
Then, let's ping the local loopback address :

It shows us what's happening : 56(84) bytes of data......; Now, interfaces 'up'


15
And, 6 packets transmitted, 6 received & 0% packet loss during about 4998 ms

still under "su/password"


ifdown lo ping -v 127.0.0.1 -c4, then it shows us 4 packets transmitted, but with faillure!

Again, ifup lo & then clear screen,


Now, let's show "where these interfaces are defined in our system

This file contains definitions of our interfaces; now, exit the superuer account, since it's not needed/clear.
Let's now assign an IP address in the netmask to our LAN or Ethernet interfaces, then do ifconfig
# It brings up the configuration informations

16
ifconfig followed by the interface, in our case "eth0"& provide an IP address to assign, then the netmask :

It needs the superuer account, & type the same thing again : ifconfig...

It shows us for 'eth0' the internet & netmask addresses does how we allocate the IP address netmak to our
machine (using command-line). exit superuer/clear. netstat (networks connections open on our machine)

with the parameter 'r', it shows us the IP routing tables :

remotelogin is a command (a lot used) to login remotely to any terminal,

17
But, it's replaced by the 'ssh' command (which gives us the same thing) :

How to Compresse files ?


In order to make files smaller, useful for both saving disk space and making it quicker to send files over
the internet. Two common tools for compressing files exist: gzip and bzip2 with their respective tools for
uncompressing: gunzip and bunzip2. gzip is the de-facto standard; bzip2 tends to produce smaller files but
takes longer to compress them. On the Windows platform, the Zip compression method is favored and
many Unix platforms provide zip and unzip tools to deal with these files. Let's practice!
pwd
/home/merabet/examples/unix/Compression
ls
sequences.fq #Gzip'ing a file
gzip sequences.fq
ls
sequences.fq.gz # Unzipping the file
gunzip sequences.fq.gz
ls
sequences.fq # Using bzip2
bzip2 sequences.fq
ls
sequences.fq.bz2 # As part of a pipe, reading from stdin and writing to stdout
cat sequences.fq.bz2 | bunzip2 | gzip > sequences.fq.gz
ls
sequences.fq.bz2 sequences.fq.gz
* Compressing works better if files are combined & compressed together, rather than compressing them
individually. The Unix tool for packing and unpacking files is 'tape archiver', this goes back to 1979 when
writing files to magnetic tape was for storage.
ls
chimp.file human.file macaque.file orangutan.file
# Pack into single file. 'f', 'c' mean create, and that next argument is the filename to write to, respectively.
tar -cf sequences.tar *.file
# The original files are untouche
ls
chimp.file human.file macaque.file orangutan.file sequences.tar
# Delete all sequences

18
rm *.file
# 'x' means extract
tar -xf sequences.tar
ls
chimp.file human.file macaque.file orangutan.file sequences.tar
tar have increased to make it more convenient
ls
chimp.file human.file macaque.file orangutan.faile sequences.tar
# Pack and gzip sequences simultaneously
tar -zcf sequences.tgz *.file
# List the contents without extracting
tar -ztf sequences.tgz
chimp.file
human.file
macaque.file
orangutan.file
# More recent versions of tar can also bzip2 files
tar -jcf sequences.tbz2 *.file
tar -jtf sequences.tbz2
chimp.file
human.file
macaque.file
orangutan.file
To summarize : Compressing, Uncompressing, Suffix, & Tar'd Suffix, 4 items that are (in 2 ex.) as follow :
gzip gunzip .gz .tgz; bzip2 bunzip2 .bz2 .tbz2

Why using remote computers?


Central computing resources tend to be much larger, more reliable & powerful than our laptop or PC. If
we need to do/use [or] a lot of work/data, then we may have no option but to use a bigger computer.
Central computers tend to have much more rigorous & tested policies for backing up data. secure shell is a
method of connecting to other computers and giving access to a command-line on them. Let's practice!
ssh auser@anothermachine.org
Password:
whoami
merabet
ssh anothermachine
*While keeping communications between our computer & a remote computer secure, ssh also allows us to
verify that a remote computer is the computer it claims to be – no point keeping traffic secure if we send
it to the wrong place -or prevent someone sitting in the connection listening's middle of to each message
then passing it on, pretending to each side to be the other. Graphical programs in keeping with their
19
heritage of terminals to remote computers, can also be run on remote machines but expect pauses unless
we have a low-latency internet connection. This is enabled by a system called the X Windows system (use
-X flag), & requires software on our local computer that understands the drawing instructions being sent.
# Connect to anothermachine, using the -X flag to enable X11
ssh -X auser@anothermachine.org
# This gives us a command-line on anothermachine. Start a graphical application; the application that appears
is running on anothermachine not our local computer.
gtk-demo &
# Get another command-line on anothermachine
xterm &
Other Unix commands
whatis; whereis; type; which; --help; man. What means ifconfig? configure a network interface.

What about 'man' & 'history'?

To know where is 'ifconfig', type 'whereis ifconfig'

To edit the root repertory 'sbin' [all files strarting with 'if'], type cd /sbin

type tells us where a command is hashed built-in or is located in a folder

For ex. 'ifconfig' is located in 'sbin'

whitch

for a'man' listing :

20
Let's go back to'home' by typing 'cd ~/'. ifconfig --help gives us the help about that command; let's type it

Note nothing helps than the 'menu pages' shortly well. 'man ifconfig' gives us any information we need.

21
'man man' gives us details of Linux manual pages.

And more requirements...

We can get the 'man' of the 'man' itself by typing man man

22
It gives us more details on Linux manual pages :

Before configuring networks that widely use Linux, one should have an idea on the
Networking road map
* Having a look at the Transmission Control Protocol/Internet Protocol themselves, The protocol "suite"
TCP/IP is a set of network protocols designed to work smoothly together. It includes several components,
each defined by a standards-track "Requests For Comments" or series of RFCs, that are :
• IP which routes data packets from one computer to another (RFC791)
• Internet Control Message Protocol providing many low-level kinds of support for IP, including error
messages, routing assistance, and debugging help (RFC792)
• Address Resolution Protocol translating IP addresses to hardware addresses (RFC826)2
• User Datagram Protocol providing unverified, one-way data delivery (RFC768)
• Transmission Control Protocol implementing reliable, full duplex, flow-controlled, error-corrected
conversations (RFC793). All of these protocols are arranged in a stack (hierarchy), with the higher-level
23
protocols making use of the protocols beneath them. TCP/IP is conventionally described as a 5-layer
system, but the actual TCP/IP protocols inhabit only 3 of these layers.

* What's a Port? IP addresses identifying a network interfaces of a machine, are not specific enough to
address individual processes or services, many of which may be actively using the network at once. A port
is a 16-bit number that supplements an IP address to specify a particular communication channel, so as
TCP and UDP extend IP addresses with a concept known as a port. Standard services such as email, FTP,
and HTTP associate themselves with “well known” ports defined in /etc/services. To avoid impersonation
of these services, Linux restrict server programs from binding to port numbers under 1024 unless they are
run as root, so that Anyone can communicate with a server running on a low port number, and the
restriction applies only to the program listening on the port.
* Some of many broad types of address defined by IP layer have direct counterparts at the link layer:
• Broadcast – addresses including all hosts on the local subnet.
• Anycast – addresses resolving to any one of a group of hosts.
• Multicast – addresses simultaneously targeting a group of hosts.
These, though largely unused on today’s Internet, facilitate applications such as video conferencing in
which the same set of packets must be sent to all participants. An Internet Group Management Protocol
constructs and manages sets of hosts treated as one multicast destination.
* Internet addressing (IP addressing) is used in networks, so IP addresses and hardware are respectively
unique and independent. Mapping from IP addresses to hardware ones is implemented at the link layer of
the TCP/IP model. On networks like Ethernet supporting broadcasting (allowing packets to be addressed
to “all hosts on such physical network”), senders use Address Resolution Protocol to discover mappings
without requiring any assistance from a system administrator. For hostname addressing, operating systems
allow hostnames to be associated with IP addresses, though these numbers' sequences are hard for users
to remember, so as users can type rfc-editor.org instead of 128.9.160.27 for example. Under Linux,
mapping can be set up in many manners, ranging from a static file (/etc/hosts) to Lightweight Directory
Access Protocol database system to the worldwide Domain Name System. Hostnames are a convenient
shorthand for IP addresses referring to network interfaces rather than computers.

Summarizing : Shell basics [where there is a shell, there is a way]


sh (original Bourne shell) and ksh (the Korn shell) are used on a few Unix systems. Major shells in the sh
lineage include bash and ksh, but not csh or tcsh).
24
* basic emacs commands are available to us when we’re editing history. Ctrl-e goes to the end of the line &
Ctrl-a to the beginning. Ctrl-p steps backward through recently executed commands & recalls them for
editing. Ctrl-r searches incrementally through your history to find old commands.
* with vi, let's put our shell’s command-line editing into vi mode like this: $ set -o vi
* Typing <Esc> to leave input mode and “i” to reenter it. In edit mode, “w” takes us forward a word, “fX”
* We can walk through past command history entries with <Esc> k. If we want emacs editing mode back
again? $ set -o emacs
cut: separate lines into fields
sort: sort lines
* Let's have some more common options, but check the man page for others; & begin with sort options
Opt Meaning
-b ignore leading whitespace
-f case insensitive sorting
-k specify the columns that form the sort key
-n compare fields as integer numbers
-r reverse sort order
-t set field separator (the default is whitespace)
-u output unique records only

*ping: check seeing if a host is alive; in many situations it's the only command needed for network debug-
ging. It sends an ICMP ECHO_REQUEST packet to a target host & waits to see if the host answers back.
<host> is an IP address of a machine whose name is as follows, ex : inspiron.u-mascara.dz
nslookup/dig <host> returns the IP address of the machine (so as it works backward with an parmetering
IP address.
telnet <host> <port> establish the interactive connection with another computer on Internet network.
host-address corresponds to the machine name or its IP address.
ssh <[user@]host> as in Secure mode, option –X to allow windowing.
ftp <host> establish the connection in transferring files with another computer, help to obtain the list of
commands.
scp [[user1@]host1:]file1 [[user2@]host2:]file2 a secure copy through a network.
ifconfig c and configure network map.
route displays active routes (as netstat –r)
ping < host > to check connectivity.
traceroute < host > to check network-transit.
netstat displays informations on networks (open ports, ect), -t ; tcp, -u ;
tcpdump to sniff trafic on networks, ex :
tcpdump src 130.79.90.60 and dst 130.79.44.193 –ne // n : numeric
(ip + num port), e : adresses MAC
tcpdump src 130.79.90.60 and port 80 –ne

25
wget for web pages aspiring.
nmap <host> displays the list of open ports. Ex : nmap localhost (scan locally the ports 1- >1024 + those
mentioned in nmap-services), nmap localhost –p1-65535 (scan ports 1 to 65535).

References
1 Evi Nemeth, Garth Snyder, Trent R. Hein & Ben Whaley, Unix & Linux System Administration

Handbook, 4th ed. Pearson Education, Inc, 2011.


2 http://www.gnu.org/.
3 https://help.ubuntu.com/16. 04/ (latest vesrion of Unbuto 16.04.1 LTS "Xenial Xerus)

26

View publication stats

You might also like