SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Unix Basics



    Prepared by
         Dima Gomaa
What Is an Operating System?

•   Interface between Users and the Hardware
•   Take care of Storage Management
•   Take care of I/O device management
History of the UNIX Operating System
 1969        AT&T Bell Labs UNICS system -designed by Ken
             Thompson & Dennis Ritchie

 1970        UNICS finally became UNIX
 1973        UNIX rewritten in C, making it portable to different hardware

 Mid 1970s   University of California at Berkeley (BSD) contributed many
             important features like vi, C shell etc.

 1982        AT & T came back and started commercial production-
             Editions ->Systems

 Late 1980s AT & T released SVR4 unification of SV3.2,BSD,SunOs &
            XENIX

 1991        Linux from Linus Torvalds

 1990s       POSIX Standard, MIT introduced X-Windows

                                                                             3
UNIX Architecture – Kernel & Shell




User   Shell     Kernel    Hardware




                                      4
More Features of UNIX


•   Hierarchical file system
•   Multi tasking
•   Multi user
•   Pattern matching (wildcard characters)
•   Programming facility
•   Documentation




                                             5
Command Line Format

Syntax:

 $ command [-options] [arguments]

1. Separation

2. Order

3. Multiple options

4. Multiple arguments


                                    6
Basic Commands(1)
   ls             list files and directories
   ls -a          list all files and directories
   mkdir          make a directory
   cd directory   change to named directory
   cd             change to home-directory
   cd ~           change to home-directory
   cd ..          change to parent directory
   pwd            display current dir path
   useradd        add new user in the system
   usermod        modify user
   userdel        delete user
   groupadd       add new group in the system
Basic Commands(2)

   cp file1 file2         copy file1 and call it file2
   mv file1 file2         move or rename file1 to file2
   rm file                remove a file
   rmdir directory        remove a directory
   cat file               display a file
   more file              display a file a page at a time
   who                    list users currently logged in
   lpr -Pprinter psfile   print postscript file to named printer
   *                      match any number of characters
   ?                      match one character
   man                    command read the online manual page for a
                           command
Basic Commands(3)
   command > file            redirect standard output to a file
   command >> file           append standard output to a file
   command < file            redirect standard input from a file
   grep 'keyword' file       search a file for keywords
       % grep science science.txt
   wc file                   count number of lines/words/characters in file
       % wc -w science.txt
   sort                      sort data (numerically or alphabetically)
       Ex:
       to sort the list of object, type
       % sort < biglist
       and the sorted list will be output to the screen.
The File System Hierarchy


                                 /




       usr          etc   home       dev    var   tmp




bin          sbin         dsk        rdsk   adm     sadm


  ls         who
                                                           10
File Path name
A sequence of file names, separated by slashes (/), that
describes the path, the system must follow to locate a
file in the file system


Absolute pathname (start from the /-directory):
       Eg: /export/home/user1/file1
Relative pathname (start from the current directory)
       ./test1 (. = current directory)
       ../team03/.profile (.. = parent directory)
                                                           11
File Characteristics

 $ ls -l
 -rw-r--r-- 1 user3 class 37   Jul 24 11:06 f1
 -rwxr-xr-x 1 user3 class 52   Jul 24 11:08 f2
 drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo



File        Links           Group                      Name
Type                                       Timestamp
                    Owner           Size
  Permissions




                                                              12
Who can access a File?
The UNIX system incorporates a three-tier structure to define who
 has access to each file and directory:

   user The owner of the file
   group A group that may have access to the file
   other Everyone else
• The ls -l command displays the owner and group who has
  access to the file.
  $ ls -l
  -rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1
  -rwxr-xr-x 1 user3 class 37 Jul 24 11:08 f2
  drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo
                      | |
                   owner group
                                                                13
File system security (access rights)




        -rwxrwxrwx   a file that everyone can read, write and execute
                     (and delete).


        -rw-------   a file that only the owner can read and write - no-
                     one else can read or write and no-one has
                     execution rights (e.g. your mailbox file).
Unix File Permissions

   File type, owner, group, others
drwx------      2   jjoshi   isfac 512       Aug 20 2003 risk management
lrwxrwxrwx      1   jjoshi   isfac   15      Apr 7 09:11 risk_m->risk management
-rw-r--r--      1   jjoshi   isfac 1754      Mar 8 18:11 words05.ps
-r-sr-xr-x      1   root     bin   9176      Apr 6 2002 /usr/bin/rs
-r-sr-sr-x      1   root     sys   2196      Apr 6 2002 /usr/bin/passwd

   File type: regular -, directory d, symlink l, device b/c, socket s, fifo f/p
   Permission: r, w, x, s or S (set.id), t (sticky)
   chmod [options] file        change access rights for named file

      For example, to remove read write and execute permissions on the file
         biglist for the group and others, type

      % chmod go-rwx biglist

      This will leave the other permissions unaffected.

      To give read and write permissions on the file biglist to all,


      % chmod a+rw biglist
Default Permissions

The default protections for newly created files and directories
are:


       File           -rw-r—r--     644
       Directory      drwxr-xr-x    755


These default settings may be modified by changing the umask
value.

                                                                  17
umask - Permission Mask

Umask specifies what permission bits will be set on a new
file or directory when created.


New Directory:        777 – 022     755      rwxr-xr-x
New File      :       666 – 022     644     rw-r—r—


The default value of umask is set in /etc/profile. This can be
changed for all the users or a particular user

                                                                 18
chown - Change File Ownership

Syntax:
chown owner [:group] filename ...
                                                  Changes owner of a
                                                  file(s) and, optionally, the
Example:                                          group ID
 $ id
 uid=101 (user1), gid=101 (group1)
 $ cp f1 /tmp/user2/f1
 $ ls -l /tmp/user2/f1
 -rw-r----- 1 user1 group1 3967 Jan 24 13:13 f1
 $ chown user2 /tmp/user2/f1
 $ ls -l /tmp/user2/f1
 -rw-r----- 1 user2 class 3967 Jan 24 13:13 f1

Only the owner of a file (or root) can change the ownership of the file.
                                                                                 19
The chgrp Command
Syntax:
 chgrp newgroup filename ...

Example:
 $ id
 uid=303 (user3), gid=300 (class)
 $ ls -l f3
 -rw-r----- 1 user3 class 3967 Jan 24 13:13 f3
 $ chgrp class2 f3
 $ ls -l f3
 -rw-r----- 1 user3 class2 3967 Jan 24 13:13 f3
 $ chown user2 f3
 $ ls -l f3
 -rw-r----- 1 user2 class2 3967 Jan 24 13:13 f3   20
su - Switch User Id
Syntax:
 su [user_name]
               Change your effective user ID and group ID

Example:
 $ ls -l f1
 -rwxr-x--- 1 user1 group1 3967 Jan 24 23:13 class_setup
 $ id
 uid=303 (user1), gid=300 (group1)

 $ su – user2
 Password:
 $ id
 uid=400 (user2), gid=300 (group1)

                                                            21
Special File Permissions – setuid, setgid,
sticky bit
   setuid – changes the effective user id of the user to the owner of
    the program
     chmod u+s f1               or
     – chmod 4744 f1

   setgid – changes the effective group id of the user to the group
    of the program
     chmod g+s f1               or
     chmod 2744 f1



   sticky bit – ensures the deletion of files by only file owner in a
    public writable directory
     chmod +t f1                or
     Chmod 1744 f1

                                                                         22
What Is vi?

•   A screen-oriented text editor
•   Included with most UNIX system distributions
•   Command driven
•   Categories of commands include
     – General administration
     – Cursor movement
     – Insert text
     – Delete text
     – Paste text
     – Modify text




                                                   23
Starting and Ending a vi
                     Session
vi [filename] Start a vi edit session of file
Example:
$ vi testfile
- If the file doesn’t exist, it will be created
- Otherwise vi will open the existing file


All modifications are made to the copy of the file brought into
memory.
:wq or :x or <shift-zz>                write and quit
:w                                     write
:q                                     quit
:q!                                    Quit without saving
                                                                  24
Cursor Control Commands
                         1G
                        <ctrl-b>
                          H
                          k
                       <up-arrow>


         0                          $
      b,B                           w,W
        h                           l
<left-arrow>                        <right-arrow>




                     <down-arrow>
                          j
                          L
                       <ctrl-f>
                         G
                                                    25
Input Mode: i, a, O, o


i will insert character at the present cursor position
I will insert character at the beginning of the line
a will append character at the present cursor position
A will append character at the end of the line

o will insert a blank line below
O will insert a blank line above




                                                         26
Deleting Text: x, dw, dd, dG

x      deletes the current character
dw     deletes the current word
dd     deletes the current line
dG     delete all lines to end of file, including current line.
With any of these you can prefix a number
Example: 3dd will delete 3 lines
d$     to delete to the end of the line
d0     to delete to the start of the line


                                                                  27
Copying, moving and
               changing Text
yy   copy the line
yw   copy the word     p will paste the yanked lines below
dw   cut the word      P will paste the yanked lines above
dd   cut the line
r    will overwrite the current character
R    will replace all text on the right of the cursor position
cw   will replace only the current word


                                                                 28
Searching for Text: /, n, N

/director will locate for the first occurrence of the
pattern ‘director’


n to locate the next occurrence
N to locate the previous occurence




                                                        29
Monitoring Process


The ps command dislays process status information

$ ps -f

UID       PID   PPID   ...   TTY    ...   COMMAND
john      202   1      ...   tty0   ...   -ksh
john      204   202    ...   tty0   ...   ksh
john      210   204    ...   yyu0   ...   ls -R /
john      212   204    ...   tty0   ...   ps -f


                                                    30
Shell Scripting

   Shell scripting skills have many applications, including:
   Ability to automate tasks, such as
     Backups

     Administration tasks

     Periodic operations on a database via cron

     Any repetitive operations on files

   Increase your general knowledge of UNIX
     Use of environment

     Use of UNIX utilities

     Use of features such as pipes and I/O redirection
Examples of Shell Scripting
   Store the following in a file named simple.sh and execute it
      #!/bin/sh
      # Show some useful info at the start of the day
      date
      echo Good morning $USER
      cal
      last | head -6

   Shows current date, calendar, and a six of previous logins
   Notice that the commands themselves are not displayed, only
    the results

Weitere ähnliche Inhalte

Was ist angesagt?

A beginners introduction to unix
A beginners introduction to unixA beginners introduction to unix
A beginners introduction to unixzafarali1981
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Wave Digitech
 
Unix files
Unix filesUnix files
Unix filesSunil Rm
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating Systemsubhsikha
 
Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & CommandsMohit Belwal
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumarymentorsnet
 
Unix
UnixUnix
UnixErm78
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)anandvaidya
 
Unix operating system architecture with file structure
Unix operating system architecture with file structure Unix operating system architecture with file structure
Unix operating system architecture with file structure amol_chavan
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1Lilesh Pathe
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to LinuxTusharadri Sarkar
 
Linux Administration
Linux AdministrationLinux Administration
Linux AdministrationHarish1983
 
Unix files
Unix filesUnix files
Unix filesSunil Rm
 
Linux presentation
Linux presentationLinux presentation
Linux presentationNikhil Jain
 

Was ist angesagt? (20)

A beginners introduction to unix
A beginners introduction to unixA beginners introduction to unix
A beginners introduction to unix
 
Linux: Basics OF Linux
Linux: Basics OF LinuxLinux: Basics OF Linux
Linux: Basics OF Linux
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Unix files
Unix filesUnix files
Unix files
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Unix OS & Commands
Unix OS & CommandsUnix OS & Commands
Unix OS & Commands
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumary
 
Unix
UnixUnix
Unix
 
Linux lecture6
Linux lecture6Linux lecture6
Linux lecture6
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
 
Unix operating system architecture with file structure
Unix operating system architecture with file structure Unix operating system architecture with file structure
Unix operating system architecture with file structure
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1
 
Linux commands
Linux commandsLinux commands
Linux commands
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to Linux
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Unix files
Unix filesUnix files
Unix files
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Linux
Linux Linux
Linux
 
Basics of Linux
Basics of LinuxBasics of Linux
Basics of Linux
 

Andere mochten auch

The Data Journalism Handbook (poster)
The Data Journalism Handbook (poster)The Data Journalism Handbook (poster)
The Data Journalism Handbook (poster)Liliana Bounegru
 
DMI Workshop: Data visualization. Analytical clouding.
DMI Workshop: Data visualization. Analytical clouding.DMI Workshop: Data visualization. Analytical clouding.
DMI Workshop: Data visualization. Analytical clouding.Digital Methods Initiative
 
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...Liliana Bounegru
 
Solved problem binomial probability distribution
Solved problem binomial probability distributionSolved problem binomial probability distribution
Solved problem binomial probability distributionEdgar Mata
 
California love tupac
California love   tupacCalifornia love   tupac
California love tupacPedsldn
 
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...Siete herramientas basicas y siete nuevas herrramientas de administracion de ...
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...Anna Escamilla
 
Ppt for solar fencing
Ppt for solar fencingPpt for solar fencing
Ppt for solar fencingnarayanamsai
 
Ra solar power generators presentation
Ra solar power generators presentationRa solar power generators presentation
Ra solar power generators presentationKATU ISAAC
 

Andere mochten auch (10)

my resume
my resumemy resume
my resume
 
DMI Workshop: Crawling and Scraping
DMI Workshop: Crawling and Scraping DMI Workshop: Crawling and Scraping
DMI Workshop: Crawling and Scraping
 
The Data Journalism Handbook (poster)
The Data Journalism Handbook (poster)The Data Journalism Handbook (poster)
The Data Journalism Handbook (poster)
 
DMI Workshop: Data visualization. Analytical clouding.
DMI Workshop: Data visualization. Analytical clouding.DMI Workshop: Data visualization. Analytical clouding.
DMI Workshop: Data visualization. Analytical clouding.
 
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...
Data Infrastructure Literacy: Reshaping Practices of Measurement, Monitoring ...
 
Solved problem binomial probability distribution
Solved problem binomial probability distributionSolved problem binomial probability distribution
Solved problem binomial probability distribution
 
California love tupac
California love   tupacCalifornia love   tupac
California love tupac
 
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...Siete herramientas basicas y siete nuevas herrramientas de administracion de ...
Siete herramientas basicas y siete nuevas herrramientas de administracion de ...
 
Ppt for solar fencing
Ppt for solar fencingPpt for solar fencing
Ppt for solar fencing
 
Ra solar power generators presentation
Ra solar power generators presentationRa solar power generators presentation
Ra solar power generators presentation
 

Ähnlich wie Unix fundamentals

Ähnlich wie Unix fundamentals (20)

Linux ppt
Linux pptLinux ppt
Linux ppt
 
Basic Linux
Basic LinuxBasic Linux
Basic Linux
 
Lession1 Linux Preview
Lession1 Linux PreviewLession1 Linux Preview
Lession1 Linux Preview
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Linux Shell Basics
Linux Shell BasicsLinux Shell Basics
Linux Shell Basics
 
Unix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptxUnix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptx
 
An Introduction to Linux
An Introduction to LinuxAn Introduction to Linux
An Introduction to Linux
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Unix Basics Commands
Unix Basics CommandsUnix Basics Commands
Unix Basics Commands
 
Rhel1
Rhel1Rhel1
Rhel1
 
basic-unix.pdf
basic-unix.pdfbasic-unix.pdf
basic-unix.pdf
 
Bootcamp linux commands
Bootcamp linux commandsBootcamp linux commands
Bootcamp linux commands
 
Linux file system nevigation
Linux file system nevigationLinux file system nevigation
Linux file system nevigation
 
Raspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OSRaspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OS
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
UNIX.pptx
UNIX.pptxUNIX.pptx
UNIX.pptx
 
linux-lecture4.ppt
linux-lecture4.pptlinux-lecture4.ppt
linux-lecture4.ppt
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
04-1-Linux.ppt
04-1-Linux.ppt04-1-Linux.ppt
04-1-Linux.ppt
 

Kürzlich hochgeladen

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Kürzlich hochgeladen (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

Unix fundamentals

  • 1. Unix Basics Prepared by Dima Gomaa
  • 2. What Is an Operating System? • Interface between Users and the Hardware • Take care of Storage Management • Take care of I/O device management
  • 3. History of the UNIX Operating System 1969 AT&T Bell Labs UNICS system -designed by Ken Thompson & Dennis Ritchie 1970 UNICS finally became UNIX 1973 UNIX rewritten in C, making it portable to different hardware Mid 1970s University of California at Berkeley (BSD) contributed many important features like vi, C shell etc. 1982 AT & T came back and started commercial production- Editions ->Systems Late 1980s AT & T released SVR4 unification of SV3.2,BSD,SunOs & XENIX 1991 Linux from Linus Torvalds 1990s POSIX Standard, MIT introduced X-Windows 3
  • 4. UNIX Architecture – Kernel & Shell User Shell Kernel Hardware 4
  • 5. More Features of UNIX • Hierarchical file system • Multi tasking • Multi user • Pattern matching (wildcard characters) • Programming facility • Documentation 5
  • 6. Command Line Format Syntax: $ command [-options] [arguments] 1. Separation 2. Order 3. Multiple options 4. Multiple arguments 6
  • 7. Basic Commands(1)  ls list files and directories  ls -a list all files and directories  mkdir make a directory  cd directory change to named directory  cd change to home-directory  cd ~ change to home-directory  cd .. change to parent directory  pwd display current dir path  useradd add new user in the system  usermod modify user  userdel delete user  groupadd add new group in the system
  • 8. Basic Commands(2)  cp file1 file2 copy file1 and call it file2  mv file1 file2 move or rename file1 to file2  rm file remove a file  rmdir directory remove a directory  cat file display a file  more file display a file a page at a time  who list users currently logged in  lpr -Pprinter psfile print postscript file to named printer  * match any number of characters  ? match one character  man command read the online manual page for a command
  • 9. Basic Commands(3)  command > file redirect standard output to a file  command >> file append standard output to a file  command < file redirect standard input from a file  grep 'keyword' file search a file for keywords % grep science science.txt  wc file count number of lines/words/characters in file % wc -w science.txt  sort sort data (numerically or alphabetically) Ex: to sort the list of object, type % sort < biglist and the sorted list will be output to the screen.
  • 10. The File System Hierarchy / usr etc home dev var tmp bin sbin dsk rdsk adm sadm ls who 10
  • 11. File Path name A sequence of file names, separated by slashes (/), that describes the path, the system must follow to locate a file in the file system Absolute pathname (start from the /-directory): Eg: /export/home/user1/file1 Relative pathname (start from the current directory) ./test1 (. = current directory) ../team03/.profile (.. = parent directory) 11
  • 12. File Characteristics $ ls -l -rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1 -rwxr-xr-x 1 user3 class 52 Jul 24 11:08 f2 drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo File Links Group Name Type Timestamp Owner Size Permissions 12
  • 13. Who can access a File? The UNIX system incorporates a three-tier structure to define who has access to each file and directory: user The owner of the file group A group that may have access to the file other Everyone else • The ls -l command displays the owner and group who has access to the file. $ ls -l -rw-r--r-- 1 user3 class 37 Jul 24 11:06 f1 -rwxr-xr-x 1 user3 class 37 Jul 24 11:08 f2 drwxr-xr-x 2 user3 class 1024 Jul 24 12:03 memo | | owner group 13
  • 14. File system security (access rights) -rwxrwxrwx a file that everyone can read, write and execute (and delete). -rw------- a file that only the owner can read and write - no- one else can read or write and no-one has execution rights (e.g. your mailbox file).
  • 15. Unix File Permissions  File type, owner, group, others drwx------ 2 jjoshi isfac 512 Aug 20 2003 risk management lrwxrwxrwx 1 jjoshi isfac 15 Apr 7 09:11 risk_m->risk management -rw-r--r-- 1 jjoshi isfac 1754 Mar 8 18:11 words05.ps -r-sr-xr-x 1 root bin 9176 Apr 6 2002 /usr/bin/rs -r-sr-sr-x 1 root sys 2196 Apr 6 2002 /usr/bin/passwd  File type: regular -, directory d, symlink l, device b/c, socket s, fifo f/p  Permission: r, w, x, s or S (set.id), t (sticky)
  • 16. chmod [options] file change access rights for named file For example, to remove read write and execute permissions on the file biglist for the group and others, type % chmod go-rwx biglist This will leave the other permissions unaffected. To give read and write permissions on the file biglist to all, % chmod a+rw biglist
  • 17. Default Permissions The default protections for newly created files and directories are: File -rw-r—r-- 644 Directory drwxr-xr-x 755 These default settings may be modified by changing the umask value. 17
  • 18. umask - Permission Mask Umask specifies what permission bits will be set on a new file or directory when created. New Directory: 777 – 022 755  rwxr-xr-x New File : 666 – 022 644 rw-r—r— The default value of umask is set in /etc/profile. This can be changed for all the users or a particular user 18
  • 19. chown - Change File Ownership Syntax: chown owner [:group] filename ... Changes owner of a file(s) and, optionally, the Example: group ID $ id uid=101 (user1), gid=101 (group1) $ cp f1 /tmp/user2/f1 $ ls -l /tmp/user2/f1 -rw-r----- 1 user1 group1 3967 Jan 24 13:13 f1 $ chown user2 /tmp/user2/f1 $ ls -l /tmp/user2/f1 -rw-r----- 1 user2 class 3967 Jan 24 13:13 f1 Only the owner of a file (or root) can change the ownership of the file. 19
  • 20. The chgrp Command Syntax: chgrp newgroup filename ... Example: $ id uid=303 (user3), gid=300 (class) $ ls -l f3 -rw-r----- 1 user3 class 3967 Jan 24 13:13 f3 $ chgrp class2 f3 $ ls -l f3 -rw-r----- 1 user3 class2 3967 Jan 24 13:13 f3 $ chown user2 f3 $ ls -l f3 -rw-r----- 1 user2 class2 3967 Jan 24 13:13 f3 20
  • 21. su - Switch User Id Syntax: su [user_name] Change your effective user ID and group ID Example: $ ls -l f1 -rwxr-x--- 1 user1 group1 3967 Jan 24 23:13 class_setup $ id uid=303 (user1), gid=300 (group1) $ su – user2 Password: $ id uid=400 (user2), gid=300 (group1) 21
  • 22. Special File Permissions – setuid, setgid, sticky bit  setuid – changes the effective user id of the user to the owner of the program  chmod u+s f1 or – chmod 4744 f1  setgid – changes the effective group id of the user to the group of the program  chmod g+s f1 or  chmod 2744 f1  sticky bit – ensures the deletion of files by only file owner in a public writable directory  chmod +t f1 or  Chmod 1744 f1 22
  • 23. What Is vi? • A screen-oriented text editor • Included with most UNIX system distributions • Command driven • Categories of commands include – General administration – Cursor movement – Insert text – Delete text – Paste text – Modify text 23
  • 24. Starting and Ending a vi Session vi [filename] Start a vi edit session of file Example: $ vi testfile - If the file doesn’t exist, it will be created - Otherwise vi will open the existing file All modifications are made to the copy of the file brought into memory. :wq or :x or <shift-zz> write and quit :w write :q quit :q! Quit without saving 24
  • 25. Cursor Control Commands 1G <ctrl-b> H k <up-arrow> 0 $ b,B w,W h l <left-arrow> <right-arrow> <down-arrow> j L <ctrl-f> G 25
  • 26. Input Mode: i, a, O, o i will insert character at the present cursor position I will insert character at the beginning of the line a will append character at the present cursor position A will append character at the end of the line o will insert a blank line below O will insert a blank line above 26
  • 27. Deleting Text: x, dw, dd, dG x deletes the current character dw deletes the current word dd deletes the current line dG delete all lines to end of file, including current line. With any of these you can prefix a number Example: 3dd will delete 3 lines d$ to delete to the end of the line d0 to delete to the start of the line 27
  • 28. Copying, moving and changing Text yy copy the line yw copy the word p will paste the yanked lines below dw cut the word P will paste the yanked lines above dd cut the line r will overwrite the current character R will replace all text on the right of the cursor position cw will replace only the current word 28
  • 29. Searching for Text: /, n, N /director will locate for the first occurrence of the pattern ‘director’ n to locate the next occurrence N to locate the previous occurence 29
  • 30. Monitoring Process The ps command dislays process status information $ ps -f UID PID PPID ... TTY ... COMMAND john 202 1 ... tty0 ... -ksh john 204 202 ... tty0 ... ksh john 210 204 ... yyu0 ... ls -R / john 212 204 ... tty0 ... ps -f 30
  • 31. Shell Scripting  Shell scripting skills have many applications, including:  Ability to automate tasks, such as  Backups  Administration tasks  Periodic operations on a database via cron  Any repetitive operations on files  Increase your general knowledge of UNIX  Use of environment  Use of UNIX utilities  Use of features such as pipes and I/O redirection
  • 32. Examples of Shell Scripting  Store the following in a file named simple.sh and execute it #!/bin/sh # Show some useful info at the start of the day date echo Good morning $USER cal last | head -6  Shows current date, calendar, and a six of previous logins  Notice that the commands themselves are not displayed, only the results

Hinweis der Redaktion

  1. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  2. Shell is a Command Intrepreter www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  3. Hierarchical File System Information is stored on the disk in containers known as files. Every file is assigned a name, and user accesses a file by referencing its name. Files normally contain data, text, programs, and so on. In the UNIX system, a directory can be used to store files or other directories. Multi-tasking In the Unix system several tasks can be performed at the same time. From a single terminal, a single user can execute several programs that all seem to be running simultaneously. Programming facility The UNIX shell is also a programming language; it was designed for a programmer, not casual end user. It has all the necessary ingredients like control structures, loops and variables that establish it as a powerful programming language on its own right. These features are used to design shell scripts- programs that also include UNIX commands in their syntax. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  4. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  5. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  6. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  7. A file has several characteristics associated with it. They can be displayed using the ls –l command. Type regular file or special file. Permission or mode access definition for the file. Links number of file names associated with a single collection of data. Owner user identification of file owner Group group identification for file access Size number of bytes file contains Timestamp date file last modified Name maximum of 14 characters www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  8. Who Has Access The three classes of users are: • Owner — Usually the person who created the file. • Group — Several users that have been grouped together by the system administrator. For example, the members of a department might belong to the same group. • Other — All other users on the system. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  9. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  10. You should also be aware of the default permissions assigned to all of your files and directories at the time you create them. You can list or change the default permission settings by using the umask command. Default file permissions are assigned by the system whenever you create a new file or directory, and these are governed by your umask setting. To restrict these default permissions for newly-created files and directories, use the umask command. When a new file is created, each bit in the file mode creation mask that is set causes the corresponding permission bit in the file mode to be cleared (disabled); hence the term mask. Conversely, bits that are cleared in the mask allow the corresponding file mode bits to be enabled in newly created files. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  11. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  12. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  13. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  14. setuid: When set-user identification (setuid) permission is set on anexecutable file, a user or process that runs this executable file is granted access based on the owner of the file (usually root) instead of the user who started the executable. For eg. the executable file /usr/bin/passwd is set with setuid so that when any nonprivileged user runs the command the effective user id is not of the user but that of root. Because of that the password is updated in the file /etc/shadow though the normal user dont have any write permission on this file. -r-sr-xr-x 1 root sys 17156 Jan 5 17:03 /usr/bin/su setgid: The set-group identification (setgid) permission is similar to setuid,except that the effective group ID of the user or the process is changed to the group owner of the file. Also, access is granted based on the permissions assigned to that group. For example, the mail program has a setgid permission used to read mail, or send mail to other users. -r-x--s--x 1 root mail 61288 Jan 5 16:57 /usr/bin/mail The setgid permission is a useful feature for creating shared directories. When a setgid permission is applied to a directory, files created in the directory belong to the group to which the directory belongs. Sticky Bit: If the directory has the Sticky Bit set, a file can be deleted only by the owner of the file, the owner of the directory, or by root. This prevents a user from deleting other users’ files from publicly writable directories. For example: # ls -ld /tmp drwxrwxrwt 6 root sys 719 May 31 03:30 /tmp www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  15. The vi editor is a powerful, versatile editing tool. The vi editor is included with every versions of UNIX. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  16. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  17. l or -&gt; will move the cursor right by one character h or &lt;- will move the cursor left by one character j or down arrow will move the cursor one line down k or up arrow will move the cursor up by one line up w or W will move cursor to the next word b or B will move cursor to the previous word 0 will move cursor to the beginning of the line $ will move cursor to the end of the line 1G will move cursor to the first line of the file G will move cursor to the last line of the file &lt;ctrl-f&gt; will move cursor down by a page &lt;ctrl-b&gt; will move cursor up by a page H will move cursor to the top of the current page M will move cursor to the Middle of the current page L will move cursor to the bottom of the current page www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  18. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  19. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  20. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  21. www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar
  22. PID: Process ID PPID: Parent Process ID UID: User ID ps command will only show the processes started by the current user. ps -af will display all the processes started by all users ps -ef will display all the processes including the system processed www.scmGalaxy.com, Author - Rajesh Kumar www.scmGalaxy.com, Author - Rajesh Kumar