Vous êtes sur la page 1sur 34

User/Group/Permissions

Linux model
Users/Groups are used to control access to
files/resources
Every user is assigned a unique User ID (UID)
Every group is assigned a unique Group ID
(GID)
User information is stored in /etc/passwd
Group information is stored in /etc/group
Password and aging information in /etc/shadow
root user can access files/folder regardless of
permissions
-rw-r--r-- 1 student class 38 18:22 a.txt

permissions
Owner (user)
Owner (group)
cont...
-rw-r--r-x
1st type of file
2,3,4 permissions for owner (user)
5,6,7 permissions for owner (group)
8,9,10 permissions for others
cont...
For files
r (read) Read a file
w (write)
Modify contents of a file (not
delete file)
x (execute)
execute/run the file, if it has
executable content
- (no
permission)
For Folders
r (read) List the contents (ls)
w (write) Create/Delete a files
x (execute) cd into the folder (cd)
- (no
permission)
Read (r)(4)
Write (w)(2)
Execute (x)(1)
Owner-user (u)
Owner-group(g)
Others (o)
chmod
chmod u+rwx a.txt
chmod ug-r a.txt
chmod ugo+x a.txt
chmod a+x a.txt
chmod...
chmod 641 a.txt
chmod 001 a.txt
chmod 777 a.txt
chown/chgrp
-rw-r--r-- 1 student class 38 18:22 a.txt
chown root:staff a.txt
chown root a.txt
chown :staff a.txt
chgrp staff a.txt
Standard I/O
I/O channel Keyword Default File descriptor operator operator(append)
Standard Input STDIN keyboard 0 <
Standard
output
STDOUT Monitor 1 > >>
Standard error STDERR Monitor 2 2> 2>>
example...
tr 'a-z' 'A-Z'
ls /home /nothing
PIPE
PIPE symbol | - redirects output of one
command as the input of the next command
ls | tr 'a-z' 'A-Z'
ls -l | tr 'a-z' 'A-Z' | lpr
ls -l | tee 1.txt | tr 'a-z' 'A-Z' | tee 2.txt | lpr
Text processing cmds
grep (print matching lines)
grep 'linux' bigfile.txt
grep -i 'linux' bigfile.txt (ignore case)
grep -c 'linux' bigfile.txt (no. of lines)
sort
sort (sort according to specified column)
sort -k1 -t: /etc/passwd (sort 1
st
column)
sort -k3 -t: -n /etc/passwd (sort numeric col.)
sort -k3 -t: -r /etc/passwd (reverse sort)
uniq
uniq (display only uniq values from sorted
input)
uniq sortedfile.txt
uniq -c sortedfile.txt (display count)
uniq -u sortedfile.txt (display values repeated
only once)
wc
wc (line, word, character count)
wc abc.txt
wc -l abc.txt
wc -w abc.txt
wc -c abc.txt
soft/hard links
Linux partitions are formatted with ext2/ext3
filesystem
The filesystem consists of 'super blocks' and
'data blocks'
Super blocks contain meta-data information
such as timestamp,permissions, owner, and
data block addresses (similar to a index of a
book), but not the name of the file.
Files are identified with a unique number,
called inode number stored in super block
Data blocks contain the actual data for a file.
How is file accessed
A directory internally stores the names of the
file and the corresponding inode numbers. (ls -
i)
While accessing a file, first it's inode number is
retrived, then the information about that inode
number is retrived from the super block, and
then the data is accessed.
Soft/Symbolic link
Soft links are links to the names of file
ln -s data.txt link1
Here data.txt is the existing file. link1 is the
soft link created
Link1 ---> data.txt ----> inode number
Hard link
Hard links are direct links to inode numbers
ln data.txt newdata.txt
data.txt ----> inode number
newdata.txt ----^^
VI editor
Most common text editor on Unix/Linux
platforms.
Supports a lot of complex features
Fully keyboard based.
VI modes
Command mode: copy, paste, delete, etc
Insert mode: type/insert text
Ex mode: save, search/replace, configure vi
Switching modes
Command mode is the default mode, Esc key
can be used to come back to command mode
To go to insert mode press i, a, o
To go to Ex mode press :
Command mode
Moving cursor (one character)
h -> left, j -> down, k -> up, l -> right
One word
w --> forward , b --> back
One sentence
( ---> back by one sentence, ) forward by one
sentence
One paragraph
{ --> back by one para, } forward by one para
Delete Copy change
line dd yy cc
word dw yw cw
sentence d) y) c)
paragraph d} y} c}
cont...
Paste
p, P
Undo
u, U
Capitalize letter
~
Insert mode
i --> insert before cursor
a --> append after cursor
o --> open a blank line below cursor
Ex mode
Write
:w
Quit
:q
Quit without saving
:q!
Write and quit
:wq
cont...
Show numbering
:set number
Automatic tabs
:set autoindent
search/replace
:1,10s/cat/dog/g
:%s/cat/dog/g
Process
ps
ps aux
-a (all user process)
-u (display user name)
-x (display auxillary/background processes)
Cont
pstree
$ pstree p
top
kill
$ kill 6002
$ kill -9 6001
Network
Ipaddres: A 32-bit number to uniquely identify a
computer
Netmask: A 32-bit number to identify which
computers are in the same network.
Gateway Ipaddres: Ipaddress of the
computer/device which connect two or more
networks
Computer1
IP: 192.168.1.10
Mask: 255.255.255.0
Computer1
IP: 192.168.1.11
Mask: 255.255.255.0
telnet 192.168.1.11
ssh 192.168.1.11
ftp 192.168.1.11
cont..
whoami (display current user name)
who (display info about logged in users)
w (display more info about logged in users)

Vous aimerez peut-être aussi