Linux Desktop Operation - Session 1

Post on 15-Apr-2017

116 views 0 download

Transcript of Linux Desktop Operation - Session 1

Linux Desktop Operation

Presented by Arash ForoughiIran, 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:

UserGroupOther (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 youArash Foroughi

Iran, April 2016

55