SO 04-05 - Structura SO

UNIX Command Line Basics

File Redirection

  • Standard Output (STDOUT) and Error Output (STDERR):

    • Use > to redirect standard output to a file.

      • Example: $ ls /fake > output.txt results in ls: cannot access /fake: No such file or directory in output.txt.

    • Use 2> to redirect error output (STDERR) to a file.

      • Example: $ ls /fake 2> error.txt captures the error message in error.txt.

    • Use &> to redirect both STDOUT and STDERR to one file.

      • Example: $ ls /fake /etc/ppp &> all.txt captures both outputs in all.txt.

Using tr Command

  • The tr command translates characters in the input.

    • Command Example: $ tr 'a-z' 'A-Z' changes lowercase letters to uppercase.

    • Input redirection can be used with <, e.g. $ tr 'a-z' 'A-Z' < sample.txt.

    • Using <<< allows directly passing a string for transformation.

      • Example: $ tr 'a-z' 'A-Z' <<< 'Transformare in majuscule'.

Finding Files with find

  • The find command helps locate files based on criteria.

    • Basic syntax: find starting_dir matching_criteria [options]

    • Example Commands:

      • $ find /usr -name startx

      • $ find /etc -name hosts 2> errors.txt for error logging.

      • $ find /etc -size +300 finds files over 300 blocks.

  • Specifying size units:

    • Use c for bytes, k for kilobytes, M for megabytes, G for gigabytes.

    • Example to find files of specific size:

      • $ find /etc -size 10c -ls 2>/dev/null to find files exactly 10 bytes.

Advanced find Options

  • Multiple criteria act as logical "AND".

    • Example: $ find /etc -size 10c -type f -ls 2>/dev/null shows files that are 10 bytes and regular files.

Using cut Command

  • The cut command extracts text columns from files.

    • Command Example: $ cut -d: -f1,5-7 mypasswd extracts specified fields from a colon-delimited file.

    • Extracting character positions:

      • Example: $ ls -l | cut -c1-11,47- shows file type & permissions along with filename.

Searching with grep

  • The grep command searches for patterns within files or command output.

    • General syntax: grep [options] what_to_search file_name

    • Example Commands:

      • $ grep root /etc/passwd

      • $ grep test ./*

      • $ ls -la | grep -i 'mar 14' for case-insensitive search.

Regular Expressions Fundamentals

  • Regular expressions consist of normal and special characters for pattern matching:

    • Basic Matching Syntax:

      • . for any single character.

      • [] for a character set.

      • * to denote zero or more occurrences.

      • ^ asserts position at line start; $ asserts position at line end.

Regular Expression Examples

  • To find patterns:

    • Command: $ grep 'a..' example.txt looks for a letter followed by any two characters.

    • Use [ab][a-d] to match patterns with specific character criteria.

    • Use [^abc] to match characters outside a specified range.

Virtual Machines in OS

  • Virtual machines simulate separate environments on a shared physical machine.

  • Each VM appears to have its own CPU and memory resources, while sharing the actual physical resources.

Components of an Operating System (OS)

  • Process Management: Handling the lifecycle and scheduling of processes.

  • Memory Management: Allocation and deallocation of memory space as needed.

  • File System Management: Creating, deleting, and accessing files and directories.

  • I/O System Management: Facilitating input/output operations between the system and hardware devices.

  • Networking: Managing communication between different devices and networks for data exchange.

Example System Calls in UNIX & Win32

  • System calls provide an interface for user programs to communicate with the OS.

    • Examples include fork and execve in UNIX; CreateProcess in Win32.


These notes summarize the core concepts presented in the transcripts about UNIX command usage, regular expressions, and basic operating system components. Use them for reviewing and preparing for your exam.