Operating Systems & Administration

[Day 3] 4. Some more commands

D
DITISS Admin
••5 min read

1. Head and Tail Commands:

  • head
    : Displays the first part of files.
    head -5 filename.txt

    • This command prints the first 5 lines of
      filename.txt
      .
    • You can also use negative numbers with
      head
      , but this feature might vary based on the implementation.
  • tail
    : Displays the last part of files.

    • Example:

      tail +5 filename.txt

    • This command starts printing from the 5th line onward to the end of

      filename.txt
      .

    • Unlike

      head
      ,
      tail
      does not accept negative numbers.


2. Echo Command:

  • echo
    : Used to display messages or output text to the console.
    • Example:
      echo "Hello Ojas"
      • This command prints
        Hello Ojas
        on the console.

3. Translate Command (tr):

  • tr
    : Used to translate or delete characters.
    • Examples:
      • Translate space to

        #
        :
        echo "text with spaces" | tr ' ' '#'

        • This replaces spaces with
          #
          .
      • Squeeze multiple spaces into one:

        echo "text    with   multiple    spaces" | tr -s ' '

        • This command condenses consecutive spaces into a single space.
      • Change case:

        echo "Hello World" | tr 'A-Z' 'a-z'

        • This converts uppercase letters to lowercase.

4. Cut Command:

  • cut
    : Used to remove sections from each line of files.
    • Example:

      cut -d ',' -f 1 filename.csv

      • This command cuts and displays the first field (column) from a CSV file, using a comma as the delimiter.

      • You can also specify ranges:

        cut -d ',' -f 1-3 filename.csv

      • This would cut and display fields 1 through 3.


Meta-characters/Wildcards in Shell:

  1. *
    : Represents all characters.
  2. ?
    : Represents a single occurrence of any character.
  3. ;
    : Used to separate multiple commands on a single line.

Changing Permissions with chmod:

  • chmod
    : Changes the file permissions (also called access or mode).

    • Examples:
      • Add write permission:

        chmod +w filename.txt

      • Add execute permission for all:

        chmod +x filename.txt

  • Setting permissions using user types:

    • u
      : User
    • g
      : Group
    • o
      : Others
    • Example:
      chmod u+x,g-w filename.txt
  • Octal Notation: Permissions can also be changed using octal numbers.

    • For example, if the original permissions are
      rw- rw- r--
      , the octal number would be
      664
      .
    • You can set this using:
      chmod 664 filename.txt

Why Are Permissions Required?

Permissions ensure that only authorized users can read, write, or execute files, providing security and access control.


Changing File Ownership with chown:

  • chown
    : Changes the ownership of a file.

    • Example:
      chown username filename.txt
  • Change group ownership:

    • Example:
      chown :groupname filename.txt
  • Change both owner and group:

    • Example:
      chown username:groupname filename.txt
  • To change ownership of a directory and all its sub-directories, use

    -R
    (recursive):
    chown -R username directoryname/


Find Command:

  • find
    : Searches for files in a directory hierarchy.
    • Search by name:

      find -name test.txt

    • Search by exact path:

      find /home/sunbeam -name test.txt

    • Search by file type:

      • Simple files:

        find -type f

      • Directories:

        find -type d

    • Search by size:

      find . -size +1M

      • This searches for files larger than 1 MB in the current directory.

Read Next

8/26/2026

[Day 4] 1. Few more Commands

## **Types of Commands in Linux** #### **1. Internal Commands** - **Definition**: Commands implemented within the shell program itself. - **Exe...

8/26/2026

[Day 4] 3. Types of Operating System

### **Resident Monitors** !3. Resident Monitors.png - **Input Method:** Code was written using a typewriter-like device on punch cards. - **Pro...