Post on 07-Feb-2018
7/21/2019 Lecture on Linux 1
1/19
7/21/2019 Lecture on Linux 1
2/19
Going with tradition
Background and History Unix
GNU : Richard Stallman
Linux : Linus Torvalds Unix philosophy
Small tools can do big tasks
Write programs that do one thing and do it well. Write programs to work together.
Everything is a file
7/21/2019 Lecture on Linux 1
3/19
Organization of File System I
/ The root
/bin
Binaries
/dev
Even your devices are mapped to files
/proc
Your processes are files too :)
7/21/2019 Lecture on Linux 1
4/19
Organization of File System II
/etc Configuration files
/lib
Essential System Libraries /home
Your home directories
/root
Root's home directory
7/21/2019 Lecture on Linux 1
5/19
Organization of File System III
/sbin System Binaries
/tmp
Temporary files /usr
User tools and binaries
/var
Variable data files including logs
/opt
7/21/2019 Lecture on Linux 1
6/19
Users I
/etc/passwd [DEMO]
Every user on a Linux system has
a username
a user ID, or UID for short an integer between 0 and 65534
a group ID, or GID for short an integer between 0 and 65534
a home directory
a default shell (what s a shell? comes later!)
memberships to one (or more groups)
a password!!
root
The God of a Linux system called the super-user
Has UID=0
Has GID=0
Has access to everything
7/21/2019 Lecture on Linux 1
7/19
Users II
What are groups? A collection of users which would be sharing ownership to some
common service, directory or files.
/etc/groups [DEMO]
One user can belong to many groups and one group cancontain many users
7/21/2019 Lecture on Linux 1
8/19
Permissions I
Every file and directory has permissions Permissions with respect to
User (u)
Group (g) Others (o)
Permissions
read (r)
write (w)
execute (x)
rwxrwxrwx
Owner Group Other
7/21/2019 Lecture on Linux 1
9/19
Meaning of rwx Read, write, execute mean different things wrtdirectories and files
Command Permissions on file Permissions on directory
cd /home/abhask N/A xls /home/abhask/*.c none r
ls -l /home/abhask/*.c none rx
cat myfile r x
cat >>myfile w x
./runme (executable) x x
./cleanup.sh (script) rx xrm filename none x
touch newfile N/A x
Permissions II
7/21/2019 Lecture on Linux 1
10/19
Permissions III
Notations r = 4
w = 2
x = 1 Example:
rwxr-x--x
rwx => 4+2+1=7 r-x => 4+0+1=5
--x => 0+0+1=1
Permissions are 751
7/21/2019 Lecture on Linux 1
11/19
Special Permissions
Sticky Bit t = 1000
Set UID
s = 4000 Running a program with privileges of the owner
Set GID
s = 2000
t-wxr-xr-x
1355
but shown as: -wxr-xr-t
7/21/2019 Lecture on Linux 1
12/19
Checking Permissions
Checking permissions of files [DEMO] ls -l
More about the ls command later
7/21/2019 Lecture on Linux 1
13/19
Lets change permissions
chmod [options] Mode[,Mode] file
some option
-R
--reference=file
Modes [ugoa] [+-=][rwxXstugo]
Octal notation
Examples chmod 755 file.c
chmod u=rwx,g=rx,o=rx file.c
DEMO
7/21/2019 Lecture on Linux 1
14/19
Changing Owner
chown [options] owner[:group] file Options
-R = recursive
--reference=rfile
owner
can be either string or UID
group
optional
can be either string or GID
DEMO
h
7/21/2019 Lecture on Linux 1
15/19
Change group
chgrp [option] group file
option
-R = recursive
--reference=rfile
group can be either string or GID
DEMO
7/21/2019 Lecture on Linux 1
16/19
Processes ps to view processes
ps ax ps aux
DEMO
top to view processes kill killing processes by pid
kill PID1 PID2 PID3 ...
killall killing processes by name killall NAME1 NAME2 NAME3 ...
options
-e, -g, -v
O h B i C d
7/21/2019 Lecture on Linux 1
17/19
Other Basic Commands
rm [options] FILE .. options
-R = recursive
-f = force
-i = interactive
mv [options] SRC DEST
options
-f = force
-i = interactive
-b = backup
-u = update
G i h l !
7/21/2019 Lecture on Linux 1
18/19
Getting help!
Manual pages getting help in Linux
man [-k] command
info [menu-item]
Dr. Google! Read this!
man man
info info
A i t
7/21/2019 Lecture on Linux 1
19/19
Assignment
Run mozilla, and try to figure out why killall -e
mozilla doesnt work?
Why is the set UID bit set for su command?
How do you check the man page for /etc/passwd ?
How do you list all the files in a particular directory(including subdirectories)? (no use of cd)
What commands can be used for compressingfiles in linux? (Hint, use man -k).