linux – lecture 3
DESCRIPTION
LINUX – lecture 3. Memory Management I/O Subsystem Management File system Network. Memory Management. Virtual memory concept Useful commands top free. I/O Subsystem Management. Hierachical file system. The file system. /usrUser program /varLogg files, spool files, mail, etc - PowerPoint PPT PresentationTRANSCRIPT
LINUX – lecture 3
• Memory Management
• I/O Subsystem Management
• File system
• Network
Memory Management
• Virtual memory concept
• Useful commands•top•free
I/O Subsystem Management
• Hierachical file system
4
The file system
• /usr User program
• /var Logg files, spool files, mail, etc
• /tmp Temporary files
• /bin Linux commands
• /sbin Commands for the sys. Admin.
• /boot The kernel and boot files
• /dev Hardware devices
5
The file system
• /etc Configuration files
• /home Home directories
• /lib Library files
• /mnt External file systems
• /proc Virtual directory for running processes
• Other directories as well
6
The file system
• Every user has a "home"– Normally in /home, but here we use /heim
• Superuser: root.
• Other file systems may be merged with the one on the local machine using mounting
• "Everything is a file":– /dev/fd0 floppydrive
/dev/hda1 first partition on first IDE hard disk/dev/ttyS0 first serial port
7
Users
• A user can only write to his/her home directory
• Root can do everything (make new users, maintain the system, read logs, clean up)
• Makes Linux safe (In other systems everyone is root!)
• A user belong to a group. (e.g "fys292")
• Every file has certain permissions (read, write and execute) for the user, the group and everybody else.
8
File systems
• Linux use the "ext2" file system. (Actually we use an extention of ext2 called ext3 here)
– Include permissions and ownership for files
– ext3 is a journaling file system
• Other file systems (f. ex. FAT, NTFS, XFS) have other properties, but Linux can read all of these, and write to almost all of them.
• Because of this, Linux can easily be integrated with other operating systems.
9
Rights and permissions (1)
ls -l fil*-rwxr-xr-x 1 espen kjeks 65 jan 23 23:06 fil1-rw-r--r-- 1 espen kjeks 65 jan 23 23:06 fil2-rw------- 1 espen kjeks 65 jan 23 23:06 fil3-rwxr--r-- 1 espen kjeks 65 jan 23 23:06 fil4drwxr-xr-x 4 espen kjeks 4096 des 26 15:31 fil5
drwxr-xr-x d = directoryr = read permissionw = write permissionx = execute permissionspecial|user|group|others
10
Rights and permissions (2)
-rwxr-xr-x 1 espen kjeks 65 jan 23 23:06 fil1– "espen" can read, write, execute.
– Users in the "kjeks" group can read and execute
– Others can also read and execute the file.
-rw-r--r-- 1 espen kjeks 65 jan 23 23:06 fil2-rw------- 1 espen kjeks 65 jan 23 23:06 fil3-rwxr--r-- 1 espen kjeks 65 jan 23 23:06 fil4drwxr-xr-x 4 espen kjeks 4096 des 26 15:31 fil5
– You need write permission to a directory to deletefiles in it.
11
Why permissions?
• More secure:– Can't delete files you're not supposed to...
– Can't view files you shouldn't
• Easy to group users together:– Easy file sharing between groups
– Only group can read/write files
• Every file has an owner
12
Changing permissions (1)
• Every new file gets a default set of permissions, most often: -rw-r--r--
• This file cannot be executed directly!
• Change so that owner can execute:chmod u+x filename
– "User: add execute permission"
– u = user, g = group, o = others, a = all
13
Changing permissions (2)
• To make a file executable and writeable (be careful...) by your group:chmod g+wx filename
• Restrict permissions with -chmod a-x filenamechmod go-r filename
• root can of course read the file anyway
• Permissions can also be set absolute -not just relative; chmod 600 filename
14
STDIN and STDOUT
• "What is input, and where does it go?"
• Usually, the keyboard is standard in, the monitor is standard out:– ls -l takes keyboard input, and views the file list on the
screen
– echo "Hello there" also takes keyboard input and views the result on the screen.
• Many commands use STDIN and STDOUT, but we can often "force" them to not use these
15
Redirection (1)
• Why don't we want ls -l to display its output on the monitor?
– Your friend wonders which .mp3 files you have. You have them all in a directory, and want to e-mail him a list of the files. There's always cut'n'paste, but...
– The system admnistrator wants to keep a list of what processes are running on the machine
• ls mymp3s > list-of-mp3s.txt• ps -aux > list-of-processes.txt
16
Redirection (2)
• Redirection to a device (here: a printer): ls mymp3s > /dev/lp0
• Redirect standard input:Assume there is a file "dirs" containing names of directories with files. We want ls to view the contents of all these:ls < dirsls < dirs > listoffiles.txt
17
Redirection (3)
• Using ">" creates/overwrites a file. Use ">>" to append to a file:ls newmp3s >> list-of-mp3s.txt
• There is also something called "Standard error". This is also usually the screen, but can be useful to "suppress" in scripts. Then we can redirect it to /dev/null, which is the Unix/Linux "Recycle bin":ls -l /crap >& /dev/nullls -l /crap >& error.msg
18
Pipes
• A "pipe" is used to direct the output of one command to act as input for another command.
• How many new mp3's do you have in "newmp3s"?ls newmp3s | wc
• To many files in the directory to get the overview?ls -l newmp3s | more
19
"Wild-characters"
• Used to denote "more than one character":– ? is a replacement for one (and only one character)– * is a replacement for any number of characters
• Useful with ls:– ls -l *.gif lists all files ending with ".gif"– ls -l /usr/bin/pi?? lists all files in /usr/bin starting
with "pi" and having four characters in total.
» "pine" and "pico" will match, but not "pinky"
20
Some useful commands (1)
• Change directory: cd– cd .. One directory up– cd /usr/local Go to /usr/local– cd Go "home"
• List files: ls– ls -l List with long format– ls -a/tmp List hidden files in
/tmp directory– ls -lt Sort by time
21
Some useful commands (2)
• Where am i? pwd– pwd Prints working directory
• Delete file: rm– rm myfile.html Removes the file– rm -rf ~/html Removes all files in
/home/user/html without prompting– rmdir myfiles Removes directory
22
Some useful commands (3)
• Make directory: mkdir– mkdir webpages Makes a directory
• Move/rename file: mv– mv oldname newname Renames file– mv file /newplace Moves file
• Print files: lpr– lpr -Pps2 file.txt Print text file to ps2– lpr -Pps4 file.ps Print PostScript file to ps4
23
Networking
• To communicate, we must have network protocols
• A protocol is a set of rules of how the communication should take place
• TCP/IP "Transmission Control Protocol/Internet Protocol" is the most common and best known.
• UDP, ICMP, ARP, SMTP, RIP, SLIP, PPP, POP
• TCP/IP is the language of Internet and Intranets
24
TCP/IP
• At the lowest level communication is just current running in wires
• A network interface card (NIC) produces these signals. A NIC has an unique address called "hardware address". Ex: 00:40:33:57:ED:9F
• We assign an IP address to a network card, for example 129.177.40.40
• We have human readable aliases for the IP numbers; 129.177.40.40 is goliat.ift.uib.no
25
Using TCP/IP
• File transfer: sftp
• Remote login: ssh
• Web: http
• News: nntp
• E-mail: pop, smtp
26
Logging on
luna~> ssh merkurespen@merkur's password:Last login: Wed Feb 13 22:56:01 2002merkur~>
– ssh has replaced telnet and rlogin, because ssh is more secure
– There are also replacements for ftp; scp and sftp
– Anonymous ftp; public servers
27
Our network
• Allows incoming ssh/sftp/scp from all nodes inside our institute.
• Outside connection has to go via portal1.ift.uib.no.
• Does not allow much else unless you are at our institute.
• ssh/sftp/scp use encryption
28
Starting programs (1)
• Some computers are fast
• Some computers have special software
• Some computers are familiar to you
• Some computers run services we want
• ...so we want to be able to log in, and run whatever we want!
29
Starting programs (2)
• Log in and start matlab:
bagdad-01> ssh merkur.ift.uib.noespen@merkur's password:Last login: Wed Feb 13 22:56:01 2002merkur~>matlab &
• ssh clients are also available for Windows, allowing you to log in from everywhere.
• This is why you should learn a console basede-mail program and text editor.
30
Some commands
• See who's logged in:– w– who– finger
• What is the machine running: uname -a• What jobs are running: ps -aux