linux command line - دانشگاه تحصیلات تکمیلی علوم پایه...

101
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linux Command Line Learning The Shell Ali Shakeri Department of Physics Institute for Advanced Studies in Basic Sciences 20 May 2015

Upload: haphuc

Post on 21-Sep-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Linux Command LineLearning The Shell

Ali Shakeri

Department of PhysicsInstitute for Advanced Studies in Basic Sciences

20 May 2015

Page 2: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Contents

IntroductionMotivationTerminology

Basic CommandsSimple CommandsNavigationFiles And DirectoriesWildcardsI/O Redirection

More About Commands

Permissions

Processes

Page 3: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Introduction

Page 4: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 5: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 6: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 7: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 8: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 9: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 10: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ Linux is available at no cost. This is in sharp contrast to Microsoft Windows.

▶ Anybody is permitted to modify it, including its source code, in any way desired.

▶ There is no Viruses for Linux. Nor trojans, spyware, etc.

▶ There is no force to upgrade. Older versions continue to be supported

▶ Linux software are free and open source.

▶ Linux is a multi user operating system.

▶ Numerous distributions (several hundred) of Linux are available. This allows usersto select the versions which best meet their specific requirements.

Page 11: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 12: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 13: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 14: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 15: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 16: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 17: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ High degree of compatibility with other operating systems.

▶ Linux is a friend of old and tired computers.

▶ Linux is capable of operating on a wide variety of platforms.

▶ There are no secrets in Linux.

▶ You have the control of your computer.

▶ Linux is developing very fast.

▶ It comes out from university.

Page 18: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Not Sufficient Yet?

Page 19: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ You can compile C programs without doing anything special.

▶ There is a default python interpreter on Linux.

▶ Linux is very light-weight.

▶ Linux software are light-weight too.

▶ Scientific software are available on Linux.

Page 20: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ You can compile C programs without doing anything special.

▶ There is a default python interpreter on Linux.

▶ Linux is very light-weight.

▶ Linux software are light-weight too.

▶ Scientific software are available on Linux.

Page 21: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ You can compile C programs without doing anything special.

▶ There is a default python interpreter on Linux.

▶ Linux is very light-weight.

▶ Linux software are light-weight too.

▶ Scientific software are available on Linux.

Page 22: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ You can compile C programs without doing anything special.

▶ There is a default python interpreter on Linux.

▶ Linux is very light-weight.

▶ Linux software are light-weight too.

▶ Scientific software are available on Linux.

Page 23: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

▶ You can compile C programs without doing anything special.

▶ There is a default python interpreter on Linux.

▶ Linux is very light-weight.

▶ Linux software are light-weight too.

▶ Scientific software are available on Linux.

Page 24: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

However These are not Enough toConvert to Linux

Page 25: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Linux?

The main reason to convert to Linux is to

Take Back the Control of Your Computer

Page 26: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Command-Line?

▶ Graphical user interfaces make easy task easy.

▶ Command line interfaces make difficult tasks possible.

▶ Convert an AVI video to MP4 by a simple command.

▶ Create an animation by a one line command.

▶ You have more control on your computer when using command line.

Page 27: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Command-Line?

▶ Graphical user interfaces make easy task easy.

▶ Command line interfaces make difficult tasks possible.

▶ Convert an AVI video to MP4 by a simple command.

▶ Create an animation by a one line command.

▶ You have more control on your computer when using command line.

Page 28: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Command-Line?

▶ Graphical user interfaces make easy task easy.

▶ Command line interfaces make difficult tasks possible.

▶ Convert an AVI video to MP4 by a simple command.

▶ Create an animation by a one line command.

▶ You have more control on your computer when using command line.

Page 29: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Command-Line?

▶ Graphical user interfaces make easy task easy.

▶ Command line interfaces make difficult tasks possible.

▶ Convert an AVI video to MP4 by a simple command.

▶ Create an animation by a one line command.

▶ You have more control on your computer when using command line.

Page 30: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

MotivationWhy Command-Line?

▶ Graphical user interfaces make easy task easy.

▶ Command line interfaces make difficult tasks possible.

▶ Convert an AVI video to MP4 by a simple command.

▶ Create an animation by a one line command.

▶ You have more control on your computer when using command line.

Page 31: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

TerminologyWhat is a Shell?

..

Shell Difinition

.

Shell is a program that takes the keyboard commands and passes them to theoperating system to carry out.

..

Shell Difinition

.

Shell is an interface between the user and the internal parts of the operatingsystem.

Page 32: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

TerminologyWhat is a Shell Prompt?

..

Shell Prompt

.

A shell prompt or command prompt is a set of characters at the start of thecommand line that indicates that the shell is ready to receive the commands.

It ends with a $ for ordinary users and a # for the root users.

[ali@localhost ~]$

Page 33: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

TerminologyWhat is a Terminal?

..

Terminal

.A Terminal is an emulator for shell in Graphical User Interface.

Page 34: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Terminology

..

Computer Hardware

.

Operating System

.

Shell

.

Graphical User Interface

Page 35: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Terminology

..

Computer Hardware

.

Operating System

.

Shell

.

Graphical User Interface

Page 36: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Terminology

..

Computer Hardware

.

Operating System

.

Shell

.

Graphical User Interface

Page 37: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Terminology

..

Computer Hardware

.

Operating System

.

Shell

.

Graphical User Interface

Page 38: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

General InformationDifferent Shells

▶ sh: The original UNIX shell.Written by Stephan Bourne at Bell Labs in 1974.

▶ bash: Bash or Bourne Again Shell is the default shell on Linux.Bash was written for GNU project and has more commands than sh.

▶ csh: csh or the C shell has a syntax similar to C programming language.It is sometimes preferred by programmers.It was created in 1978 by Bill Joy who also wrote the vi text editor at Universityof California Berkeley.

▶ ksh: The Korn Shell developed by David Korn at Bell Labs. It is more like csh.

Page 39: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

General InformationDifferent Shells

▶ sh: The original UNIX shell.Written by Stephan Bourne at Bell Labs in 1974.

▶ bash: Bash or Bourne Again Shell is the default shell on Linux.Bash was written for GNU project and has more commands than sh.

▶ csh: csh or the C shell has a syntax similar to C programming language.It is sometimes preferred by programmers.It was created in 1978 by Bill Joy who also wrote the vi text editor at Universityof California Berkeley.

▶ ksh: The Korn Shell developed by David Korn at Bell Labs. It is more like csh.

Page 40: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

General InformationDifferent Shells

▶ sh: The original UNIX shell.Written by Stephan Bourne at Bell Labs in 1974.

▶ bash: Bash or Bourne Again Shell is the default shell on Linux.Bash was written for GNU project and has more commands than sh.

▶ csh: csh or the C shell has a syntax similar to C programming language.It is sometimes preferred by programmers.It was created in 1978 by Bill Joy who also wrote the vi text editor at Universityof California Berkeley.

▶ ksh: The Korn Shell developed by David Korn at Bell Labs. It is more like csh.

Page 41: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

General InformationDifferent Shells

▶ sh: The original UNIX shell.Written by Stephan Bourne at Bell Labs in 1974.

▶ bash: Bash or Bourne Again Shell is the default shell on Linux.Bash was written for GNU project and has more commands than sh.

▶ csh: csh or the C shell has a syntax similar to C programming language.It is sometimes preferred by programmers.It was created in 1978 by Bill Joy who also wrote the vi text editor at Universityof California Berkeley.

▶ ksh: The Korn Shell developed by David Korn at Bell Labs. It is more like csh.

Page 42: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Basic Commands

Page 43: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Date and calendar

[ali@localhost ~]$ date

Mon May 18 08:20:45 IRDT 2015

[ali@localhost ~]$ cal

May 2015

Su Mo Tu We Th Fr Sa

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

31

Page 44: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Disk drive and memory

[ali@localhost ~]$ df

Filesystem 1K-blocks Used Available Use% Mounted on

devtmpfs 1736276 0 1736276 0% /dev

tmpfs 1744964 152 1744812 1% /dev/shm

tmpfs 1744964 860 1744104 1% /run

tmpfs 1744964 0 1744964 0% /sys/fs

/dev/mapper/fedora -root 100660656 16294852 79229420 18% /

tmpfs 1744964 36 1744928 1% /tmp

/dev/sda1 487652 137593 320363 31% /boot

/dev/mapper/fedora -home 375258800 302930456 53243240 86% /home

[ali@localhost ~]$ free

total used free shared buffers cached

Mem: 3489932 1801160 1688772 81696 80488 1262116

-/+ buffers/cache: 458556 3031376

Swap: 4095996 0 4095996

Page 45: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

List cpu information

[ali@localhost ~]$ lscpu

Architecture: i686

CPU op-mode(s): 32-bit , 64-bit

Byte Order: Little Endian

CPU(s): 4

On-line CPU(s) list: 0-3

Thread(s) per core: 2

Core(s) per socket: 2

Socket(s): 1

Vendor ID: GenuineIntel

CPU family: 6

Model: 58

Model name: Intel(R) Core(TM) i3 -3217U CPU @ 1.80 GHz

Stepping: 9

CPU MHz: 1800.000

CPU max MHz: 1800.0000

CPU min MHz: 800.0000

L1d cache: 32K

L1i cache: 32K

L2 cache: 256K

L3 cache: 3072K

Page 46: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Print working directory

[ali@localhost ~]$ pwd

/home/ali

[ali@localhost ~]$ ls

Desktop Documents Downloads Music Pictures Programming

sources Videos

Page 47: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Long listing format

[ali@localhost ~]$ ls -l

total 32

drwxr -xr -x. 5 ali ali 4096 May 18 08:39 Desktop

drwxr -xr -x. 12 ali ali 4096 May 17 10:08 Documents

drwxr -xr -x. 7 ali ali 4096 May 10 18:12 Downloads

drwxr -xr -x. 9 ali ali 4096 May 2 14:02 Music

drwxr -xr -x. 8 ali ali 4096 May 13 22:38 Pictures

drwxrwxr -x. 17 ali ali 4096 May 4 19:37 Programming

drwxrwxr -x. 5 ali ali 4096 May 11 18:11 sources

drwxr -xr -x. 7 ali ali 4096 May 2 18:55 Videos

Page 48: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Anatomy of the long format

[ali@localhost ~]$ ls -l

total 32

drwxr -xr -x. 5 ali ali 4096 May 18 08:39 Desktop

...

drwxrwxr -x. 17 ali ali 4096 May 4 19:37 Programming

...

▶ First field:first character indicates the type of file.next three are access right for the file owner.next three for the members of the file.next three for everyone else.

▶ Second field: number of hard links

▶ Third field: username of the file’s owner.

▶ Fourth field: username of the group which owns the file.

Page 49: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

List and sort

[ali@localhost ~]$ ls -lt

total 32

drwxr -xr -x. 5 ali ali 4096 May 18 08:39 Desktop

drwxr -xr -x. 12 ali ali 4096 May 17 10:08 Documents

drwxr -xr -x. 8 ali ali 4096 May 13 22:38 Pictures

drwxrwxr -x. 5 ali ali 4096 May 11 18:11 sources

drwxr -xr -x. 7 ali ali 4096 May 10 18:12 Downloads

drwxrwxr -x. 17 ali ali 4096 May 4 19:37 Programming

drwxr -xr -x. 7 ali ali 4096 May 2 18:55 Videos

drwxr -xr -x. 9 ali ali 4096 May 2 14:02 Music

Page 50: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

List and sort

[ali@localhost ~]$ ls -lt --reverse

total 32

drwxr -xr -x. 9 ali ali 4096 May 2 14:02 Music

drwxr -xr -x. 7 ali ali 4096 May 2 18:55 Videos

drwxrwxr -x. 17 ali ali 4096 May 4 19:37 Programming

drwxr -xr -x. 7 ali ali 4096 May 10 18:12 Downloads

drwxrwxr -x. 5 ali ali 4096 May 11 18:11 sources

drwxr -xr -x. 8 ali ali 4096 May 13 22:38 Pictures

drwxr -xr -x. 12 ali ali 4096 May 17 10:08 Documents

drwxr -xr -x. 5 ali ali 4096 May 18 08:39 Desktop

Page 51: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

List almost everything

[ali@localhost ~]$ ls -lA

total 404

drwx ------. 3 ali ali 4096 Oct 29 2014 .adobe

drwxrwxr -x. 2 ali ali 4096 May 4 19:22 .asy

-rw -------. 1 ali ali 27167 May 18 08:48 .bash_history

-rw-r--r--. 1 ali ali 18 Aug 9 2013 .bash_logout

-rw-r--r--. 1 ali ali 193 Aug 9 2013 .bash_profile

-rw-r--r--. 1 ali ali 515 Jan 20 11:09 .bashrc

drwx ------. 24 ali ali 4096 May 17 11:06 .cache

drwxrwxr -x. 3 ali ali 4096 Sep 23 2014 .color

drwx ------. 33 ali ali 4096 May 3 20:22 .config

drwxr -xr -x. 5 ali ali 4096 May 18 08:39 Desktop

drwxr -xr -x. 12 ali ali 4096 May 17 10:08 Documents

drwxr -xr -x. 7 ali ali 4096 May 10 18:12 Downloads

drwxrwxr -x. 3 ali ali 4096 Nov 18 19:31 .eclipse

drwx ------. 2 ali ali 4096 Jan 4 17:53 .elinks

-rw-rw-r--. 1 ali ali 195 Jan 24 19:44 .ems.cfg

-rw -------. 1 ali ali 16 Sep 23 2014 .esd_auth

drwxrwxr -x. 2 ali ali 36864 Oct 13 2014 .fonts

Page 52: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

List another directory

[ali@localhost ~]$ ls .fonts

ABAN.TTF JALAL_SF.TTF

ABO -THAR.TTF JOKERMAN.TTF

ADOBEARABIC -BOLDITALIC.TTF JUICE___.TTF

ADOBEARABIC -BOLD.TTF Junicode -BoldItalic.ttf

ADOBEARABIC -ITALIC.TTF JUNICODE -BOLD.TTF

ADOBEARABIC -REGULAR.TTF JUNICODE -ITALIC.TTF

...

Page 53: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Read the manuals

man ls

NAME

ls - list directory contents

SYNOPSIS

ls [OPTION ]... [FILE ]...

DESCRIPTION

List information about the FILEs (the current

directory by default ). Sort entries alphabetically.

Mandatory arguments to long options are mandatory for short options too.

-a, --all

do not ignore entries starting with .

-A, --almost -all

do not list implied . and ..

...

Page 54: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change directory

[ali@localhost ~]$ cd Music/Rock/

[ali@localhost Rock]$

[ali@localhost Rock]$ pwd

/home/ali/Music/Rock

[ali@localhost Rock]$ cd ..

[ali@localhost Music]$

[ali@localhost Music]$ cd .

[ali@localhost Music]$

[ali@localhost Music]$ cd ~

[ali@localhost ~]$

Page 55: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Some facts about filenames

▶ Filenames that begin with ”.” character are hidden.

▶ Filenames and commands are case sensitive.

▶ Linux has no concept of a file extension.

▶ Try not to use spaces in filenames, use underscore instead.

Page 56: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Some facts about filenames

▶ Filenames that begin with ”.” character are hidden.

▶ Filenames and commands are case sensitive.

▶ Linux has no concept of a file extension.

▶ Try not to use spaces in filenames, use underscore instead.

Page 57: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Some facts about filenames

▶ Filenames that begin with ”.” character are hidden.

▶ Filenames and commands are case sensitive.

▶ Linux has no concept of a file extension.

▶ Try not to use spaces in filenames, use underscore instead.

Page 58: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Some facts about filenames

▶ Filenames that begin with ”.” character are hidden.

▶ Filenames and commands are case sensitive.

▶ Linux has no concept of a file extension.

▶ Try not to use spaces in filenames, use underscore instead.

Page 59: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Determining file types

[ali@localhost ~]$ file Music/

Music/: directory

[ali@localhost ~]$ file Pictures/group_photo_2613.jpg

Pictures/group_photo_2613.jpg: JPEG image data , EXIF standard 2.21

[ali@localhost ~]$ file Music /10\ Shadi.mp3

Music /10 Shadi.mp3: Audio file with ID3 version 2.3.0

Page 60: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Files And DirectoriesMake directories

[ali@localhost ~]$ mkdir sample_dir

[ali@localhost ~]$ cd sample_dir

[ali@localhost sample_dir]$ mkdir dir1 dir2 dir3

[ali@localhost sample_dir]$ ls

dir1 dir2 dir3

[ali@localhost sample_dir]$ cd dir1

[ali@localhost dir1]$ touch script_1 script_2

[ali@localhost dir1]$ ls

script_1 script_2

Page 61: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Files And DirectoriesCopy and move

[ali@localhost dir1]$ cp script_1 script_2 ../ dir2

[ali@localhost dir1]$ ls ../ dir2

script_1 script_2

[ali@localhost dir1]$ mv script_1 ../ dir3

[ali@localhost dir1]$ ls

script_2

[ali@localhost dir1]$ cd ../ dir3/

[ali@localhost dir3]$ ls

script_1

Page 62: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Files And DirectoriesList multiple directories

[ali@localhost sample_dir]$ ls

dir1 dir2 dir3

[ali@localhost sample_dir]$ ls dir1 dir2 dir3

dir1:

script_2

dir2:

script_1 script_2

dir3:

script_1

Page 63: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Files And DirectoriesRemove directories

[ali@localhost sample_dir]$ rm -r dir1 dir2

[ali@localhost sample_dir]$ ls

dir3

▶ Linux assumes you are big enough to take care of yourself.

▶ Once you removed something using rm, it’s gone.

Page 64: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Files And DirectoriesRemove directories

[ali@localhost sample_dir]$ rm -r dir1 dir2

[ali@localhost sample_dir]$ ls

dir3

▶ Linux assumes you are big enough to take care of yourself.

▶ Once you removed something using rm, it’s gone.

Page 65: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ ls -l

total 56

-rw-rw-r--. 1 ali ali 36 Jan 11 20:57 defs.h

-rw-rw-r--. 1 ali ali 79 Jan 11 21:07 exponential.cpp

-rw-rw-r--. 1 ali ali 29 Jan 11 20:57 exponential.h

-rw-rw-r--. 1 ali ali 1596 Jan 23 20:04 exponential.o

-rw-rw-r--. 1 ali ali 489 Jan 22 17:15 main.cpp

-rw-rw-r--. 1 ali ali 2756 Jan 23 20:04 main.o

-rw-rw-r--. 1 ali ali 719 Jan 23 20:07 Makefile

-rw-rw-r--. 1 ali ali 76 Jan 11 21:06 radical.cpp

-rw-rw-r--. 1 ali ali 25 Jan 11 20:57 radical.h

-rw-rw-r--. 1 ali ali 1584 Jan 23 20:04 radical.o

-rw-rw-r--. 1 ali ali 932 May 18 11:56 README

-rw-rw-r--. 1 ali ali 73 Jan 11 21:06 square.cpp

-rw-rw-r--. 1 ali ali 24 Jan 11 20:57 square.h

-rw-rw-r--. 1 ali ali 1548 Jan 23 20:04 square.o

Page 66: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ ls -l *

-rw-rw-r--. 1 ali ali 36 Jan 11 20:57 defs.h

-rw-rw-r--. 1 ali ali 79 Jan 11 21:07 exponential.cpp

-rw-rw-r--. 1 ali ali 29 Jan 11 20:57 exponential.h

-rw-rw-r--. 1 ali ali 1596 Jan 23 20:04 exponential.o

-rw-rw-r--. 1 ali ali 489 Jan 22 17:15 main.cpp

-rw-rw-r--. 1 ali ali 2756 Jan 23 20:04 main.o

-rw-rw-r--. 1 ali ali 719 Jan 23 20:07 Makefile

-rw-rw-r--. 1 ali ali 76 Jan 11 21:06 radical.cpp

-rw-rw-r--. 1 ali ali 25 Jan 11 20:57 radical.h

-rw-rw-r--. 1 ali ali 1584 Jan 23 20:04 radical.o

-rw-rw-r--. 1 ali ali 932 May 18 11:56 README

-rw-rw-r--. 1 ali ali 73 Jan 11 21:06 square.cpp

-rw-rw-r--. 1 ali ali 24 Jan 11 20:57 square.h

-rw-rw-r--. 1 ali ali 1548 Jan 23 20:04 square.o

Page 67: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ ls -l s*

-rw-rw-r--. 1 ali ali 73 Jan 11 21:06 square.cpp

-rw-rw-r--. 1 ali ali 24 Jan 11 20:57 square.h

-rw-rw-r--. 1 ali ali 1548 Jan 23 20:04 square.o

[ali@localhost Test]$ ls -l *.cpp

-rw-rw-r--. 1 ali ali 79 Jan 11 21:07 exponential.cpp

-rw-rw-r--. 1 ali ali 489 Jan 22 17:15 main.cpp

-rw-rw-r--. 1 ali ali 76 Jan 11 21:06 radical.cpp

-rw-rw-r--. 1 ali ali 73 Jan 11 21:06 square.cpp

Page 68: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ ls -l [[: upper :]]*

-rw-rw-r--. 1 ali ali 719 Jan 23 20:07 Makefile

-rw-rw-r--. 1 ali ali 932 May 18 11:56 README

[ali@localhost Test]$ ls -l ????.*

-rw-rw-r--. 1 ali ali 36 Jan 11 20:57 defs.h

-rw-rw-r--. 1 ali ali 489 Jan 22 17:15 main.cpp

-rw-rw-r--. 1 ali ali 2756 Jan 23 20:04 main.o

Page 69: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ ls -l *

-rw-rw-r--. 1 ali ali 36 Jan 11 20:57 defs.h

-rw-rw-r--. 1 ali ali 79 Jan 11 21:07 exponential.cpp

-rw-rw-r--. 1 ali ali 29 Jan 11 20:57 exponential.h

-rw-rw-r--. 1 ali ali 1596 Jan 23 20:04 exponential.o

-rw-rw-r--. 1 ali ali 489 Jan 22 17:15 main.cpp

-rw-rw-r--. 1 ali ali 2756 Jan 23 20:04 main.o

-rw-rw-r--. 1 ali ali 719 Jan 23 20:07 Makefile

-rw-rw-r--. 1 ali ali 76 Jan 11 21:06 radical.cpp

-rw-rw-r--. 1 ali ali 25 Jan 11 20:57 radical.h

-rw-rw-r--. 1 ali ali 1584 Jan 23 20:04 radical.o

-rw-rw-r--. 1 ali ali 932 May 18 11:56 README

-rw-rw-r--. 1 ali ali 73 Jan 11 21:06 square.cpp

-rw-rw-r--. 1 ali ali 24 Jan 11 20:57 square.h

-rw-rw-r--. 1 ali ali 1548 Jan 23 20:04 square.o

Page 70: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost Test]$ mkdir src lib bin && mv *.cpp src; mv *.h lib; mv *.o bin

[ali@localhost Test]$ ls *

Makefile README

bin:

exponential.o main.o radical.o square.o

lib:

defs.h exponential.h radical.h square.h

src:

exponential.cpp main.cpp radical.cpp square.cpp

Page 71: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Wildcards

[ali@localhost ~]$ mkdir photos

[ali@localhost ~]$ cd photos/

[ali@localhost photos]$ mkdir {2007..2009} -{01..12}

[ali@localhost photos]$ ls

2007 -01 2007 -07 2008 -01 2008 -07 2009 -01 2009 -07

2007 -02 2007 -08 2008 -02 2008 -08 2009 -02 2009 -08

2007 -03 2007 -09 2008 -03 2008 -09 2009 -03 2009 -09

2007 -04 2007 -10 2008 -04 2008 -10 2009 -04 2009 -10

2007 -05 2007 -11 2008 -05 2008 -11 2009 -05 2009 -11

2007 -06 2007 -12 2008 -06 2008 -12 2009 -06 2009 -12

Page 72: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Redirect standard output to file

[ali@localhost ~]$ mkdir test && cd test

[ali@localhost test]$ ls -l /usr > output.txt

[ali@localhost test]$ less output.txt

total 284

dr-xr -xr -x. 3 root root 69632 May 16 11:53 bin

drwxr -xr-x. 2 root root 4096 Aug 7 2013 games

drwxr -xr-x. 113 root root 12288 May 2 19:29 include

dr-xr -xr -x. 220 root root 139264 May 9 17:39 lib

drwxr -xr-x. 3 root root 4096 Oct 30 2014 lib64

drwxr -xr-x. 37 root root 12288 May 2 19:28 libexec

drwxr -xr-x. 11 root root 4096 Oct 29 2014 local

dr-xr -xr -x. 2 root root 20480 May 2 19:29 sbin

drwxr -xr-x. 300 root root 12288 May 4 19:22 share

drwxr -xr-x. 4 root root 4096 Dec 12 2013 src

lrwxrwxrwx. 1 root root 10 Dec 12 2013 tmp -> ../var/tmp

Page 73: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Append standard output to file

Using ¿¿ operator will result output appended to the file:

[ali@localhost test]$ ls -l /home

Page 74: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Join two files together

[ali@localhost test]$ ls

data1.txt data2.txt data3.txt data4.txt data5.txt

[ali@localhost test]$ cat data .*.txt > data.txt

Page 75: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Pipelines

Read data from standard output of one command1 and send it to standard input ofcommand2:

command1 | command2

Pipelines are used to perform complex operations on data

[ali@localhost ~]$ ls /bin | sort | less

Page 76: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

More About Commands

Page 77: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

A command could be one of four different things:

▶ An executable program: Compiled binary programs written in C and C++ orprograms written in scripting languages such as shell or python.

▶ Shell builtins: The commands that belong to the bash itself.

▶ A shell function: Shell scripts that exist into the environment.

▶ An alias: Commands that are build from other commands.

Page 78: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

A command could be one of four different things:

▶ An executable program: Compiled binary programs written in C and C++ orprograms written in scripting languages such as shell or python.

▶ Shell builtins: The commands that belong to the bash itself.

▶ A shell function: Shell scripts that exist into the environment.

▶ An alias: Commands that are build from other commands.

Page 79: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

A command could be one of four different things:

▶ An executable program: Compiled binary programs written in C and C++ orprograms written in scripting languages such as shell or python.

▶ Shell builtins: The commands that belong to the bash itself.

▶ A shell function: Shell scripts that exist into the environment.

▶ An alias: Commands that are build from other commands.

Page 80: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

A command could be one of four different things:

▶ An executable program: Compiled binary programs written in C and C++ orprograms written in scripting languages such as shell or python.

▶ Shell builtins: The commands that belong to the bash itself.

▶ A shell function: Shell scripts that exist into the environment.

▶ An alias: Commands that are build from other commands.

Page 81: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

A command could be one of four different things:

▶ An executable program: Compiled binary programs written in C and C++ orprograms written in scripting languages such as shell or python.

▶ Shell builtins: The commands that belong to the bash itself.

▶ A shell function: Shell scripts that exist into the environment.

▶ An alias: Commands that are build from other commands.

Page 82: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

What is a command?

[ali@localhost ~]$ type type

type is a shell builtin

[ali@localhost ~]$ type ls

ls is aliased to `ls --color=auto '

[ali@localhost ~]$ type cp

cp is /usr/bin/cp

Page 83: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Appropriate Commands

[ali@localhost ~]$ apropos pdf

dvipdfm (1) - produce PDF files directly from DVI files

dvipdft (1) - create thumbnail images for use with dvipdfm

epstopdf (1) - convert an EPS file to PDF

pdf180 (1) - rotate the pages of pdf files

pdf270 (1) - rotate the pages of pdf files

pdf90 (1) - rotate the pages of pdf files

pdfflip (1) - rotate the pages of pdf files

pdfjam (1) - A shell script for manipulating PDF files

pdftocairo (1) - PDF to PNG/JPEG/TIFF/PDF/PS/EPS/SVG

pdftohtml (1) - program to convert PDF files into HTML , XML and PNG images

pdftoppm (1) - Portable Document Format to Portable Pixmap converter

pdftops (1) - Portable Document Format (PDF) to PostScript converter

...

Page 84: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Appropriate Commands

[ali@localhost ~]$ apropos download

aria2c (1) - The ultra fast download utility

axel (1) - A light download accelerator for Linux.

fxload (8) - Firmware download to EZ-USB devices

git -fetch (1) - Download objects and refs from another repository

lwp -download (1) - Fetch large files from the web

repotrack (1) - track a package and its dependencies and download them

smbget (1) - wget -like utility for download files over SMB

update -pciids (8) - download new version of the PCI ID list

wget (1) - The non -interactive network downloader.

youtube -dl (1) - download videos from youtube.com or other video platforms

yumdownloader (1) - download RPM packages from Yum repositories

Page 85: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Create New Commands

[ali@localhost ~]$ alias inst='sudo apt -get install '

[ali@localhost ~]$ inst gnuplot

[sudo] password for ali:

[ali@localhost ~]$ unalias inst

Page 86: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Create New Commands

[ali@localhost ~]$ alias ..='cd ..'

alias update='sudo apt -get update && sudo apt -get upgrade '

alias playwave='for i in *.wav; do mplayer "$i"; done '

alias playogg='for i in *.ogg; do mplayer "$i"; done '

alias playmp3='for i in *.mp3; do mplayer "$i"; done '

Page 87: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Permissions

Page 88: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

▶ Linux is a multi-user operating system.

▶ More than on person can be using the computer at the same time.

▶ Users should be protected from each other.

Page 89: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

▶ Linux is a multi-user operating system.

▶ More than on person can be using the computer at the same time.

▶ Users should be protected from each other.

Page 90: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

As a regular user you do not have permission to do everything.

[ali@localhost ~]$ cp linux_program.pdf /usr/bin/

cp: cannot create regular file /usr/bin/linux_program.pdf: Permission denied

Page 91: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Permission Attributes

As a regular user you do not have permission to do everything.

[ali@localhost ~]$ ls -l linux_program.pdf

-rw-rw-r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

- rw- rw- r–(File type) (Owner) (Group) (Everyone)

Page 92: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change File Mode

chmod: Change file mode

[ali@localhost ~]$ ls -l linux_program.pdf

-rw-rw-r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

[ali@localhost ~]$ chmod +x linux_program.pdf

[ali@localhost ~]$ ls -l linux_program.pdf

-rwxrwxr -x. 1 ali ali 70595 May 19 14:05 linux_program.pdf

[ali@localhost ~]$ chmod -x linux_program.pdf

[ali@localhost ~]$ ls -l linux_program.pdf

-rw-rw-r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

Page 93: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change File Mode

[ali@localhost ~]$ ls -l linux_program.pdf

-rw-rw-r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

[ali@localhost ~]$ chmod u+x linux_program.pdf

[ali@localhost ~]$ ls -l linux_program.pdf

-rwxrw -r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

u means user.

Page 94: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change File Mode

[ali@localhost ~]$ ls -l linux_program.pdf

-rw-rw-r--. 1 ali ali 70595 May 19 14:05 linux_program.pdf

[ali@localhost ~]$ chmod og-rw linux_program.pdf

[ali@localhost ~]$ ls -l linux_program.pdf

-rw -------. 1 ali ali 70595 May 19 14:05 linux_program.pdf

g means group. o means others.

Page 95: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change Identities

The su command start a shell as another user

su -[options] [user]

If user is not specified, the superuser is assumed

[ali@localhost ~]$ su -

Password:

Last login: Sun May 17 18:32:14 IRDT 2015 on pts/1

[root@localhost ~]#

When finished, enter exit

[root@localhost ~]# exit

logout

[ali@localhost ~]$

Page 96: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Change Password

[ali@localhost ~]$ passwd

Changing password for user ali.

Changing password for ali.

(current) UNIX password:

New password:

BAD PASSWORD: The password is shorter than 8 characters

New password:

BAD PASSWORD: It is based on a dictionary word

New password:

BAD PASSWORD: The password is too similar to the old one

passwd: Have exhausted maximum number of retries for service

Page 97: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Processes

Page 98: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Viewing Processes Dynamically

[ali@localhost ~]$ top

Tasks: 183 total , 2 running , 181 sleeping , 0 stopped , 0 zombie

%Cpu(s): 0.2 us, 0.7 sy, 24.5 ni, 74.1 id , 0.4 wa, 0.2 hi, 0.0 si, 0.0 st

KiB Mem: 3489932 total , 3371280 used , 118652 free , 3912 buffers

KiB Swap: 4095996 total , 284040 used , 3811956 free , 3022980 cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

11851 ali 39 19 196816 32068 23280 R 99.7 0.9 0:26.71 tracker -extract

1030 root 20 0 59484 21304 14472 S 1.0 0.6 1:55.36 Xorg

9734 ali 20 0 153768 16804 12172 S 0.7 0.5 0:03.62 gnome -terminal -

1705 ali 20 0 633536 101224 23100 S 0.3 2.9 2:55.23 gnome -shell

11804 ali 20 0 5580 2780 2400 R 0.3 0.1 0:00.23 top

1 root 20 0 8564 3760 2604 S 0.0 0.1 0:02.27 systemd

2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd

3 root 20 0 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd /0

5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker /0:0H

7 root 20 0 0 0 0 S 0.0 0.0 0:03.84 rcu_sched

8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh

9 root 20 0 0 0 0 S 0.0 0.0 0:03.95 rcuos/0

10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0

11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration /0

12 root rt 0 0 0 0 S 0.0 0.0 0:00.02 watchdog /0

13 root rt 0 0 0 0 S 0.0 0.0 0:00.02 watchdog /1

14 root rt 0 0 0 0 S 0.0 0.0 0:00.02 migration /1

Page 99: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Kill a Processes

[ali@localhost ~]$ kill PID

Example:

[ali@localhost ~]$ kill 9734

Page 100: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Job in a background

[ali@localhost ~]$ firefox &

[1] 12125

[ali@localhost ~]$ jobs

[1]+ Running firefox &

Bring back the job to the foreground:

[ali@localhost ~]$ fg %1

Page 101: Linux Command Line - دانشگاه تحصیلات تکمیلی علوم پایه ...a.shakeri/files/linux/part_1.pdf · 2018-02-20 · Motivation Why Linux? Linux is available at

..........

.....

....................................................................................

......

.....

.....

.

Thank You