Unix/Linux basics 0010 Operating systems lab Gergely Windisch uni-obuda.hu room 4.12.

Slides:



Advertisements
Similar presentations
Unix/Linux basics user management Operating systems lab Gergely Windisch room 4.12
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
5 Basic utilities When a user logs in to the Linux operating system the directory that they will start in is their home directory. Most users will have.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
1 CSE 303 Lecture 4 users/groups; permissions; intro to shell scripting read Linux Pocket Guide pp , 25-27, 61-65, , 176 slides created by.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Second Edition
Linux Linux File System.
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
UNIX Files and Security Software Tools. Slide 2 File Systems l What is a file system? A means of organizing information on the computer. A file system.
Introduction to Linux and Shell Scripting Jacob Chan.
Linux Commands LINUX COMMANDS.
Systems Programming Concepts
Unix/Linux basics 0011 Operating systems lab Gergely Windisch room 4.12
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Unix Basics Chapter 4.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Linux+ Guide to Linux Certification, Second Edition
Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
File Security and Permissions. File Permissions (1) u With respect to a particular file, Unix divides the set of all users on a system into three categories:
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
ICE UNIX TUTORIAL. File System Commands cd – change directory cd – change directory ls – list contents ls – list contents rm – remove/delete rm – remove/delete.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
BIF703 File Permissions. As you recall from our previous notes, that Unix/Linux recognizes everything as a file: Regular files to store data, programs,
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Linux Filesystem Management
Introduction to Unix – CS 21
By Jonathan Rinfret UNIX/LINUX By Jonathan Rinfret
Tutorial of Unix Command & shell scriptS 5027
File permissions Operating systems I800
Development Environment Basics
CS306 Lab Workout 2 Fall 2017.
Chapter 11 Command-Line Master Class
Prepared by: Eng. Maryam Adel Abdel-Hady
Linux file system "On a UNIX system, everything is a file;
CS314 – Section 5 Recitation 1
Shell Script Assignment 1.
BIF703 File Permissions.
Tutorial of Unix Command & shell scriptS 5027
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
LING 408/508: Computational Techniques for Linguists
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Lab 7 Shell Script Reference:
Linux Commands LINUX COMMANDS.
Presentation transcript:

Unix/Linux basics 0010 Operating systems lab Gergely Windisch uni-obuda.hu room 4.12

unix filesystems (1) Unix supports many filesystems Filesystems are not accessed via drive id – mounted into the / mount point Virtual file system layer makes it unique Akik az Advanced Programming in the Unix Environment (Richard Stevens) könyvből vették

unix filesystems (2) - VFS Akik az Advanced Programming in the Unix Environment (Richard Stevens) könyvből vették Source:

unix filesystems (3) - drives Akik az Advanced Programming in the Unix Environment (Richard Stevens) könyvből vették

unix file systems (4)

Inode inode, cornerstone of all file storage – contains information about the file inode identifies the data itself (inode table) – link to the actual data – access times – owners, permissions etc. Name is not part of the inode – name is just a record in the directory file ls –i: print inode numbers speaking_unix:_it’s_all_about_the_inode.php

inode (2) - demonstration mkdir fruits, cd fruits touch apple, ls -i touch orange, ls -i the inode numbers are different – numbers are in a stricly increasing manner ls -ali :. and.. are visible – what can you see concerning. and..? – cd.. && ls –ali : anything interesting now? the indices of directories are also increasing, but starts from a different number

i-nodes Akik az Operation System Concepts (Silberschatz,Galvin) könyvből vették

Links Hard link: – Creating a „true” second file (same inode) – also a record in the inode table – ln target new_link – Size, permission are in the inode table. The name is stored in the directory --> creating new links (names) to the same inode – Deleting one does not affect the others (there is no original) – ls -l shows how many links point to that file

Problem with hard link: only on the same filesystem cp: creates new inode mv: same inode – only in the same file system touch mule ls -il cp mule horse mv mule hamster

Symbolic (soft) link – Make the files and directories available with a different name - eg: compatibility issues, simpler access – ln -s target new_syslink – Symbolic link points to a file or directory name – Deleting the original file renders the link useless

Exercise Create a file, write your name into it. Create a hard link that points to it. How many links point to it? Create a soft link that points to it. How many links point to it now? Modify the original file. What do you see in the other files? Modify the hardlink. What do you see now? Modify the soft link. What do you see now?

Security measures in linux Login using username and password – cannot access anything without it Filesystem protection: files and directories have permissions – File access permissions: r - read w - write x – execute (enter directories) – The system stores permissions for the owner, owner group and everyone else

Permissions (1) chmod – set permissions Owner/Owner group/Everyone else read: 4 (list directories) write: 2 (modify contents – create, delete) execute: 1 (enter directory) – if you cannot enter, you cannot list either

15 Permissions (2) Setting permission: chmod number file For example: 754 means the following OwnerOwner groupOthers rwxrwxrwx

16 Permissions (3) Changing owner of objects: chown chown owner file (or chown owner.group file) Changing owner group: chgrp newgroup file pl. chgrp users letter

17 Access permissions ls –l - rw-rw-rw- 1 demo guest Aug 23 20:23 file1 d rwxrw-rwx 1 demo... l rwxrwxrwx... Meaning: (first column) - regular file d directory p named pipe l symbolic link c character device b block device rwxr--rw- ownergroupothers permission -deny wwrite rread xexecute

18 Modifying access permissions I. chmod [R] files: (read=4, write=2, execute=1 ) pl.owner: read, write, execute (4+2+1=7) group members: read, execute (4+1=5) eveyone else: read (4) the octal code is: 754 chmod 754 file1 ls -l file1 -rwxr-xr-- 1 demo guest 18 Aug 23 20:42 file1

19 Modifying access permissions II. Other way: 'u' (user : owner)'+' : grant right (add) 'g' (group )'-' : deny right (substract) 'o' (others)'=‘ : make permissions exactly like that 'a' (all) chmod a+x file1 ( executable for everyone (a+x)) ls -l file1 -r-xr-xr-x 1 demo guest... (only the executable bit) chmod u=rw file1 ls -l file1 -rw-r-xr-x 1 demo... (owner will have read and write permissions, regardless of previous state).

20 chmod command I. echo „first example” >example chmod u+x example orchmod 744 example Execute rights for the user. chmod go-rw example Read and write permissions to the group and others (nothing else changes). mkdir texts chmod -R a+X texts Recursively giving executable permissions to the content of the texts directory X gives execution rights only to executable types chmod o= example Denying all the rights from the others (nothing else changes).

21 A chmod command II. chmod a=r example or chmod 444 example Read permissions for everyone, nothing else. chmod 750 example Owner can read, write, execute, group can read and execute, others cannot do anything chmod u=rwx example chmod g=rx example chmod o= example A szimbolikus jogok alkalmazásával

22 Pop quiz chmod 123 file chmod 777 file chmod 533 file chmod 217 file chmod 182 file chmod a=x file

Permissions - special flags (1) sticky bit: chmod +t filename – Obsolete for executables (keep in memory) – directories: only the owner of the files can delete them – useful for /tmp, shared ftp directories suid (set user id): chmod +s filename – program is executed with the owners permissions – for example copy to directories writeable only to root – could be considered a security threat sgid: – like suid, but with the group

SUID, SGID, Sticky is the first number when there are 4 digits sticky: 1 sgid: 2 suid: 4 pl: chmod 4777 file – 4: suid – 777: regular permissions Permissions - special flags (2)

Exercise Create a directory. Create 3 files in that directory. Set different permissions for each file (for example: rw-rw- rw, r-x,r-x,---,rwxr---r---

Exercise 2 Create a directory called public Set the permissions for the directory to Let the user hallgato do everything with it. Let the users of the group hallgato read the contents (ie. open the files inside) Anyone not part of the hallgato group should be denied access altogether The owner of the file should be the only one that has permissions to delete the files.

Let's edit text - vi(m)‏ user friendly, but chooses his friends carefully important, because it is there on all unixes vi is the original, we'll use vim (VI iMproved)‏ vim filename vi: vim:

Let's edit text - vi(m)‏ 2 modes: insert, command - esc, i (insert)‏ quit: esc, :q, :wq, :q! save: :w delete the current line: dd (6dd: delete 6 lines)‏ copy the current line: yy (6yy: copy 6 lines)‏ paste the content of the buffer: p

Let's edit text - nano nano filename menu bar: ctrl + key ctrl+x: quit ctrl+o: save ctrl+w: search

Let's edit text - mcedit midnight commander editor mcedit filename F2: save, F3 select install if not installed - on opensolaris – add new software somewhere. – pkg list -s | grep packagename – pkg search -l packagename – pkg install -v packagename

Let's edit text - joe joe filename quit: ctrl + k, ctrl + x

Let's edit text - emacs I don't know emacs, but it is popular Anyone?

Shell scripting Multiple commands in one file #!/bin/bash - first line - bash is the "compiler" chmod a+x filename./filename shell scripts are really powerful and useful. There are many small commands which we can put together in a shell script to create one big application (that is the unix way)‏

Our first shell script #!/bin/bash # That's how the comments work echo "Shell scripts rule" exit 0 exit 0 is not necessary, but good practice – tell the shell that all is well – remember the && and ||: that's how it works

Using variables number=43 othervariable="oneword" other2="could be multiple words" – other2=that will result in severe error messages no spaces around the = !!!! (Really important)‏ don't forget to put ""-s around strings accessing variables: $ echo $other2

Exercise 1 Let's create a shell script where we have two variables. Add values to both and then print them both on the screen

Exercise 1 solution #!/bin/bash first="I don't know" second="me neither" echo $first $second exit 0

Exercise 2 Let's create a shell script where we have two variables. They should have numerical values, and add them together. What happens?

Exercise 2 solution #!/bin/bash first=40 second=50 echo exit 0

Apostrophes - spaces mess things up ' ' : treat everything that's inside literally – echo '$first' – will print $first " " : use the special characters inside the string – echo "$first" – will print the value of $first ` ` : run command (alt gr+7 - hungarian keys)‏ – echo `date` – runs date and then substitutes the result

Handing user input - parameters $# : number of command line parameters $1..9: value of the nth parameter $0 : name of the current shell script $* : all the parameters in one big script

math in bash expr number=`expr 3 + 4`

Exercise 2.5 Make a shell script that sums the numbers it gets as parameters

Exercise 3 Write a shell script which takes a parameter from the user, and lists the contents of the directory specified in the parameter. The result should go in a file called the actual date. The format of the filename should be year-month- day_hour-minute.

Hint - Exercise 3 get the date formatting using man date ambigous redirect means that the shell thinks that there are more than one files after >

Solution to Exercise 3 #!/bin/bash ls -l $1 > `date +%F_%H-%M`.txt or ls -l $1 > "`date`"

Exercise 4 Create a shell script which takes an input parameter, and creates a symbolic link with the given name that points to /bin/cat

Solution to Exercise 4 #!/bin/bash ln -s /bin/cat $1

Exercise 5 Create a shell script which takes an input parameter, and sets the permissions of the file that was given so that the owner can have all rights, group should have read permissions, and no rights for the others

Exercise 5 #!/bin/bash chmod 740 $1

Evaluation eval command eval can run a command that sits in variable commandvariable=”ls -l /home | sort” eval $commandvariable

Exercise 6 Create a shell script which takes input parameters and runs the command that was given (for example: runme ls -l /home/hallgato)

Bad solution to Exercise 6 #!/bin/bash `$*` What happens here?

Solution to Exercise 6 #!/bin/bash eval $*

Mathematics expr command calculator with 5 commands |,&: or, and0 (0 when true, 1 when false)‏ =,> +,-,*,/,% (remainder)‏ n1=20 n2=10 sum=`expr $n1 + $n2`

Compression tar (tape archiever) tar -cvzf nameoffile.tar.gz * – pack and compress everything in cwd tar -xvzf nameoffile.tar.gz – unpack the contents of nameoffile.tar.gz Switches – man tar – x: eXtract, c: create, v: verbose, z: gzip, f: filename

Exercise 6.5 Use tar to compress all your shell scripts into one file

Solution to Exercise 6.5 tar -cvzf myShellScripts.tar.gz *

Exercise 7 Create a shell script which takes two numbers as input parameters and add them together (those of you who already know ifs should write a full-featured calculator)

Solution to Exercise 7 #!/bin/bash sum=`expr $1 + $2` echo "The sum of $1 and $2 is $sum"

Exercise 8 Write a shell script that adds the current date (date command) and the current uptime (uptime command) to the ~/uplog file. There should be a separator after these two data, so that the next run can be identified easily.

Solution to Exercise 8 #!/bin/bash newfile="~/uptime" date >> $newfile uptime >>$newfile echo " " >>$newfile echo " " >>$newfile

Exercise 9 Write a shell script that takes two input parameters from the user, and then creates a symbolic link pointing to the file denoted by the first parameter with the name provided as the second parameter.

Solution to Exercise 9 #!/bin/bash ln -s $1 $2

Exercise 10 Write a shell script that prints the contents of the PATH (the one which holds the names of the directories where the shell would look for an executable) variable to a file. The filename is provided in the first input parameter.

Solution to Exercise 10 #!/bin/bash echo "Contents of \$PATH: $PATH" > $1

Exercise 11 Write a shell script that takes the name of a directory as an input parameter and adds that directory to the PATH variable. Be careful not to overwrite the original content, just add it (and use the standard separator of that variable). Advanced versions (require for and if) – check if the directory exists – if the user provides more than one dir, add them as well

Solution to Exercise 11 #!/bin/bash PATH="$PATH:$1"

Upload your precious work If you want, you can send your work to me. If the solutions are correct (or interesting), it could count in your final grades. Send it using the commands: – sudo dhclient eth2 (password: nik119) – scp name_of_tar (password: hallgato) Or via