Lab01 IntroductionToLinux
Lab01 IntroductionToLinux
Operating System
Lab 01
1
اللهم علمنا ما ينفعنا ،،،وانفعنا بما علمتنا ،،،وزدنا علما
2
Lab Objective
• To introduce some of the common Linux
commands
3
Introduction
• Linux is a clone of the Unix operating system.
• Unix was developed in 1969 by Dennis Ritchie and
Kevin Thompson at Bell Laboratories.
• Most of the Unix operating system is written in the
high-level programming language C.
• A Unix operating system consists of a kernel and a
set of common utility programs.
• The kernel is the core of the operating system,
which manages the computer hardware, controls
program executions, manages memory, etc.
• The utility programs provide user level commands,
such as those to create and edit files.
4
Why Linux?
• Free, open source.
• Ubuntu is a complete Linux operating system
• At Ubuntu's heart is the Linux kernel
• Ubuntu has a graphical user interface (GUI),
making it similar to other popular operating
systems like Windows and Mac OS
• The OS represents applications as icons or menu
choices that you can select using keyboard
commands or a mouse
5
How to Use Ubuntu?
• Requirements:
6
How to Use Ubuntu?
• Once you have download the VirtualBox:
1- Install the Ubuntu operating system by using
its ISO file on the Virtual Machine.
2- Open VirtualBox and click on New tab.
7
How to Use Ubuntu?
3- Identify the operating system as following:
8
How to Use Ubuntu?
4- Set the amount of RAM as following:
9
How to Use Ubuntu?
5- Create a virtual hard drive as following:
10
How to Use Ubuntu?
6- Once the virtual machine has been configured,
Start the operating system installation. Double-
click your new machine (ubuntu) in the left menu,
then browse through your computer for the
installation image file
11
How to Use Ubuntu?
7- Click Start to prompt VirtualBox to begin
reading your ISO file.
12
How to Use Ubuntu?
8- Boot up your virtual machine. Once the
operating system is installed, your virtual machine
is ready to go. Simply double-click the name of
your virtual machine in the left menu of the
VirtualBox main page to start it up.
13
How to Use Ubuntu?
You may encounter an ERROR when you try to
start up Ubuntu as this message shows:
14
How to Use Ubuntu?
To solve that problem, you have to enable
Virtualization by Restarting your computer and
booting. HOW?
• By pressing F12 or F2 while starting the
system to get the booting menu, then
choose advanced setting and enable
Virtualization or choose (VT-X / AMD V)
from Virtualization menu.
• Save the changes and exit.
15
How to Use Ubuntu?
Once there is no problem, Install Ubuntu as
described in the following link.
https://brb.nci.nih.gov/seqtools/installUbuntu.h
tml#install
16
Ubuntu
18
Starting an UNIX Terminal
• To open an UNIX terminal window, click
on the "Terminal" icon in the lunch bar.
19
General Linux Command Format
• A little like DOS commands on windows with
some differences
One or more the
directory/file to apply
The Command the command to
$ cmd –[option(s)] [argument(s)]
• Notes:
– Parts between [] packets are optional
– Linux is CASE SENSITIVE
20
Getting Help
• In Linux, there are on-line manuals which gives information
about most commands.
• man is used to read the manual page for a particular
command one page at a time:
$ man cmd
• Examples,
$ man ls Displays the manual pages of the command ls
$ man man Displays the manual pages of the command man
21
DIRECTORY COMMANDS
22
What is a Directory?
• In Linux, all the files are grouped together in the directory
structure.
• The file-system is arranged in a hierarchical structure, like an
inverted tree.
• The top of the hierarchy is called root (written as a slash / )
• In the diagram above, the full path to the file report.doc is:
/home/knoppix/report.doc
23
Pathnames
• pwd (print working directory) is used to
prints the current directory, type:
$ pwd The full pathname will look something like this:
/home/rawan
24
Making and Removing Directories
• mkdir and rmdir are used for making and
removing directories.
$ mkdir dirname Creates a new directory with name dirname
in the current directory
25
Changing to a Different Directory
• cd (Change Directory) is used to change the
working directory.
$ cd dirpath Changes the current directory to the relative or
absolute pathname of the directory dirpath.
$ cd If no directory is given, the command changes
the current directory to the home directory.
$ cd .. Changes to the parent directory.
• Examples:
$ cd Change to home-directory
$ cd dir1 Change to directory dir1
$ cd dir2 Error because dir2 is not in dir1
$ cd .. Change to parent directory dir1
$ cd dir2 Change to directory dir2
$ cd /home/knoppix/dir1 Change to directory dir1 26
Directory Commands Summary
Command Meaning
pwd display the path of the current directory
mkdir dirname make a directory
rmdir dirname remove a directory
cd directory change to named directory
cd change to home-directory
cd .. change to parent directory
27
FILE COMMANDS
28
What is a file?
• A file is a collection of data.
• They are created by users using text
editors, running compilers etc.
• Examples of files:
– a document (report, essay etc.)
– the text of a program written in some high-
level programming language (like C or C++)
T
e
29
Listing files and directories
• ls (list) is used to list information about files and
directories.
$ ls dirpath If the command has a directory name as
argument (i.e., dirpath), then the command lists
the files in that directory.
$ ls If no directory is given, then the command lists
the files in the current directory.
$ ls -l Includes extensive information on each file.
30
Moving and renaming Files
• mv is used to rename or move a file or a
directory.
$ mv fname newfile The file or directory fname is renamed as
newfile. If the destination file (newfile) exists,
then the content of the file is overwritten, and
the old content of newfile is lost.
31
Copying and Removing Files
• cp (copy) and rm (remove) are used to copy and
remove files:
$ cp fname newfile Copies the content of file fname to newfile.
If a file with name newfile exists the
content of that file is overwritten.
$ cp fname dirname If the second argument is a directory, then
a copy of fname is created in directory
dirname.
$ rm fname Removes the file fname from the current
directory
• Examples:
$ cp file1 dir1 Copy file1 to dir1
$ cd dir1
$ cp file1 file2 Copy to file1 to file2 overwriting its content
$ rm file1 Removes file1
32
Creating a text file.
Note: Use the the >> instead of > to append data to existing file and
to avoid overwriting files.
• Examples:
33
File Commands Summary
Command Meaning
ls list files and directories in the current directory
ls dirpath List files and directories in dirpath
ls -l Includes extensive information on each file
mv file1 file2 rename file1 to file2
mv file1 dirpath move file1 to dirpath
cp file1 file2 copy file1 and call it file2
cp file1 dirpath copy file1 to dirpath
rm file remove a file
more file display a file
cat file display a file
34
Redirecting Programs Output
• > and >> are used to redirect program output
$ cmd > fname The output of cmd is written to file fname. The
file is created if it doesn’t already exist, and the
contents is overwritten if the file exists.
$ cmd >> fname Appends the output of command cmd to the end
of file fname.
• Examples:
$ ls > mylist Writes a listing of the current directory in
file mylist
$ ls >> mylist Appends a listing of the current directory to
file mylist
35
PROCESSES AND JOBS
COMMANDS
36
Foreground and Background Processes
• A process is an executing program identified
by a unique PID (process identifier).
• In Linux, each terminal window can run
multiple commands at the same time.
• It is possible to stop a command temporarily
and resume it at a later time.
• In each terminal window, one command can
be run as a foreground process and multiple
command can be run as background
processes. ِExample:Start xeyes, calculator in the background
xeyes &
gnome-calculator &
37
Processes and Jobs Commands
Command Meaning
Ctrl+C Terminates the command running in the foreground
Ctrl+Z Stops (suspend) the commands in the foreground.
cmd& Executes the command cmd in the background
bg background the suspended job
kill pid Terminates the process with the specified ID: pid, where
pid is as displayed by the command ps
38
Exercise
• List all the content of the home directory then remove any
subdirectory in it
• Go to the home directory then make 3 new subdirectory
called (pics, docs, backup)
• Make a subdirectory in (pics), call it (babies)
• Rename the (backup) directory to (bup) then move it to the
(docs) directory
• Write a listing of the current directory in a file called (list_a)
• Copy the file (list_a) to the (docs) directory
• Make a copy of (list_a) and call it (list_b) then move (list_b)
to (bup) directory
• Run the command that displays the manual of the (passwd)
command in the background
• Terminate all the background process
39
??? ANY QUESTIONS ???
40