Operating Systems & Administration

[Day 2] 6. Some more commands

D
DITISS Admin
••2 min read

File Manipulation Commands

Displaying File Content

  1. Number Lines:
    cat -n <filename>
    • Displays the contents of the file with line numbers.
  2. View First Lines:
    head <filename>
    • Displays the first 10 lines of the file by default.
  3. View Last Lines:
    tail <filename>
    • Displays the last 10 lines of the file by default.
  4. View Specific Number of Lines from Start:
    head -6 <filename>
    • Displays the first 6 lines of the file.
  5. View Specific Number of Lines from End:
    tail -5 <filename>
    • Displays the last 5 lines of the file.

Extracting Middle Elements

  • There is no direct option to print specific middle elements of a file. To achieve this, you need to combine commands, such as using
    head
    and
    tail
    .

Sorting and Reversing Content

  1. Sort File:
    sort <filename>
    • Sorts the file contents in lexicographical order (alphabetically).
  2. Number-wise Sorting:
    sort -n <filename>
    • Sorts the file contents numerically.
  3. Reverse File Horizontally:
    rev <filename>
    • Reverses the contents of the file line by line (horizontally).
  4. Reverse File Vertically:
    tac <filename>
    • Displays the file contents in reverse order (vertically).
  5. Display Unique Values:
    uniq <filename>
    • Displays only unique values in the file.
    • Works only on sorted data and requires consecutive duplicates to be filtered.

Read Next

8/26/2026

[Day 2] 7. Redirection

### Console Standard Files The console operates with three internal standard files: 1. **Standard Input File**: Used to take input. 2. **Standa...

8/26/2026

[Day 3] 1. Revision

### **Process Control Block (PCB) in Linux** - The `task_struct` is a structure used to create the Process Control Block (PCB). - The size of...