SlideShare a Scribd company logo
Linux Desktop Operation
Presented by Arash Foroughi
Iran, April 2016
Session 1
Linux, a Free and Open Source Software
• Linux is one of the most famous pieces of FOSS software. Linux which
also sometimes called GNU/Linux, is a computer operating system, like
Microsoft Windows or Apple Mac OS X. But unlike other operating
systems, Linux is free.
• Linux was originally developed by Finnish programmer Linus
Torvalds. First released in 1991, it has since grown to encompass an
army of developers, tens of thousands of applications and tools, and
millions of users.
3
Linux Advantages
• Linux is free
• Linux is portable to any hardware platform
• Linux was made to keep on running
• Linux is secure and stable
• Linux is scalable
• The Linux OS and most Linux apps have very short debug-times
4
Linux Distributions
• Distributions differ in several ways, and three of the most important
versions are:
• Purpose
• Configuration and packaging
• Support model
5
Linux Distributions
• What is a Linux distribution? It is a collection of applications,
packages, management, and features that run on top of the Linux
kernel. The kernel is what all distributions have in common (it is
sometimes customized by the distribution maintainers), but at their
core they all run Linux.
6
Linux Kernel
• The kernel is the core of all computer operating systems and is usually
the layer that allows the operating system to interact with the
hardware in your computer. The kernel contains software that allows
you to make use of your hard disk drives, network cards, RAM, and
other hardware components.
• In the Linux world, the kernel is based on code originally developed by
Linux’s founder, Finnish developer Linus Torvalds. The kernel is now
maintained by a community of open source developers, and changes
go through a software life-cycle process.
7
RedHat Enterprise Linux
• Red Hat Enterprise Linux (http://www.redhat.com/rhel/) is a popular
commercially supported Linux platform.
• Red Hat platforms are commonly used by corporate organizations as
server platforms due to the dedicated support and service levels
available from the vendor.
8
CentOS
• CentOS (http://www.centos.org/) is a derivation of the Red Hat
Enterprise Linux platform.
• Based on the same source code, it is available at no charge (and
without Red Hat’s support).
• People who wish to make use of the Red Hat platform and its stability
without paying for additional support commonly use it.
9
Administration Interfaces
• There are two methods for administration of Linux :
 GUI (Graphical User Interface) Desktop
 CLI (Command Line Interface)
10
The GUI Desktop
• On Linux the GUI interface is a combination of several applications.
The basic application is called the X Window System (you’ll also see it
called X11 or simply X).
• On top of X you then add a desktop environment to provide the “look
and feel” and desktop functionality such as toolbars, icons, buttons,
and the like. There are two major desktop environments popular on
Linux: Gnome and KDE.
11
The Command Line (CLI)
• In the Linux world, the command line is one of the most powerful tools available to
you.
• In this course, a lot of focus is going to be on the command line.
• From inside the Gnome or KDE GUI interface, you have two options. The first is to use
a virtual console—a kind of Linux management console that runs by default on most
Linux distributions. Or you can launch a terminal emulator application like the
Gnome Terminal or Konsole.
• To launch a virtual console from inside a Gnome or KDE GUI, use the key combination
Ctrl+Alt and one of the F1 through F6 keys.
• You can also launch a terminal emulator. In Gnome, for example, you click the
Applications menu, open the Accessories tab, and select the Terminal application or
just simply right click on desktop and select “Open terminal”
12
Shell
• What command line is presented to you depends on what shell is
running for your user. Shells are interfaces to the operating system and
kernel of your host. For example, the command line on a Windows XP
host is also a shell. Each shell contains a collection of built-In
commands that allow you to interact with your host (these are
supplemented by additional tools installed by your distribution).
• A variety of shells are available, with the most common being the Bash
(or Bourne-again) shell that is used by default on many distributions,
including the popular Red Hat, Ubuntu, and Debian distributions.
13
Shell 14
Command-Line Prompt
• After logging in to your Linux host, you should see a prompt that looks like this:
• [arash@redhat5 ~]$
• So what does this mean? Well let’s break it down:
• user@host directory$
• On most Linux distributions, the basic prompt is constructed from the username
you’re logged in as, the name of the host, the current directory, and the $ symbol,
which indicates what sort of user you are logged in as which is not root
(administrator) user.
• ~ symbol is an abbreviated method of referring to your home directory.
15
Basic Commands
• On a Linux host, most users have a special directory, called a home directory, which is
created when the user is created.
• Print name of current/working directory
• $pwd
• Find the name of the user you are logged in as.
• $whoami
• Show who is logged on and what they are doing.
• $w
• $w -h
16
Basic Commands
• Display the history list with line numbers
$ history
• Displays a calendar
$ cal
• Bash Command Completion
• Most shells allow command completion, typically bound to the TAB key, which
allow you to complete the names of commands stored upon your PATH, file
names, or directory names.
17
Command Structure
• Linux commands share the common form:
• command option(s) argument(s)
• The command identifies the command you want Linux to execute.
• Options modify the way that a command works.
• Most commands let you specify options or arguments. However, in any
given case, you may not need to do so.
18
Command Types
• Linux command Types (Internal and External)
• Internal commands are those commands which are shell built-in
commands. These commands are loaded at the time of booting. Shell does
not start separate process to run this commands.
• Example: cd , pwd , echo etc.
• External commands are those command which are stored as a separate
binaries. Shell starts separate sub-process to execute them. Most external
commands are stored in the form of binaries in /bin directory.
• Example : ls
• $ type cd
• $ type ls
19
Getting Help
• $man date
• The man command will return a document that describes the command and
its various options.
• For searching in the man pages enter : /pattern to search for a pattern
• Exiting from man page by pressing “q”
• Exercise :
• Display the date in format of YYYY-mm-dd
• Set the date to 5 July 2012 15:00
• Set the time to 17:20
• Display the UTC time
20
Getting Help
• -Display the date in format of YYYY-mm-dd
$ date +%Y%m%d
• -Set the date to 5 July 2012 15:00
# date -s "5 July 2012 15:00"
• -Set the time to 17:20
# date -s "17:20"
• -Display the UTC time
$ date --utc
21
Getting Help
• man sections :
1. General commands
2. System calls
3. C library functions
4. Special files (usually devices, those found in /dev) and drivers
5. File formats and conventions
6. Games and screensavers
7. Miscellanea
8. System administration commands and daemons
• $man -a passwd
• View section 5 ---> $man -S 5 passwd
22
Getting Help
• Other commands for getting help :
• help : Display helpful information about builtin commands.
• apropos : apropos - search the whatis database for strings
• Info : read Info documents
23
Alias
• The alias command can be useful if you want to create a 'shortcut' to a command.
The format is alias name='command‘
• Example : alias list="ls -la"
• To see a list of aliases set up on your linux box, just type alias at the prompt.
$ alias
• Exercise :
• Define an alias named today which returns current day of week
• How to remove an alias ?
24
Alias
• Exercise :
• Write an alias named yesterday which shows the date of past day in
the format of yyddmm
• Tip : date -d yesterday gives the date of the past day
• $ alias yesterday='date -d yesterday'
25
Finger Information
• finger - user information lookup program
$ finger
$ finger [username]
• Exercise :
• How to change finger information ? ---> $ chfn
• The finger information is stored in /etc/passwd file
26
Getting Host Information
• Hostname is the name of machine which is used by many of the networking
programs to identify the machine.
• hostname - show or set the system’s host name
• Print the host name :
$ hostname
• Set the hostname
# hostname [newhostname]
27
Copying a File
• You can make a copy of an existing file to a new location using “cp” command
which normally gets two arguments which are source file and destination
path :
• $ cp [Source-file] [Destination]
• For example : cp /tmp/namef .
• . indicates the current directory which you are working in (CWD = Current
Working Directory or PWD = Present Working Directory)
28
Listing the Files
• ls - list directory contents
• In order to list the files in current directory
$ ls
• A “Directory” in Linux world is equivalent to “Folder” in Windows
world
29
View Contents of a File
• Print the contents of a file on screen
$ cat [Filename]
• In order to understand the contents of the file it should be text file.
• You can determine the type of a file by “file” command :
• file - determine file type
$ file [Filename]
30
Printing Specified Columns or Fields
• cut - Cut out selected fields of each line of a file.
• Display columns 1 to 17
$ cut -c 1-17 namef
• Display columns 18 to 34
$ cut -c 18-34
• Display columns 34 to the end
$ cut -c 34- namef
31
Email
Sending mail to a specific user :
• $ mail [username]
• Subject:
• [Letter body]
• (Press Ctrl+D)
• Cc:
• Checking mails
$ mail
32
Functions
$function_name()
{
[action1]
[action2]
}
• Defining a function named "d" which prints the date :
$d()
{
date
}
• Calling the function
$d
33
Standard Input & Output & Error
• Many Linux commands print their
output to screen. But the screen isn't
the only place where the commands
can print their output because you
can redirect the output of several
commands to files, devices, and even
to the input of other commands.
34
Standard Input & Output & Error
• The CLI programs that display their
results do so usually by sending the
results to standard output, or stdout
for short. By default, standard output
directs its contents to the screen, as
you've seen with the ls and cat
commands. But if you want to direct
the output to somewhere else, you
can use the > character.
35
Pipelines
• We use | (pipe) operator in order to redirect output of one program
and use it as input for another program :
• Using output of cat command as input for mail command
$ cut -c1-10 namef | mail -s "list" a.foroughi
36
Sorting
• sort - sort lines of text files
$cat [filename] | sort
• Sort by the n-th column
$ cat [filename] | sort -k [n]
• Numeric sort by the n-th column
$ cat [filename] | sort -n -k [n]
37
Omit Repeated Lines
• What is the difference between two below commands ?
$cat namef | uniq
$cat namef | sort | uniq
• Which option gives the number of occurrences ?
-c
cat namef | sort | uniq -c
38
Head & Tail
• head - output the first part of files / tail - output the last part of files
• head namef
• head -5 namef
• cat namef | head -n 5
• We have same options and arguments for tail command
• How to get line 5 of namef file ?
cat namef | head -5 | tail -1
39
More & Less
• In order to view a file page by page :
$ more [filename]
• What is the other form of using this command based on standard
output ?
Command | more
• The "less" command is much more convenient with more options :
$ less [filename]
40
More & Less
• Important actions in less environment :
Search for a pattern /pattern
Go to the next search result n
Go to the previous search result Shift + n
Previous line Down arrow key
Next line Up arrow key
Next page Space
Previous page b
Go to the last line Shift + g
Go to the first line 1 Shift + g
41
Redirection > , >>
• We can redirect output of a command to a file
$ [Command] > [Filename]
$ [Command] >> [Filename]
• > : Creates new file or overwrite an existing file
• >> : Creates new file or appends to the end of an existing fie
• $ ls > /tmp/list
• $ cat /tmp/list
• Counting number of lines of a file :
$ wc -l [filename]
$ cat $filename | wc -l
42
Field Separation
• The file /etc/passwd contains list of users on the system. How can we
display only the first field using cut command ?
$ cut -d":" -f1
• Exercise: Print the different shells assigned to each user in
/etc/passwd and count their usage
$ cut -d: -f6 /etc/passwd | sort | uniq -c
43
Variables
• To define a variable and give it a value
$ fname="Ali"
• We defined avariable named "fname" and gave it the value of "Ali"
• To use this variable we use $ character before name of variable :
• Print value of a variable
$ echo $fname
44
Reading a Variable from Input
• To get the value of a variable from user :
$ read fname
$ read -p "Please enter your name : " fname
• -p option displays a prompt before reading the value from input
45
Variables
• There are some pre-defined variables in your shell like for example
"SHELL" which contains the name of your current shell :
$ echo $SHELL
/bin/bash
• We call these kind of variables "Environment variables"
46
Change Directory
• By default after logging in to the system, we are in our home directory.
For username "john" the home directory would be /home/john
• We can find out our current working directory by pwd command.
$ pwd
• Navigating to another directory is possible using "cd" (Change
Directory) command
$ cd [directory-name]
47
Change Directory
$ cd [directory-name]
• The directory-name could be either a full path starting with "/" or a relative path to our
current directory.
• Full Path:
$ cd /home/a.foroughi
• Relative Path: (If you are already in /home directory)
$ cd a.foroughi
• Moving one folder up
$ cd ..
48
Listing Files & Directories
• Listing current directory contents
$ ls
• Listing a specific directory contents
$ ls [direcory-name]
• Use a long listing format
$ ls -l
• It gives more information regarding type of entry (file or directory),
permissions, owner, size, last modification date, and file name
49
File Types
• The file type and permissions are contained in the first ten characters, the section resembling
-rw-r--r--
• File Types : Almost everything on the Linux file system can be generally described as a file.
Type Description
- File
d Directory
l Link
c Character devices
b Block devices
s Socket
P Named pipe
50
File Permissions
• The next nine characters detail the access permissions assigned to the file or
directory.
• On Linux, permissions are used to determine what access users and groups
have to a file.
• There are three commonly assigned types of permissions for files:
Read, indicated by the letter r
Write, indicated by the letter w
Execute, indicated by the letter x
51
File Permissions
Read permissions allow a file to be read or viewed but not edited.
Write permissions allow you to make changes or write to a file. If the write
permission is set on a directory, you are able to create, delete, and rename
files in that directory.
Execute permissions allow you to run a file; for example, all binary files and
commands (binary files are similar to Windows executables) must be marked
executable to allow you to run them.
• If this permission is set on a directory, you are able to traverse the directory,
for example, by using the cd command to access a subdirectory.
52
File Ownership
• Every file/directory is owned by a user and by a group which can be
seen in ls -l output 3th and 4th fields.
• For example below directory is owned by root user and lp group.
$ ls -ld /etc/cups
drwxr-xr-x 5 root lp 4096 Jun 29 2011 /etc/cups
53
File Permissions
• Each file on your host has three classes of permissions:
User
Group
Other (everyone else)
 The User class describes the permissions of the user
who owns the file. These are the first three characters
in our listing.
 The Group class describes the permissions of the
group that owns the file. These are the second set of
three characters in our listing.
 Lastly, the Other class describes the permissions that
all others have to the file. These are the final set of
three characters in the listing.
54
Thank you
Arash Foroughi
Iran, April 2016
55

More Related Content

PPTX
File permissions
PPTX
Access control list acl - permissions in linux
PPTX
A general Overview of linux !!
PPTX
Basics of-linux
PPT
Bash shell
DOCX
linux file sysytem& input and output
PDF
Linux commands
PPTX
Linux file system
File permissions
Access control list acl - permissions in linux
A general Overview of linux !!
Basics of-linux
Bash shell
linux file sysytem& input and output
Linux commands
Linux file system

What's hot (20)

PPTX
Users and groups
PDF
LCU14 500 ARM Trusted Firmware
PPTX
Linux fundamentals
PDF
systemd
PPT
Linux Administration
PDF
Presentation on linux
PDF
Linux directory structure by jitu mistry
PDF
Board Bringup
PDF
File system
PDF
Device Tree for Dummies (ELC 2014)
PDF
Lesson 2 Understanding Linux File System
PPTX
Linux distributions
PDF
Unix - An Introduction
PPT
Linux file system
PPTX
Linux booting process - Linux System Administration
PPTX
Operating Systems: Linux in Detail
PPT
Vi editor in linux
PPT
Storage Management in Linux OS.ppt
PPTX
Linux.ppt
PPTX
File permission in linux
Users and groups
LCU14 500 ARM Trusted Firmware
Linux fundamentals
systemd
Linux Administration
Presentation on linux
Linux directory structure by jitu mistry
Board Bringup
File system
Device Tree for Dummies (ELC 2014)
Lesson 2 Understanding Linux File System
Linux distributions
Unix - An Introduction
Linux file system
Linux booting process - Linux System Administration
Operating Systems: Linux in Detail
Vi editor in linux
Storage Management in Linux OS.ppt
Linux.ppt
File permission in linux
Ad

Viewers also liked (6)

KEY
Linux in Business - Workstation Integration
ODP
Linux on the Corporate Desktop: We Did It, and You Can Too
PDF
Modern Deployment Strategies
PDF
Linux AD integration with OpenDJ
PPTX
Excel
PDF
Building Open Source Identity Management with FreeIPA
Linux in Business - Workstation Integration
Linux on the Corporate Desktop: We Did It, and You Can Too
Modern Deployment Strategies
Linux AD integration with OpenDJ
Excel
Building Open Source Identity Management with FreeIPA
Ad

Similar to Linux Desktop Operation - Session 1 (20)

PPTX
Linuxtraining 130710022121-phpapp01
PPTX
Linux Systems Programming: Ubuntu Installation and Configuration
PPTX
Linux Basics.pptx
PPTX
Presentation for RHCE in linux
PPTX
LinuxTraining_3.pptx
PDF
Raspberry Pi - Lecture 2 Linux OS
PPTX
linux system administration for system admin jobs
PDF
PDF
Linux Tutorial with commands to use while learning
PPTX
UNIX/Linux training
PDF
Linux systems - Linux Commands and Shell Scripting
PDF
Linux Systems: Getting started with setting up an Embedded platform
PDF
Linux OS guide to know, operate. Linux Filesystem, command, users and system
PPTX
Linux Presentation
PPTX
Linux Shell Basics
PDF
17 Linux Basics #burningkeyboards
PPTX
18 LINUX OS.pptx Linux command is basic isma
PPT
redhat_by_Cbitss.ppt
PPTX
Red hat linux essentials
Linuxtraining 130710022121-phpapp01
Linux Systems Programming: Ubuntu Installation and Configuration
Linux Basics.pptx
Presentation for RHCE in linux
LinuxTraining_3.pptx
Raspberry Pi - Lecture 2 Linux OS
linux system administration for system admin jobs
Linux Tutorial with commands to use while learning
UNIX/Linux training
Linux systems - Linux Commands and Shell Scripting
Linux Systems: Getting started with setting up an Embedded platform
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Linux Presentation
Linux Shell Basics
17 Linux Basics #burningkeyboards
18 LINUX OS.pptx Linux command is basic isma
redhat_by_Cbitss.ppt
Red hat linux essentials

Recently uploaded (20)

PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
Internet___Basics___Styled_ presentation
PPTX
Digital Literacy And Online Safety on internet
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPT
tcp ip networks nd ip layering assotred slides
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
E -tech empowerment technologies PowerPoint
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Power Point - Lesson 3_2.pptx grad school presentation
SAP Ariba Sourcing PPT for learning material
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Internet___Basics___Styled_ presentation
Digital Literacy And Online Safety on internet
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Module 1 - Cyber Law and Ethics 101.pptx
Sims 4 Historia para lo sims 4 para jugar
Cloud-Scale Log Monitoring _ Datadog.pdf
tcp ip networks nd ip layering assotred slides
RPKI Status Update, presented by Makito Lay at IDNOG 10
WebRTC in SignalWire - troubleshooting media negotiation
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
E -tech empowerment technologies PowerPoint
Design_with_Watersergyerge45hrbgre4top (1).ppt
international classification of diseases ICD-10 review PPT.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf

Linux Desktop Operation - Session 1

  • 1. Linux Desktop Operation Presented by Arash Foroughi Iran, April 2016
  • 3. Linux, a Free and Open Source Software • Linux is one of the most famous pieces of FOSS software. Linux which also sometimes called GNU/Linux, is a computer operating system, like Microsoft Windows or Apple Mac OS X. But unlike other operating systems, Linux is free. • Linux was originally developed by Finnish programmer Linus Torvalds. First released in 1991, it has since grown to encompass an army of developers, tens of thousands of applications and tools, and millions of users. 3
  • 4. Linux Advantages • Linux is free • Linux is portable to any hardware platform • Linux was made to keep on running • Linux is secure and stable • Linux is scalable • The Linux OS and most Linux apps have very short debug-times 4
  • 5. Linux Distributions • Distributions differ in several ways, and three of the most important versions are: • Purpose • Configuration and packaging • Support model 5
  • 6. Linux Distributions • What is a Linux distribution? It is a collection of applications, packages, management, and features that run on top of the Linux kernel. The kernel is what all distributions have in common (it is sometimes customized by the distribution maintainers), but at their core they all run Linux. 6
  • 7. Linux Kernel • The kernel is the core of all computer operating systems and is usually the layer that allows the operating system to interact with the hardware in your computer. The kernel contains software that allows you to make use of your hard disk drives, network cards, RAM, and other hardware components. • In the Linux world, the kernel is based on code originally developed by Linux’s founder, Finnish developer Linus Torvalds. The kernel is now maintained by a community of open source developers, and changes go through a software life-cycle process. 7
  • 8. RedHat Enterprise Linux • Red Hat Enterprise Linux (http://www.redhat.com/rhel/) is a popular commercially supported Linux platform. • Red Hat platforms are commonly used by corporate organizations as server platforms due to the dedicated support and service levels available from the vendor. 8
  • 9. CentOS • CentOS (http://www.centos.org/) is a derivation of the Red Hat Enterprise Linux platform. • Based on the same source code, it is available at no charge (and without Red Hat’s support). • People who wish to make use of the Red Hat platform and its stability without paying for additional support commonly use it. 9
  • 10. Administration Interfaces • There are two methods for administration of Linux :  GUI (Graphical User Interface) Desktop  CLI (Command Line Interface) 10
  • 11. The GUI Desktop • On Linux the GUI interface is a combination of several applications. The basic application is called the X Window System (you’ll also see it called X11 or simply X). • On top of X you then add a desktop environment to provide the “look and feel” and desktop functionality such as toolbars, icons, buttons, and the like. There are two major desktop environments popular on Linux: Gnome and KDE. 11
  • 12. The Command Line (CLI) • In the Linux world, the command line is one of the most powerful tools available to you. • In this course, a lot of focus is going to be on the command line. • From inside the Gnome or KDE GUI interface, you have two options. The first is to use a virtual console—a kind of Linux management console that runs by default on most Linux distributions. Or you can launch a terminal emulator application like the Gnome Terminal or Konsole. • To launch a virtual console from inside a Gnome or KDE GUI, use the key combination Ctrl+Alt and one of the F1 through F6 keys. • You can also launch a terminal emulator. In Gnome, for example, you click the Applications menu, open the Accessories tab, and select the Terminal application or just simply right click on desktop and select “Open terminal” 12
  • 13. Shell • What command line is presented to you depends on what shell is running for your user. Shells are interfaces to the operating system and kernel of your host. For example, the command line on a Windows XP host is also a shell. Each shell contains a collection of built-In commands that allow you to interact with your host (these are supplemented by additional tools installed by your distribution). • A variety of shells are available, with the most common being the Bash (or Bourne-again) shell that is used by default on many distributions, including the popular Red Hat, Ubuntu, and Debian distributions. 13
  • 15. Command-Line Prompt • After logging in to your Linux host, you should see a prompt that looks like this: • [arash@redhat5 ~]$ • So what does this mean? Well let’s break it down: • user@host directory$ • On most Linux distributions, the basic prompt is constructed from the username you’re logged in as, the name of the host, the current directory, and the $ symbol, which indicates what sort of user you are logged in as which is not root (administrator) user. • ~ symbol is an abbreviated method of referring to your home directory. 15
  • 16. Basic Commands • On a Linux host, most users have a special directory, called a home directory, which is created when the user is created. • Print name of current/working directory • $pwd • Find the name of the user you are logged in as. • $whoami • Show who is logged on and what they are doing. • $w • $w -h 16
  • 17. Basic Commands • Display the history list with line numbers $ history • Displays a calendar $ cal • Bash Command Completion • Most shells allow command completion, typically bound to the TAB key, which allow you to complete the names of commands stored upon your PATH, file names, or directory names. 17
  • 18. Command Structure • Linux commands share the common form: • command option(s) argument(s) • The command identifies the command you want Linux to execute. • Options modify the way that a command works. • Most commands let you specify options or arguments. However, in any given case, you may not need to do so. 18
  • 19. Command Types • Linux command Types (Internal and External) • Internal commands are those commands which are shell built-in commands. These commands are loaded at the time of booting. Shell does not start separate process to run this commands. • Example: cd , pwd , echo etc. • External commands are those command which are stored as a separate binaries. Shell starts separate sub-process to execute them. Most external commands are stored in the form of binaries in /bin directory. • Example : ls • $ type cd • $ type ls 19
  • 20. Getting Help • $man date • The man command will return a document that describes the command and its various options. • For searching in the man pages enter : /pattern to search for a pattern • Exiting from man page by pressing “q” • Exercise : • Display the date in format of YYYY-mm-dd • Set the date to 5 July 2012 15:00 • Set the time to 17:20 • Display the UTC time 20
  • 21. Getting Help • -Display the date in format of YYYY-mm-dd $ date +%Y%m%d • -Set the date to 5 July 2012 15:00 # date -s "5 July 2012 15:00" • -Set the time to 17:20 # date -s "17:20" • -Display the UTC time $ date --utc 21
  • 22. Getting Help • man sections : 1. General commands 2. System calls 3. C library functions 4. Special files (usually devices, those found in /dev) and drivers 5. File formats and conventions 6. Games and screensavers 7. Miscellanea 8. System administration commands and daemons • $man -a passwd • View section 5 ---> $man -S 5 passwd 22
  • 23. Getting Help • Other commands for getting help : • help : Display helpful information about builtin commands. • apropos : apropos - search the whatis database for strings • Info : read Info documents 23
  • 24. Alias • The alias command can be useful if you want to create a 'shortcut' to a command. The format is alias name='command‘ • Example : alias list="ls -la" • To see a list of aliases set up on your linux box, just type alias at the prompt. $ alias • Exercise : • Define an alias named today which returns current day of week • How to remove an alias ? 24
  • 25. Alias • Exercise : • Write an alias named yesterday which shows the date of past day in the format of yyddmm • Tip : date -d yesterday gives the date of the past day • $ alias yesterday='date -d yesterday' 25
  • 26. Finger Information • finger - user information lookup program $ finger $ finger [username] • Exercise : • How to change finger information ? ---> $ chfn • The finger information is stored in /etc/passwd file 26
  • 27. Getting Host Information • Hostname is the name of machine which is used by many of the networking programs to identify the machine. • hostname - show or set the system’s host name • Print the host name : $ hostname • Set the hostname # hostname [newhostname] 27
  • 28. Copying a File • You can make a copy of an existing file to a new location using “cp” command which normally gets two arguments which are source file and destination path : • $ cp [Source-file] [Destination] • For example : cp /tmp/namef . • . indicates the current directory which you are working in (CWD = Current Working Directory or PWD = Present Working Directory) 28
  • 29. Listing the Files • ls - list directory contents • In order to list the files in current directory $ ls • A “Directory” in Linux world is equivalent to “Folder” in Windows world 29
  • 30. View Contents of a File • Print the contents of a file on screen $ cat [Filename] • In order to understand the contents of the file it should be text file. • You can determine the type of a file by “file” command : • file - determine file type $ file [Filename] 30
  • 31. Printing Specified Columns or Fields • cut - Cut out selected fields of each line of a file. • Display columns 1 to 17 $ cut -c 1-17 namef • Display columns 18 to 34 $ cut -c 18-34 • Display columns 34 to the end $ cut -c 34- namef 31
  • 32. Email Sending mail to a specific user : • $ mail [username] • Subject: • [Letter body] • (Press Ctrl+D) • Cc: • Checking mails $ mail 32
  • 33. Functions $function_name() { [action1] [action2] } • Defining a function named "d" which prints the date : $d() { date } • Calling the function $d 33
  • 34. Standard Input & Output & Error • Many Linux commands print their output to screen. But the screen isn't the only place where the commands can print their output because you can redirect the output of several commands to files, devices, and even to the input of other commands. 34
  • 35. Standard Input & Output & Error • The CLI programs that display their results do so usually by sending the results to standard output, or stdout for short. By default, standard output directs its contents to the screen, as you've seen with the ls and cat commands. But if you want to direct the output to somewhere else, you can use the > character. 35
  • 36. Pipelines • We use | (pipe) operator in order to redirect output of one program and use it as input for another program : • Using output of cat command as input for mail command $ cut -c1-10 namef | mail -s "list" a.foroughi 36
  • 37. Sorting • sort - sort lines of text files $cat [filename] | sort • Sort by the n-th column $ cat [filename] | sort -k [n] • Numeric sort by the n-th column $ cat [filename] | sort -n -k [n] 37
  • 38. Omit Repeated Lines • What is the difference between two below commands ? $cat namef | uniq $cat namef | sort | uniq • Which option gives the number of occurrences ? -c cat namef | sort | uniq -c 38
  • 39. Head & Tail • head - output the first part of files / tail - output the last part of files • head namef • head -5 namef • cat namef | head -n 5 • We have same options and arguments for tail command • How to get line 5 of namef file ? cat namef | head -5 | tail -1 39
  • 40. More & Less • In order to view a file page by page : $ more [filename] • What is the other form of using this command based on standard output ? Command | more • The "less" command is much more convenient with more options : $ less [filename] 40
  • 41. More & Less • Important actions in less environment : Search for a pattern /pattern Go to the next search result n Go to the previous search result Shift + n Previous line Down arrow key Next line Up arrow key Next page Space Previous page b Go to the last line Shift + g Go to the first line 1 Shift + g 41
  • 42. Redirection > , >> • We can redirect output of a command to a file $ [Command] > [Filename] $ [Command] >> [Filename] • > : Creates new file or overwrite an existing file • >> : Creates new file or appends to the end of an existing fie • $ ls > /tmp/list • $ cat /tmp/list • Counting number of lines of a file : $ wc -l [filename] $ cat $filename | wc -l 42
  • 43. Field Separation • The file /etc/passwd contains list of users on the system. How can we display only the first field using cut command ? $ cut -d":" -f1 • Exercise: Print the different shells assigned to each user in /etc/passwd and count their usage $ cut -d: -f6 /etc/passwd | sort | uniq -c 43
  • 44. Variables • To define a variable and give it a value $ fname="Ali" • We defined avariable named "fname" and gave it the value of "Ali" • To use this variable we use $ character before name of variable : • Print value of a variable $ echo $fname 44
  • 45. Reading a Variable from Input • To get the value of a variable from user : $ read fname $ read -p "Please enter your name : " fname • -p option displays a prompt before reading the value from input 45
  • 46. Variables • There are some pre-defined variables in your shell like for example "SHELL" which contains the name of your current shell : $ echo $SHELL /bin/bash • We call these kind of variables "Environment variables" 46
  • 47. Change Directory • By default after logging in to the system, we are in our home directory. For username "john" the home directory would be /home/john • We can find out our current working directory by pwd command. $ pwd • Navigating to another directory is possible using "cd" (Change Directory) command $ cd [directory-name] 47
  • 48. Change Directory $ cd [directory-name] • The directory-name could be either a full path starting with "/" or a relative path to our current directory. • Full Path: $ cd /home/a.foroughi • Relative Path: (If you are already in /home directory) $ cd a.foroughi • Moving one folder up $ cd .. 48
  • 49. Listing Files & Directories • Listing current directory contents $ ls • Listing a specific directory contents $ ls [direcory-name] • Use a long listing format $ ls -l • It gives more information regarding type of entry (file or directory), permissions, owner, size, last modification date, and file name 49
  • 50. File Types • The file type and permissions are contained in the first ten characters, the section resembling -rw-r--r-- • File Types : Almost everything on the Linux file system can be generally described as a file. Type Description - File d Directory l Link c Character devices b Block devices s Socket P Named pipe 50
  • 51. File Permissions • The next nine characters detail the access permissions assigned to the file or directory. • On Linux, permissions are used to determine what access users and groups have to a file. • There are three commonly assigned types of permissions for files: Read, indicated by the letter r Write, indicated by the letter w Execute, indicated by the letter x 51
  • 52. File Permissions Read permissions allow a file to be read or viewed but not edited. Write permissions allow you to make changes or write to a file. If the write permission is set on a directory, you are able to create, delete, and rename files in that directory. Execute permissions allow you to run a file; for example, all binary files and commands (binary files are similar to Windows executables) must be marked executable to allow you to run them. • If this permission is set on a directory, you are able to traverse the directory, for example, by using the cd command to access a subdirectory. 52
  • 53. File Ownership • Every file/directory is owned by a user and by a group which can be seen in ls -l output 3th and 4th fields. • For example below directory is owned by root user and lp group. $ ls -ld /etc/cups drwxr-xr-x 5 root lp 4096 Jun 29 2011 /etc/cups 53
  • 54. File Permissions • Each file on your host has three classes of permissions: User Group Other (everyone else)  The User class describes the permissions of the user who owns the file. These are the first three characters in our listing.  The Group class describes the permissions of the group that owns the file. These are the second set of three characters in our listing.  Lastly, the Other class describes the permissions that all others have to the file. These are the final set of three characters in the listing. 54

Editor's Notes