linux desktop operation - session 1

55
Linux Desktop Operation Presented by Arash Foroughi Iran, April 2016

Upload: arash-foroughi

Post on 15-Apr-2017

127 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Linux Desktop Operation - Session 1

Linux Desktop Operation

Presented by Arash ForoughiIran, April 2016

Page 2: Linux Desktop Operation - Session 1

Session 1

Page 3: Linux Desktop Operation - 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

Page 4: Linux Desktop Operation - Session 1

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

Page 5: Linux Desktop Operation - Session 1

Linux Distributions

• Distributions differ in several ways, and three of the most important versions are:• Purpose• Configuration and packaging• Support model

5

Page 6: Linux Desktop Operation - Session 1

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

Page 7: Linux Desktop Operation - Session 1

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

Page 8: Linux Desktop Operation - Session 1

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

Page 9: Linux Desktop Operation - Session 1

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

Page 10: Linux Desktop Operation - Session 1

Administration Interfaces

• There are two methods for administration of Linux :

GUI (Graphical User Interface) Desktop CLI (Command Line Interface)

10

Page 11: Linux Desktop Operation - Session 1

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

Page 12: Linux Desktop Operation - Session 1

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

Page 13: Linux Desktop Operation - Session 1

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

Page 14: Linux Desktop Operation - Session 1

Shell 14

Page 15: Linux Desktop Operation - Session 1

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

Page 16: Linux Desktop Operation - Session 1

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

Page 17: Linux Desktop Operation - Session 1

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

Page 18: Linux Desktop Operation - Session 1

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

Page 19: Linux Desktop Operation - Session 1

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

Page 20: Linux Desktop Operation - Session 1

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

Page 21: Linux Desktop Operation - Session 1

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

Page 22: Linux Desktop Operation - Session 1

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

Page 23: Linux Desktop Operation - Session 1

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

Page 24: Linux Desktop Operation - Session 1

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

Page 25: Linux Desktop Operation - Session 1

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

Page 26: Linux Desktop Operation - Session 1

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

Page 27: Linux Desktop Operation - Session 1

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

Page 28: Linux Desktop Operation - Session 1

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

Page 29: Linux Desktop Operation - Session 1

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

Page 30: Linux Desktop Operation - Session 1

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

Page 31: Linux Desktop Operation - Session 1

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

Page 32: Linux Desktop Operation - Session 1

Email

Sending mail to a specific user :

• $ mail [username]• Subject:• [Letter body]• (Press Ctrl+D)• Cc:

• Checking mails

$ mail

32

Page 33: Linux Desktop Operation - Session 1

Functions$function_name()

{

[action1]

[action2]

}

• Defining a function named "d" which prints the date :

$d()

{

date

}

• Calling the function

$d

33

Page 34: Linux Desktop Operation - Session 1

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

Page 35: Linux Desktop Operation - Session 1

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

Page 36: Linux Desktop Operation - Session 1

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

Page 37: Linux Desktop Operation - Session 1

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

Page 38: Linux Desktop Operation - Session 1

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

Page 39: Linux Desktop Operation - Session 1

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

Page 40: Linux Desktop Operation - Session 1

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

Page 41: Linux Desktop Operation - Session 1

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

Page 42: Linux Desktop Operation - Session 1

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

Page 43: Linux Desktop Operation - Session 1

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

Page 44: Linux Desktop Operation - Session 1

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

Page 45: Linux Desktop Operation - Session 1

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

Page 46: Linux Desktop Operation - Session 1

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

Page 47: Linux Desktop Operation - Session 1

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

Page 48: Linux Desktop Operation - Session 1

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

Page 49: Linux Desktop Operation - Session 1

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

Page 50: Linux Desktop Operation - Session 1

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

Page 51: Linux Desktop Operation - Session 1

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

Page 52: Linux Desktop Operation - Session 1

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

Page 53: Linux Desktop Operation - Session 1

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

Page 54: Linux Desktop Operation - Session 1

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

Page 55: Linux Desktop Operation - Session 1

Thank youArash Foroughi

Iran, April 2016

55