SlideShare a Scribd company logo
1 of 40
Download to read offline
Basic Linux Commands

       Srihari Kalgi
  M.Tech, CSE (KReSIT),
       IIT Bombay



       May 5, 2009
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
Calender


    ◮   cal: Command to see calender for any specific month or a
        complete year
          ◮   cal [ [month] year]
              $ cal april 2009
                       April 2009
              Su Mo Tu We Th Fr      Sa
                             1 2 3    4
               5 6 7 8 9 10          11
              12 13 14 15 16 17      18
              19 20 21 22 23 24      25
              26 27 28 29 30
date


       ◮   date: displays the current date
           $ date
           Tue Apr 21 21:33:49 IST 2009
           kuteer$ date +"%D %H:%M:%S"
           04/21/09 21:35:02
       ◮   Options:
             ◮   d - The da of the month (1-31)
             ◮   y - The last two digits of the year
             ◮   H,M,S - Hour Minute and second respectively
             ◮   D - the date in mm/dd/yy
       ◮   For more information see man date
echo and printf


    ◮   echo: Print message on the terminal
    ◮   usage: echo “<message>”
        $ echo "Welcome to the workshop"
        Welcome to the workshop
    ◮   printf: Print the formatted message on the terminal
    ◮   Syntax of printf is same as C language printf statement
    ◮   usage: printf “<formatted message”
        $ printf "the amount is %dn" 100
        the amount is 100
Calculator




    ◮   bc: A text based calculator
        $ bc
        2*10+20-9+4/2 [Input]
        33 [Output]
        [ctrl+d] [Quit]
    ◮   xcalc is graphical based calculator
script: Record your session
    ◮   script command records your session and stores it in a file
        $ script
        Script started, file is typescript
        $ echo "this is a sample script"
        this is a sample script
        $ [ctrl+d]
        Script done, file is typescript
    ◮   By default if you dont specify any file name the contents
        will be stored in file name typescipt
          $ cat typescript
        Script started on Tuesday 21 April 2009 10:07:00
        $ echo "this is a sample script"
        this is a sample script
        $
        Script done on Tuesday 21 April 2009 10:07:34 PM
passwd: Changing your password




    ◮   passwd command allows you to change your password
         kuteer:˜/workshop$ passwd
        Changing password for srihari.
        (current) UNIX password:
        Enter new UNIX password:
        Retype new UNIX password:
        passwd: password updated successfully
WHO: Who are the users?




    ◮   who command tells you the users currently logged on to
        the system
         kuteer:˜$ who
        srihari pts/0 2009-04-15        11:58   (:10.129.41.3)
        nithin pts/1 2009-04-15         16:09   (:10.129.20.5)
        avadhut pts/2 2009-04-13        14:39   (:10.129.45.20)
        anil pts/3    2009-04-13        16:32   (:10.129.23.45)
man - The reference Manual



    ◮   man displays the documentation for a command
    ◮   usage: man <command name>
               ls - list directory contents
        SYNOPSIS
               ls [OPTION]... [FILE]...
        DESCRIPTION
               List information about the              FILEs (the
               none of -cftuvSUX nor --sort.
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
Linux file system



    ◮   Standard directory structure
          ◮   / - the topmost
          ◮   /dev - all the devices are accessible as files
          ◮   /var - “variable” data such as mails, log files, databases
          ◮   /usr - almost all the packages installed
          ◮   /etc - configuration files
          ◮   /home - home directories for all the users
          ◮   /root - home directory of the privileged user root
          ◮   /mnt - used to mount other directories/partitions.
File Attributes


     ◮   To see the file attributes type ls -l on your terminal
         kuteer:˜$ ls -l
         $<$permissions$>$ $<$owner$>$ $<$group$>$
         drwxr-xr-x 2 srihari srihari       144 2009-04-0
         -rw-r--r-- 1 srihari srihari      1548 2009-03-2
         drwxr-xr-x 2 srihari srihari        48 2009-03-1
         -rw-r--r-- 1 srihari srihari      3570 2009-03-2
     ◮   The file Testing.java has the following permissions -rw-r–r–
     ◮   It has 10 characters, first character is d if its directory and -
         if its file.
     ◮   Next 9 characters are divided into three groups with a set
         of 3 characters each
File Attributes Contd. . .


     ◮   First 3 characters - Owner of the file or directory
     ◮   Next 3 characters - Group
     ◮   Last 3 characters - Others
     ◮   r - Read i.e. File or directory is readable
     ◮   w - Write i.e. File or directory is writable
     ◮   x - Execute i.e. File or directory is executable
     ◮   -rw-r–r– means it has read, write but not execute
         permissions for the owner of the file, only read permissions
         for the group and only read permissions for others
File Attributes Contd. . .




     ◮   The third column of the command ls -l tells about the
         owner of the file, next column tells to which group it
         belongs
          -rw-r--r--      1 srihari srihari             3570 2009-03-
     ◮   The file Testing.java has the owner as srihari and also
         belongs to a group called srihari
Changing the File attributes




    ◮   chmod Changing the permissions of the file
        kuteer:˜$ chmod o+x Testing.java
        kuteer:˜$ ls -l Testing.java
        -rw-r--r-x 1 srihari srihari 3570 2009-03-23 10:
        kuteer:˜$ chmod 655 Testing.java
        kuteer:˜$ ls -l Testing.java
        -rw-r-xr-x 1 srihari srihari 3570 2009-03-23 10:
Changing ownership



    ◮   chown command is used for changing the ownership and
        also group of the file
         kuteer:˜$ chown guest Testing.java
        kuteer:˜$ ls -l Testing.java
        -rw-r-xr-x 1 geust srihari 3570 2009-03-23 10:52
         kuteer:˜$ chown guest:guest Testing.java
        kuteer:˜$ ls -l Testing.java
        -rw-r-xr-x 1 geust guest 3570 2009-03-23 10:52 T
File system commands

    ◮   Deleting Files - rm
    ◮   Copying and moving files - cp, mv
    ◮   Creating directories - mkdir
    ◮   Deleting Empty Directory - rmdir
        $ rm Testing.java
        //deletes the file Testing.java
        $ cp Testing.java Copy.java
        //creates the copy of Testing.java
        $ mv Testing.java Test.java
        //renames the file Testing.java to Test.java
        $ mkdir newDir
        //Creates directory newDir
        $ rmdir newDir
        //deletes directory newDir newDir should be empt
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
cat : Concatenate Files


    ◮   cat command is used to display the contents of a small file
        on terminal
    ◮   usage: cat <file name>
        $ cat sample3.txt
        Unix (officially trademarked as UNIX, sometimes
        ......
    ◮   cat when supplied with more than one file will concatenate
        the files without any header information
         $ cat sample3.txt sample4.txt
        /*contents of sameple3.txt*/
        /*Followed by contents of sample4.txt without an
tac : concatenate files in reverse


    ◮   tac command is used to display the contents of a small file
        in reverse order on terminal
    ◮   usage: tac <file name>
          $ tac sample3.txt
        /*displays sample3.txt in reverse order*/
    ◮   tac when supplied with more than one file will concatenate
        the reverse contents of files without any header information
         $ tac sample3.txt sample4.txt
        /*print sample3.txt in reverse order*/
        /*print sample4.txt in reverse order without any
more, less : paging output

    ◮   more and less commands are used to view large files one
        page at a time
    ◮   usage: more <file name>
    ◮   usage: less <file name>
          $ more sample1.txt
        /*sample1.txt will be displayed one page
        at a time */
          $ less sample1.txt
        /*sample1.txt will be displayed one page
        at a time */
    ◮   less is the standard pager for linux and in general less is
        more powerful than more
wc : statistic of file


     ◮   wc command is used to count lines, words and characters,
         depending on the option used.
     ◮   usage: wc [options] [file name]
          $ wc sample1.txt
            65 2776 17333 sample1.txt
     ◮   Which means sample1.txt file has 65 lines, 2776 words,
         and 17333 characters
     ◮   you can just print number of lines, number of words or
         number of charcters by using following options:
           ◮   -l : Number of lines
           ◮   -w : Number of words
           ◮   -c : Number of characters
cmp: comparing two files


    ◮   cmp command is used to compare two files whether they
        are identical or not
    ◮   usage: cmp <file1> <file2>
    ◮   The two files are compared byte by byte and the location of
        the first mismatch is printed on the screen
    ◮   If two files are identical, then it doesnot print anything on
        the screen
         $ cmp sample1.txt sample2.txt
        sample1.txt sample2.txt differ: byte 1, line 1
         $ cmp sample1.txt sample1_copy.txt
         $ /*No output prompt returns back*/
comm : what is common?

   ◮   comm command displays what is common between both
       the files
   ◮   usage: comm <file1> <file2>
   ◮   The input files to comm command should be sorted
       alphabetically
        $ comm sample5.txt sample6.txt
                       anil
               barun
                       dasgupta
               lalit
                       shukla
       singhvi
       sumit
comm: contd. . .




    ◮   Column 1 gives the names which are present in
        sample5.txt but not in sample6.txt
    ◮   Column 2 gives the names which are not present in
        sample5.txt but present in sample6.txt
    ◮   Column 3 gives the names which are present in both the
        files
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
gzip and gunzip
    ◮   gzip command is used to compress the file, and gunzip is
        used to de-compress it.
    ◮   usage: gzip <file name>
    ◮   It provides the extension .gz and removes the original file
        $ wc sample_copy.txt
             65 2776 17333 sample_copy.txt
        $ gzip sample_copy.txt
        $ wc sample_copy.txt.gz
            26 155 7095 sample_copy.txt.gz
    ◮   The compression ratio depends on the type, size and
        nature of the file
    ◮   usage: gunzip <file name with.gz>
        $ gunzip sample_copy.txt.gz
        $ /*do ls and you can see the original file*/
    ◮   If you want to compress the directory contents recursively,
        use -r option with gzip command and unzip it use the
        same option with gunzip command
tar : The archival program

    ◮   tar command is used to create archive that contains a
        group or file or entire directory structure.
    ◮   It is generally used for back ups.
    ◮   usage: tar [options] <output file.tar> <file1 or dir> . . .
    ◮   The following are the options:
          ◮   -c Create an archive
          ◮   -x Extract files from archive
          ◮   -t Display files in archive
          ◮   -f arch Name the archive arch
         $ tar -cvf compression.tar compression
        compression/               //v for verbose
        compression/temp/
        compression/temp/sample2.txt
        compression/sample1.txt
tar contd. . .
     ◮   We can use tar and gzip command in succession to
         compress the tar file.
          $ tar -cvf compression.tar compression
          $ gzip compression.tar
          $ //will create compression.tar.gz file
     ◮   For un-compression the file first use gunzip command,
         which will create a tar file and then use tar command to
         untar the contents
          $ gunzip compression.tar.gz
          $ tar -xvf compression.tar
     ◮   To just view the contents of the tar file use -t option
          $ tar -tvf compression.tar
         $ tar -tvf compression.tar
         drwxr-xr-x srihari/srihari                0 2009-04-22 11:29
         drwxr-xr-x srihari/srihari                0 2009-04-22 11:29
         -rw-r--r-- srihari/srihari 17663 2009-04-22 11:2
         -rw-r--r-- srihari/srihari 17333 2009-04-22 11:2
tar contd. . .


     ◮   Instead of doing tar first and then gzip next, we can
         combine both of them using the option -z
         $ tar -cvzf compression.tar.gz compression
         compression/
         compression/temp/
         compression/temp/sample2.txt
         compression/sample1.txt
     ◮   We can de-compress .tar.gz agin in a single command
         using the option -z with -x
          $ tar -xvzf compression.tar.gz
zip and unzip: compressing and archiving

    ◮   zip command can be used for archiving as well as
        compressing the contents of the directory or the file
    ◮   usage: zip [options] output.zip <files to be zipped or
        directory>
        $ zip sample1.zip sample1.txt
        //will create sample1.zip file
    ◮   Use -r option to recursively zip the contents of the directory
         $ zip -r compression.zip compression
        // will create compression.zip file
    ◮   To un-compress the file use unzip command
         $ unzip compression.zip
        // will uncompress the compression.zip file
General Purpose utilities


Linux File System


File Handling Commands


Compressing and Archiving Files


Simple Filters
Filters
     ◮    Filters are commands which accept data from standard
          input, manupulate it and write the results to standard
          output
     ◮    head command displays the top of the file, when used
          without any option it will display first 10 lines of the file
            $ head sample1.txt
          /*display first 10 lines*/
     ◮    Similarly tail command displays the end of the file. By
          default it will display last 10 lines of the file
            $ tail sample1.txt
          /*display last 10 lines*/
     ◮    tail or head with -n followed by a number will display that
          many number of lines from last and from first respectively
            $ head -n 20 sample1.txt
          /* will display first 20 lines*/
            $ tail -n 15 sample1.txt
          /* will display last 15 lines */
cut : cutting columns



    ◮   cut command can be used to cut the columns from a file
        with -c option
    ◮   usage: cut -c [numbers delemited by comma or range]
        <file name>
         $ cut -c 1,2,3-5 students.txt
        1 ani
        2 das
        3 shu
        4 sin
cut : cutting fields



     ◮   With -f option you can cut the feilds delemited by some
         character
          $ cut -d" " -f1,4 students.txt
         1 Mtech
         2 Btech
         3 Mtech
     ◮   -d option is used to specify the delimiter and -f option used
         to specify the feild number
paste : pasting side by side



    ◮   paste command will paste the contents of the file side by
        side
         $ paste cutlist1.txt cutlist2.txt
        1 Mtech 1 anil H1
        2 Btech 2 dasgupta H4
        3 Mtech 3 shukla H7
        4 Mtech 4 singhvi H12
        5 Btech 5 sumit H13
sort : ordering a file



    ◮   sort re-orders lines in ASCII collating sequences-
        whitespaces first, then numerals, uppercase and finally
        lowercase
    ◮   you can sort the file based on a field by using -t and -k
        option.
         $ sort -t" " -k 2 students.txt
        /* sorts the file based on the second field
        using the delimiter as space*/
grep : searching for a pattern




    ◮   grep scans its input for a pattern, and can display the
        selected pattern, the line numbers or the filename where
        the pattern occurs.
    ◮   usage: grep options pattern filename(s)

More Related Content

What's hot

Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line conceptsArtem Nagornyi
 
Basic commands
Basic commandsBasic commands
Basic commandsambilivava
 
Linux commands part -2
Linux commands part -2Linux commands part -2
Linux commands part -2bhatvijetha
 
Linux command for beginners
Linux command for beginnersLinux command for beginners
Linux command for beginnersSuKyeong Jang
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filtersbhatvijetha
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic CommandsHanan Nmr
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity TipsKeith Bennett
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Noé Fernández-Pozo
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manualdummy
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
 

What's hot (20)

Linux commands
Linux commandsLinux commands
Linux commands
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Basic commands
Basic commandsBasic commands
Basic commands
 
Linux commands part -2
Linux commands part -2Linux commands part -2
Linux commands part -2
 
Linux command for beginners
Linux command for beginnersLinux command for beginners
Linux command for beginners
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic Commands
 
Unix Command Line Productivity Tips
Unix Command Line Productivity TipsUnix Command Line Productivity Tips
Unix Command Line Productivity Tips
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manual
 
Linux cheat-sheet
Linux cheat-sheetLinux cheat-sheet
Linux cheat-sheet
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
 
Unix
UnixUnix
Unix
 

Similar to Basic linux commands

Similar to Basic linux commands (20)

Group13
Group13Group13
Group13
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Chapter 3 Using Unix Commands
Chapter 3 Using Unix CommandsChapter 3 Using Unix Commands
Chapter 3 Using Unix Commands
 
2.Utilities.ppt
2.Utilities.ppt2.Utilities.ppt
2.Utilities.ppt
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Bozorgmeh os lab
Bozorgmeh os labBozorgmeh os lab
Bozorgmeh os lab
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
Linux file commands and shell scripts
Linux file commands and shell scriptsLinux file commands and shell scripts
Linux file commands and shell scripts
 
Basics of Unix Adminisration
Basics  of Unix AdminisrationBasics  of Unix Adminisration
Basics of Unix Adminisration
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Raspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OSRaspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OS
 
Unix Basics Commands
Unix Basics CommandsUnix Basics Commands
Unix Basics Commands
 
Basic Linux Commands
Basic Linux CommandsBasic Linux Commands
Basic Linux Commands
 
35 ls Command Examples in Linux (The Complete Guide).pdf
35 ls Command Examples in Linux (The Complete Guide).pdf35 ls Command Examples in Linux (The Complete Guide).pdf
35 ls Command Examples in Linux (The Complete Guide).pdf
 
Shell programming
Shell programmingShell programming
Shell programming
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Basic linux commands

  • 1. Basic Linux Commands Srihari Kalgi M.Tech, CSE (KReSIT), IIT Bombay May 5, 2009
  • 2. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 3. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 4. Calender ◮ cal: Command to see calender for any specific month or a complete year ◮ cal [ [month] year] $ cal april 2009 April 2009 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  • 5. date ◮ date: displays the current date $ date Tue Apr 21 21:33:49 IST 2009 kuteer$ date +"%D %H:%M:%S" 04/21/09 21:35:02 ◮ Options: ◮ d - The da of the month (1-31) ◮ y - The last two digits of the year ◮ H,M,S - Hour Minute and second respectively ◮ D - the date in mm/dd/yy ◮ For more information see man date
  • 6. echo and printf ◮ echo: Print message on the terminal ◮ usage: echo “<message>” $ echo "Welcome to the workshop" Welcome to the workshop ◮ printf: Print the formatted message on the terminal ◮ Syntax of printf is same as C language printf statement ◮ usage: printf “<formatted message” $ printf "the amount is %dn" 100 the amount is 100
  • 7. Calculator ◮ bc: A text based calculator $ bc 2*10+20-9+4/2 [Input] 33 [Output] [ctrl+d] [Quit] ◮ xcalc is graphical based calculator
  • 8. script: Record your session ◮ script command records your session and stores it in a file $ script Script started, file is typescript $ echo "this is a sample script" this is a sample script $ [ctrl+d] Script done, file is typescript ◮ By default if you dont specify any file name the contents will be stored in file name typescipt $ cat typescript Script started on Tuesday 21 April 2009 10:07:00 $ echo "this is a sample script" this is a sample script $ Script done on Tuesday 21 April 2009 10:07:34 PM
  • 9. passwd: Changing your password ◮ passwd command allows you to change your password kuteer:˜/workshop$ passwd Changing password for srihari. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
  • 10. WHO: Who are the users? ◮ who command tells you the users currently logged on to the system kuteer:˜$ who srihari pts/0 2009-04-15 11:58 (:10.129.41.3) nithin pts/1 2009-04-15 16:09 (:10.129.20.5) avadhut pts/2 2009-04-13 14:39 (:10.129.45.20) anil pts/3 2009-04-13 16:32 (:10.129.23.45)
  • 11. man - The reference Manual ◮ man displays the documentation for a command ◮ usage: man <command name> ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION List information about the FILEs (the none of -cftuvSUX nor --sort.
  • 12. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 13. Linux file system ◮ Standard directory structure ◮ / - the topmost ◮ /dev - all the devices are accessible as files ◮ /var - “variable” data such as mails, log files, databases ◮ /usr - almost all the packages installed ◮ /etc - configuration files ◮ /home - home directories for all the users ◮ /root - home directory of the privileged user root ◮ /mnt - used to mount other directories/partitions.
  • 14. File Attributes ◮ To see the file attributes type ls -l on your terminal kuteer:˜$ ls -l $<$permissions$>$ $<$owner$>$ $<$group$>$ drwxr-xr-x 2 srihari srihari 144 2009-04-0 -rw-r--r-- 1 srihari srihari 1548 2009-03-2 drwxr-xr-x 2 srihari srihari 48 2009-03-1 -rw-r--r-- 1 srihari srihari 3570 2009-03-2 ◮ The file Testing.java has the following permissions -rw-r–r– ◮ It has 10 characters, first character is d if its directory and - if its file. ◮ Next 9 characters are divided into three groups with a set of 3 characters each
  • 15. File Attributes Contd. . . ◮ First 3 characters - Owner of the file or directory ◮ Next 3 characters - Group ◮ Last 3 characters - Others ◮ r - Read i.e. File or directory is readable ◮ w - Write i.e. File or directory is writable ◮ x - Execute i.e. File or directory is executable ◮ -rw-r–r– means it has read, write but not execute permissions for the owner of the file, only read permissions for the group and only read permissions for others
  • 16. File Attributes Contd. . . ◮ The third column of the command ls -l tells about the owner of the file, next column tells to which group it belongs -rw-r--r-- 1 srihari srihari 3570 2009-03- ◮ The file Testing.java has the owner as srihari and also belongs to a group called srihari
  • 17. Changing the File attributes ◮ chmod Changing the permissions of the file kuteer:˜$ chmod o+x Testing.java kuteer:˜$ ls -l Testing.java -rw-r--r-x 1 srihari srihari 3570 2009-03-23 10: kuteer:˜$ chmod 655 Testing.java kuteer:˜$ ls -l Testing.java -rw-r-xr-x 1 srihari srihari 3570 2009-03-23 10:
  • 18. Changing ownership ◮ chown command is used for changing the ownership and also group of the file kuteer:˜$ chown guest Testing.java kuteer:˜$ ls -l Testing.java -rw-r-xr-x 1 geust srihari 3570 2009-03-23 10:52 kuteer:˜$ chown guest:guest Testing.java kuteer:˜$ ls -l Testing.java -rw-r-xr-x 1 geust guest 3570 2009-03-23 10:52 T
  • 19. File system commands ◮ Deleting Files - rm ◮ Copying and moving files - cp, mv ◮ Creating directories - mkdir ◮ Deleting Empty Directory - rmdir $ rm Testing.java //deletes the file Testing.java $ cp Testing.java Copy.java //creates the copy of Testing.java $ mv Testing.java Test.java //renames the file Testing.java to Test.java $ mkdir newDir //Creates directory newDir $ rmdir newDir //deletes directory newDir newDir should be empt
  • 20. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 21. cat : Concatenate Files ◮ cat command is used to display the contents of a small file on terminal ◮ usage: cat <file name> $ cat sample3.txt Unix (officially trademarked as UNIX, sometimes ...... ◮ cat when supplied with more than one file will concatenate the files without any header information $ cat sample3.txt sample4.txt /*contents of sameple3.txt*/ /*Followed by contents of sample4.txt without an
  • 22. tac : concatenate files in reverse ◮ tac command is used to display the contents of a small file in reverse order on terminal ◮ usage: tac <file name> $ tac sample3.txt /*displays sample3.txt in reverse order*/ ◮ tac when supplied with more than one file will concatenate the reverse contents of files without any header information $ tac sample3.txt sample4.txt /*print sample3.txt in reverse order*/ /*print sample4.txt in reverse order without any
  • 23. more, less : paging output ◮ more and less commands are used to view large files one page at a time ◮ usage: more <file name> ◮ usage: less <file name> $ more sample1.txt /*sample1.txt will be displayed one page at a time */ $ less sample1.txt /*sample1.txt will be displayed one page at a time */ ◮ less is the standard pager for linux and in general less is more powerful than more
  • 24. wc : statistic of file ◮ wc command is used to count lines, words and characters, depending on the option used. ◮ usage: wc [options] [file name] $ wc sample1.txt 65 2776 17333 sample1.txt ◮ Which means sample1.txt file has 65 lines, 2776 words, and 17333 characters ◮ you can just print number of lines, number of words or number of charcters by using following options: ◮ -l : Number of lines ◮ -w : Number of words ◮ -c : Number of characters
  • 25. cmp: comparing two files ◮ cmp command is used to compare two files whether they are identical or not ◮ usage: cmp <file1> <file2> ◮ The two files are compared byte by byte and the location of the first mismatch is printed on the screen ◮ If two files are identical, then it doesnot print anything on the screen $ cmp sample1.txt sample2.txt sample1.txt sample2.txt differ: byte 1, line 1 $ cmp sample1.txt sample1_copy.txt $ /*No output prompt returns back*/
  • 26. comm : what is common? ◮ comm command displays what is common between both the files ◮ usage: comm <file1> <file2> ◮ The input files to comm command should be sorted alphabetically $ comm sample5.txt sample6.txt anil barun dasgupta lalit shukla singhvi sumit
  • 27. comm: contd. . . ◮ Column 1 gives the names which are present in sample5.txt but not in sample6.txt ◮ Column 2 gives the names which are not present in sample5.txt but present in sample6.txt ◮ Column 3 gives the names which are present in both the files
  • 28. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 29. gzip and gunzip ◮ gzip command is used to compress the file, and gunzip is used to de-compress it. ◮ usage: gzip <file name> ◮ It provides the extension .gz and removes the original file $ wc sample_copy.txt 65 2776 17333 sample_copy.txt $ gzip sample_copy.txt $ wc sample_copy.txt.gz 26 155 7095 sample_copy.txt.gz ◮ The compression ratio depends on the type, size and nature of the file ◮ usage: gunzip <file name with.gz> $ gunzip sample_copy.txt.gz $ /*do ls and you can see the original file*/ ◮ If you want to compress the directory contents recursively, use -r option with gzip command and unzip it use the same option with gunzip command
  • 30. tar : The archival program ◮ tar command is used to create archive that contains a group or file or entire directory structure. ◮ It is generally used for back ups. ◮ usage: tar [options] <output file.tar> <file1 or dir> . . . ◮ The following are the options: ◮ -c Create an archive ◮ -x Extract files from archive ◮ -t Display files in archive ◮ -f arch Name the archive arch $ tar -cvf compression.tar compression compression/ //v for verbose compression/temp/ compression/temp/sample2.txt compression/sample1.txt
  • 31. tar contd. . . ◮ We can use tar and gzip command in succession to compress the tar file. $ tar -cvf compression.tar compression $ gzip compression.tar $ //will create compression.tar.gz file ◮ For un-compression the file first use gunzip command, which will create a tar file and then use tar command to untar the contents $ gunzip compression.tar.gz $ tar -xvf compression.tar ◮ To just view the contents of the tar file use -t option $ tar -tvf compression.tar $ tar -tvf compression.tar drwxr-xr-x srihari/srihari 0 2009-04-22 11:29 drwxr-xr-x srihari/srihari 0 2009-04-22 11:29 -rw-r--r-- srihari/srihari 17663 2009-04-22 11:2 -rw-r--r-- srihari/srihari 17333 2009-04-22 11:2
  • 32. tar contd. . . ◮ Instead of doing tar first and then gzip next, we can combine both of them using the option -z $ tar -cvzf compression.tar.gz compression compression/ compression/temp/ compression/temp/sample2.txt compression/sample1.txt ◮ We can de-compress .tar.gz agin in a single command using the option -z with -x $ tar -xvzf compression.tar.gz
  • 33. zip and unzip: compressing and archiving ◮ zip command can be used for archiving as well as compressing the contents of the directory or the file ◮ usage: zip [options] output.zip <files to be zipped or directory> $ zip sample1.zip sample1.txt //will create sample1.zip file ◮ Use -r option to recursively zip the contents of the directory $ zip -r compression.zip compression // will create compression.zip file ◮ To un-compress the file use unzip command $ unzip compression.zip // will uncompress the compression.zip file
  • 34. General Purpose utilities Linux File System File Handling Commands Compressing and Archiving Files Simple Filters
  • 35. Filters ◮ Filters are commands which accept data from standard input, manupulate it and write the results to standard output ◮ head command displays the top of the file, when used without any option it will display first 10 lines of the file $ head sample1.txt /*display first 10 lines*/ ◮ Similarly tail command displays the end of the file. By default it will display last 10 lines of the file $ tail sample1.txt /*display last 10 lines*/ ◮ tail or head with -n followed by a number will display that many number of lines from last and from first respectively $ head -n 20 sample1.txt /* will display first 20 lines*/ $ tail -n 15 sample1.txt /* will display last 15 lines */
  • 36. cut : cutting columns ◮ cut command can be used to cut the columns from a file with -c option ◮ usage: cut -c [numbers delemited by comma or range] <file name> $ cut -c 1,2,3-5 students.txt 1 ani 2 das 3 shu 4 sin
  • 37. cut : cutting fields ◮ With -f option you can cut the feilds delemited by some character $ cut -d" " -f1,4 students.txt 1 Mtech 2 Btech 3 Mtech ◮ -d option is used to specify the delimiter and -f option used to specify the feild number
  • 38. paste : pasting side by side ◮ paste command will paste the contents of the file side by side $ paste cutlist1.txt cutlist2.txt 1 Mtech 1 anil H1 2 Btech 2 dasgupta H4 3 Mtech 3 shukla H7 4 Mtech 4 singhvi H12 5 Btech 5 sumit H13
  • 39. sort : ordering a file ◮ sort re-orders lines in ASCII collating sequences- whitespaces first, then numerals, uppercase and finally lowercase ◮ you can sort the file based on a field by using -t and -k option. $ sort -t" " -k 2 students.txt /* sorts the file based on the second field using the delimiter as space*/
  • 40. grep : searching for a pattern ◮ grep scans its input for a pattern, and can display the selected pattern, the line numbers or the filename where the pattern occurs. ◮ usage: grep options pattern filename(s)