You are on page 1of 35

LINUX SHELL

Choopan Rattanapoka

Introduction

Linux command line 3


Virtual

Terminal
Graphical Terminal
Remote Terminal (Telnet, SSH)

command line
Shell
Linux shell
BASH (Bourne-again shell)

Linux Shell

terminal command prompt


Linux shell

Prompt
[choopan@localhost ~]$ $ =
# =

Path

whoami

Linux
whoami

Login Linux
root
root Login
su

Ctrl+D exit Enter shell


root

Directory

Directory
pwd
cd
mkdir
mv
ls
rm
rmdir

directory
directory
Directory
directory
directory

directory

Directory
directory Hello directory Test
home directory ()
directory

Linux Filesystem (1)


Linux directory ( folder)
Directory Linux

root
home
bin
sbin
lib
usr

home directory
directory home
Linux

library

usr/bin
usr/sbin
usr/lib



library

Linux Filesystem (2)

var
log, database, web, mail
boot
boot
etc
config
lost+found

media
dynamic (USB key,
CD-rom)
misc
NFS
srv
web, ftp, cvs
mnt
(CD-ROM, remote file)
opt
3rd-party
proc

dev
hardware (HDD, network card)
tmp

ls -l list
Directory

Linux 3


drwxrwxrw
x
all
group
user
directory
rwx

r = read
w = write
x=
execute




link directory

(File types)

-
d directory
l soft link
b block device (HDD, CD-ROM)
c character device (modem)
s socket network
p pipe

(1)

chmod (change mode)


3

(user) u
(group) g
(all) a
(read) r
(write) w
(execute) x

myfile.txt

chmod g+w myfile.txt

(2)


3 , ,
, ,

rwx
421

myfile.txt




chmod 740 myfile.txt

touch Linux

testpriv1
testpriv2

testpriv1

: touch < >

testpriv2

Text Editor : vi

Linux command
line text editor vi
vi
text
editor
vi Linux Unix
Linux

vi

vi 2

vi

vi

vi
vi
vi ESC

vi

Up arrow, k

cursor 1

Down arrow, j

cursor 1

Left arrow, h

cursor 1

Right arrow, l

cursor 1

:q

:q!

:w

:wq , ZZ

cursor

dw

1 cursor

dd

1 cursor

vi (2)

/ <text>

yy

undo
Copy cursor

yw

Copy cursor

Paste copy

cursor

cursor

<>G

<>

hello vi
Hello everybody
This is my text file created by vi
Try to copy the following line 5
times
HelloWorld
HelloWorld
HelloWorld
HelloWorld
HelloWorld
Try to save this file with :w
ello
XHelloWorldX

cat

cat 1 2

more

more

less


head

tail
head tail option -n
head

-n 10

10

tail

-n 10

10

link

Linux link 2
Soft link
Hard link

Soft link shortcut Windows



softlink ln s TARGET link_name
softlink

Hard link Linux


hardlink ln TARGET link_name

Link

soft link ect hello


hard link cit hello
link ect cit cat
hello
link ect cit cat
hello
link ect cit cat

text processing
Comman
d

Usage

Description

wc

wc < >

grep

grep <> < >

cut

cut < >

sort

sort < >

wc

option

-l
-w
-c

grep

grep
grep

root /etc/passwd
root /etc/passwd

grep
regular expression (option r)
Regular expression
pattern

Regular expression
Pattern

Usage

[aeiou]

Matching 1 a, e, i, o, u

[a-z]

Matching a z

[a-z][A-Z]

Matching a z A Z

^<pattern>

Matching
pattern

<pattern>$

Matching pattern

^[a-z][0-9]$
.

Matching a z

<pattern>+

Matching pattern 1

<pattern>*

Matching pattern 0

<pattern>?

Matching pattern 0 1

Matching 1

grep -r

grep cit
Hello
Hello
World
World
HelloWorld
4

cut

cut option
-c


-f

-d (delimiter)
-c -f 5
N

N
N N
N-M
N M
-M
M
N,M,.. N, M,

cut

/etc/passwd
: root:x:0:0:root:/root:/bin/bash

username:password:userID:groupID:name:HomeDirecto
ry:shell
cut username

cut username userID

cut -d: -f1 /etc/passwd


cut -d: -f1,3 /etc/passwd

cut 3

cut -c-3 /etc/passwd


cut -c1-3 /etc/passwd

sort

sort
sort [option]
/etc/passwd
sort

/etc/passwd

option -n
sort

-n

Standard I/O devices

Linux, Unix concept I/O


streams
3
standard

input (default keyboard)


standard output (default monitor)
standard error (default monitor)

standard input
standard output standard error
Redirection

Redirection

redirect standard streams


3 > , >>, <

> redirect standard output


cat /etc/passwd > mypass

>> redirect standard output >



< redirect standard input
keyboard

mysql databasename < sql.txt

redirect standard error 2 >

ls l xerdf 2> output

Piping

redirect pipe piping


| (vertical bar)
output |
input |
piping

: root
/etc/passwd
cat

/etc/passwd | grep root

Help Linux

Linux Linux help

help Linux man (manual)


: help ls
man

ls

/etc/passwd Linux
username, home directory, shell
exo1
userID
exo2
username username s
exo3
username username er
exo4

You might also like