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.txtresults inls: cannot access /fake: No such file or directoryinoutput.txt.
Use
2>to redirect error output (STDERR) to a file.Example:
$ ls /fake 2> error.txtcaptures the error message inerror.txt.
Use
&>to redirect both STDOUT and STDERR to one file.Example:
$ ls /fake /etc/ppp &> all.txtcaptures both outputs inall.txt.
Using tr Command
The
trcommand 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
findcommand 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.txtfor error logging.$ find /etc -size +300finds files over 300 blocks.
Specifying size units:
Use
cfor bytes,kfor kilobytes,Mfor megabytes,Gfor gigabytes.Example to find files of specific size:
$ find /etc -size 10c -ls 2>/dev/nullto find files exactly 10 bytes.
Advanced find Options
Multiple criteria act as logical "AND".
Example:
$ find /etc -size 10c -type f -ls 2>/dev/nullshows files that are 10 bytes and regular files.
Using cut Command
The
cutcommand extracts text columns from files.Command Example:
$ cut -d: -f1,5-7 mypasswdextracts 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
grepcommand searches for patterns within files or command output.General syntax:
grep [options] what_to_search file_nameExample 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.txtlooks 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
forkandexecvein UNIX;CreateProcessin 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.