UNIX Complete Study Guide PDF
Document Details
![EndearingFairy1361](https://quizgecko.com/images/avatars/avatar-1.webp)
Uploaded by EndearingFairy1361
Czech University of Life Sciences Prague
Tags
Summary
This document provides a study guide for UNIX, covering basic concepts, file systems, permissions, processes, and shell commands. It is likely intended for students in computer science.
Full Transcript
UNIX Complete Study Guide Basic Concepts 1. What is an operating system kernel? – A program that resides in main memory and controls hardware – Starts programs and controls their execution according to user requirements 2. What components make up an OS distribution?...
UNIX Complete Study Guide Basic Concepts 1. What is an operating system kernel? – A program that resides in main memory and controls hardware – Starts programs and controls their execution according to user requirements 2. What components make up an OS distribution? – Kernel of OS – System programs – Libraries – Configuration files 3. What are the file types in Unix and their symbols? – Regular files (-) – Directory (d) – Link file (l) – Control file for character data transfer (c) – Control file for blocked data transfer (b) File System & Permissions 4. What is an i-node and what information does it store? – Type of file – Access rights – UID and GID – Date of last write, use, and modification – Size of file in bytes – Total number of used blocks – Total number of hard links – Addresses of data blocks 5. What is the difference between hard and soft links? Hard Link: – Is a directory item (couple of filename and i-node number) – Cannot cross file systems – Cannot link to directories – Deleting original file doesn’t affect hard link Soft Link: – Special file containing path to target – Can cross file systems – Has its own i-node – Can link to directories – Becomes invalid if target is deleted 6. How are file permissions organized? Access rights are defined for: – Individual owner – Group owner – Other users Rights include: – Read (r) – Write (w) – Execute (x) 7. What are special permission bits? – s-bit (Set User ID/Set Group ID) – t-bit (Sticky bit) Effects: When s-bit is set on executable: Changes effective owner of process When t-bit is set on directory: For binary programs: Prevents the OS from freeing all program pages after termination., For directories: Allows users to create files but only delete their own files. 8. What does the command chmod 755 file do? A: Sets the permissions of the file to rwxr-xr-x. Processes 8. How are processes created in Unix? – New processes are crested using through fork() system call – Exception is the process swapper (or init), created by OS kernel at system start 9. What happens during fork() system call? 1. OS creates new process (child) that is copy of calling process (parent) 2. Child process gets its own page table 3. Child process gets its own u-area 4. Return values differ: In parent process: PID of child process In child process: 0 10. What are the basic process states? – Running in user mode – Running in kernel mode – Ready to run – Blocked 11. What is multitasking in Unix? Unix uses pre-emptive multitasking: – Process can run continuously only for limited time (time quantum) – After time quantum expires, kernel stops running process – Scheduler chooses next process according to priority – Process stopping due to time quantum expiration is called pre-emption 12. What are process groups? - A process group is a collection of processes identified by a group ID (PGRP). The leader of the group has a PID equal to PGRP. Shell Commands 12. What is the basic shell command format? name [-options] [arguments] 13. What are escape characters in shell and their purpose? - ” ” - Special meaning of all characters inside except $ is canceled - ’ ’ - Special meaning of all characters inside including $ is canceled - - Special meaning of the character that follows is canceled 14. What happens during the execve() system call? - The OS finds the executable file, checks permissions, and verifies the magic number. - Changes the effective user ID if the setuid bit is set. - Copies program arguments and environment to the new process stack. - Initializes the process memory and sets the instruction register to the program's entry point. 15. What is a pipe in shell? – Shell creates temporary file (buffer) in filesystem – Ensures controlled data transfer from standard output of prog1 to standard input of prog2 – Syntax: prog1 | prog2 16. What are file descriptors? – Small nonnegative integers (starting from 0) used for file identification – Standard descriptors: 0: standard input (keyboard) 1: standard output (display) 2: error output (display) 17. What are escape characters in the shell? - \ Cancels the special meaning of the character that follows. - " Cancels special meaning for all characters except $. - ' Cancels special meaning for all characters, including $. Signals 16. What are signals in Unix and their purpose? – Signals inform processes about asynchronous events – Processes can send signals using kill() system call – OS kernel can also send signals to processes 17. What are the three most important signals? – SIGINT (2): Sent by keyboard handler after CTRL+C – SIGKILL (9): Signal for process termination, cannot be ignored – SIGTERM (15): Signal for standard process termination Shell Variables 18. What are the types of shell variables? Local variables: – Contain information for running shell – Can be used in scripts – Not accessible in processes started from shell – Usually named with small letters Environmental variables: – Accessible in processes started from shell – Some have standard meaning (HOME, USER, etc.) – Usually named with capital letters Common Commands 19. Important command examples: – Create file: touch filename – Create directory: mkdir dirname – Change directory: cd path – List files: ls [options] – Remove files: rm [options] files – Copy files: cp source destination – Move files: mv source destination – View file contents: cat filename – View process status: ps [options] – Kill process: kill [signal] PID – Search text: grep pattern file 20. How to run a program in background? – Add & at end of command:./program & – Switch running program to background: Ctrl+Z, then bg – Bring background program to foreground: fg Regular Expressions and Text Processing 21. Basic regular expression patterns: – ^ - Start of line – $ - End of line –. - Any single character – * - Zero or more occurrences – [] - Any character in brackets – [^] - Any character not in brackets – [0-9] - Any digit – [a-z] - Any lowercase letter Commands and Utilities 22. What commands are used for common tasks? Print a string: echo "text" Display manual pages: man command Create a file: touch filename List files: ls View file contents: cat filename Report running processes: ps 23. What is the command to find all processes of a user? ps -u username Advanced Topics 24. What is an environmental variable? How is it different from a local variable? Environmental Variable: Accessible to child processes; defined using export NAME=value. Local Variable: Limited to the shell or script where it is defined; set using NAME=value. 25. How does the file cache improve performance? The file cache stores recently accessed blocks of data to reduce disk I/O operations, speeding up read/write processes. 26. How do you run a program in the background? Use & after the command, e.g.,./program &. Answers I got wrong from 3 UNIX Credit tests. File, directory, and variable Write command to pull a file Write cmd to pull a directory Which of following commands will list all files in current directory that include characters m or c? ls *[mc]* Becuase ls list the content in files, * Matches any sequence of characters & [mc] Matches either 'm' or 'c' Obtatin a sample of first five student accounts defined in the system using pipeline cat /etc/passwd | grep student | head -n 5 cat /etc/passwd - gives the output of contents of /etc/password, grep filters the output to only students, head -n 5 - limits the output to the first five lines and | combines together multiple commands. Switch a running process from background to foreground: fg - to run program from bg to fg (terminate process un fg: Ctrl + C) bg - to run program from fg to bg (terminate process un fg: Ctrl + Z) Switch from a direcory /home/user1 into /etc using one of following options cd../../etc cd change directory../../ moves up two directory levels etc target directory Redirect both standard and error output of program prog1 into a file log: prog1 2>&1 > log prog1 is the cmd being executed. 2>&1 merges file descriptor 2 into the same file descripter 2 > execueted into file log Let’s suppose student accounts are created using pattern xstudent00..xstudent99,Provide with all student accounts: grep xstudent /etc/passwd grep is used for searching text patterns within file. What is the next step after finishing a shell script script1.sh in a text editor? Set permissions to execute. What command is used to search/find a file: find What loop is best used for iteration throughout files? for What special variable stores return value from the last executed command? $? $# - no of arguments Delete all files from folder Trash in your current directory. ls -l drwxrwxrwx 1 user user 1212575289 Oct 16 17:48 Trash rm Trash/* rm – remove, Trash/* is ony trash directory and not sub directory. Program prg,is located in current directory. How do we run such program?./prg./ for current directory and without it, it will the shell looks for the executable in directories listed in the PATH environment variable A command ls -a will print out: also hidden files (begin with „.“) UNIX COMPLETE STUDY GUIDE 1. What is an operating system kernel? Answer: A program that is in the main memory and controls hardware means of the computer, starts programs and controls their execution according to user requirements 2. What components make up an OS distribution? Answer: Kernel of OS System programs Libraries Configuration files 3. What are the file types in Unix and their symbols? Answer: Regular files (-) Directory (d) Link file (l) Control file for character data transfer (c) Control file for blocked data transfer (b) 4. What are descriptors and what are they used for? Answer: A descriptor is a small nonnegative integer (starting from 0) that process can use for file identification. After successful file open, the system calls open() or creat() return this descriptor that process can use in the following read and write calls. 5. What are the standard descriptors and their uses? Answer: 0 - standard input (keyboard) 1 - standard output (display) 2 - error output (display) 6. What is the basic shell command format? Answer: name [-options] [arguments] 7. How are processes created in Unix? Answer: New process arises only if some running process calls the system service fork(). The exception is the process swapper (or init if the system has no swapper), which is created by OS kernel after start of the system. 8. What happens during fork() system call? Answer: 1. OS creates a new process (child process) that is a copy of the calling process (parent process) 2. The child process has its own page table 3. The child process has its own u-area 4. Return values differ: a. In parent process: PID of child process b. In child process: 0 9. What are the basic process states? Answer: Running in user mode Running in kernel mode Ready to run Blocked 10. What is multitasking in Unix? Answer: In Unix multitasking is pre-emptive, meaning: Process can run continuously only for limited time (time quantum) After time quantum expires, kernel stops the running process Scheduler chooses next process according to priority The stopping of process due to time quantum expiration is called pre-emption 11. What are signals in Unix and their purpose? Answer: Signals inform processes about asynchronous events. Process can send signal to another process using system service kill(). The OS kernel can send signals to processes as well. 12. What are the three most important signals? Answer: SIGINT (2) - Keyboard handler sends to process running on foreground after CTRL+C SIGKILL (9) - Signal for process termination, cannot be ignored or treated SIGTERM (15) - Signal for standard process termination 13. What information is stored in an i-node? Answer: Type of the file Access rights UID and GID Date of last write, use, and modification Size of file in bytes Total number of used blocks Total number of hard links Addresses of data blocks 14. What is the difference between hard and soft links? Answer: Hard Link: Is a directory item (couple of filename and i-node number) Cannot cross file systems Cannot link to directories Soft Link: Special file containing path to target Can cross file systems Has its own i-node Can link to directories Becomes invalid if target is deleted 15. How does shell execute commands? Answer: Shell: 1. Interprets special characters in the strings 2. If string is an alias, replaces according to alias table 3. If string is user defined function, executes this function 4. If string is inner shell command, executes it 5. Otherwise considers string to be path to executable file 16. What are escape characters in shell and their purpose? Answer: " " - Special meaning of all characters inside except $ is canceled ' ' - Special meaning of all characters inside including $ is canceled \ - Special meaning of the character that immediately follows \ is canceled 17. What is pipe in shell? Answer: Shell creates temporary file (buffer) in file system and ensures controlled transfer of data from standard output of prog1 to standard input of prog2 when using syntax: prog1|prog2 18. What information is stored in process table? Answer: PID - Process number Process state Field of signals Pointer to page table Pointer to u-area 19. What information is stored in u-area? Answer: Real and effective user and group name Current directory and root directory Table of descriptors I/O parameters Signal treatment Control terminal Result and parameters of system call 20. What are process groups? Answer: Each process is member of process group. Process groups are denoted by natural number PGRP. Each group has leader - process whose PID equals PGRP. 21. What happens during system call execve()? Answer: 1. OS finds file determined by path, checks magic number and execution right x 2. If file has user s-bit set, changes effective owner of process 3. Stores running parameters and environmental parameters on system stack 4. Creates new process page table 5. Copies parameters into new process stack 6. Inserts starting address of new binary program into processor instruction register 22. What are file permissions organized? Answer: Access rights are defined for: Individual owner Group owner Other users Rights include: Read (r) Write (w) Execute (x) 23. What does file cache contain and how is it used? Answer: File cache consists of buffers. Each buffer has: Header with status and pointers Data block It's used for caching read and written data blocks of files. 24. What happens during file open operation? Answer: 1. OS searches for file's i-node following complete path 2. Checks file's access rights 3. Copies i-node to i-node cache if not present 4. Assigns first free row in descriptor table 5. Sets up file table entry 6. Returns file descriptor to process 25. What are the types of shell variables and their differences? Answer: Local variables: Contain information for running shell Can be used in scripts Not accessible in processes started from shell Usually named with small letters Environmental variables: Accessible in processes started from shell Some have standard meaning (HOME, USER, etc.) Usually named with capital letters 26. What is a function in shell and how is it defined? Answer: Function is defined as: name_of_function() { commands } Can be deleted using: unset name_of_function 27. What is condition testing in shell? Answer: Can be done through: Inner test [ condition ] Outer test (program test) Result stored in variable ? 0 if condition satisfied 1 if condition not satisfied 28. What is the purpose of t-bit (sticky bit)? Answer: If set on: Binary program: After program termination, OS won't free all program pages in memory Directory: Users can create new files but can only delete their own files 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 02_Seminar 1_summary Započetí testu Úterý, 6. prosince 2022, 21.47 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.57 Délka pokusu 10 min. 5 sekund Známka 13,87 z možných 15,00 (92,47%) Úloha 1 An operating system (OS) is system software that manages computer hardware, software resources, and Správně provides common services for computer programs. Bodů 1,00 / 1,00 Vyberte jednu z nabízených možností: Pravda ! Nepravda Správná odpověď je 'Pravda' Úloha 2 Unix operating system cannot have graphic user interface, it's just a terminal Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda Nepravda ! Správná odpověď je 'Nepravda' Úloha 3 Most of the servers run unix based operating system Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda ! Nepravda Správná odpověď je 'Pravda' https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 1 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 4 Choose areas where unix based operating systems play a dominant role Částečně správně a. Desktop computers and laptops Bodů 0,89 / 1,00 b. Mobile phones c. Servers! d. IoT! e. Embedded systems! f. Visual effects demanding high performance g. Cloud computing! h. Supercomputers! i. Submarines, Space industry and aviation industry (planes)! j. Control systems! k. Security experts! Vaše odpověď je částečně správná. Vybrali jste správně 8. Správné odpovědi jsou: Servers, IoT, Embedded systems, Visual effects demanding high performance, Cloud computing, Supercomputers, Submarines, Space industry and aviation industry (planes), Control systems, Security experts Úloha 5 Unix based operating systems are NOT usually open source Správně Bodů 1,00 / Vyberte jednu z nabízených možností: 1,00 Pravda Nepravda ! Správná odpověď je 'Nepravda' https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 2 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 6 Tag existing strictly Unix variants: Správně Bodů 1,00 / a. Solaris by Sun Microsystems! 1,00 b. BSD by University of California! c. Xenix by Microsoft! d. HP-UX by Hewlett Packard! e. AIX by IBM! f. Fedora by Red Hat g. Android by Google h. MacOS by Apple Vaše odpověď je správná. Správné odpovědi jsou: Solaris by Sun Microsystems, BSD by University of California, Xenix by Microsoft, HP-UX by Hewlett Packard, AIX by IBM Úloha 7 What programming language was used to develop unix operating system Správně Bodů 1,00 / a. C++ 1,00 b. C! c. R d. Python e. Pascal f. Shell script g. Fortran h. Java Vaše odpověď je správná. Správná odpověď je: C. https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 3 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 8 To what device can we install unix operating system? Správně Bodů 1,00 / a. All of mentioned! 1,00 b. Server c. Desktop computer d. Smartphone e. Embedded device f. Virtual machine Vaše odpověď je správná. Správná odpověď je: All of mentioned. Úloha 9 Assign correctly years and the operating systems Částečně správně Unix OS 1969 ! Bodů 0,71 / 1,00 Linux OS 1981 " Mac OS 2001 ! MS-DOS 1991 " MS Windows 1985 ! Android 2007 ! Symbian 1998 ! Vaše odpověď je částečně správná. Vybrali jste správně 5. Správná odpověď je: Unix OS → 1969, Linux OS → 1991, Mac OS → 2001, MS-DOS → 1981, MS Windows → 1985, Android → 2007, Symbian → 1998. https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 4 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 10 Tag stricltly linux distributions Částečně správně a. Debian! Bodů 0,60 / 1,00 b. Mint c. Ubuntu! d. Fedora e. Red Hat! f. Solaris g. iOS h. CentOS i. PC-DOS j. OpenSUSE! k. ArchLinux! l. Slackware m. Gentoo! n. Xbox OS Vaše odpověď je částečně správná. Vybrali jste správně 6. Správné odpovědi jsou: Debian, Mint, Ubuntu, Fedora, Red Hat, CentOS, OpenSUSE, ArchLinux, Slackware, Gentoo https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 5 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 11 What are the advantages of Unix operating systems? Částečně správně a. Compatibility with a third party software Bodů 0,67 / 1,00 b. Gaming industry c. Security and privacy! d. Open source (free of charge, custom configurations)! e. Package & update management! f. Performance g. Stability & Sustainability! h. Large community support Vaše odpověď je částečně správná. Vybrali jste správně 4. Správné odpovědi jsou: Security and privacy, Open source (free of charge, custom configurations), Package & update management, Performance, Stability & Sustainability, Large community support Úloha 12 What is the command to print a string into standard output (terminal)? Správně Bodů 1,00 / Odpověď: echo ! 1,00 Správná odpověď je: echo Úloha 13 What is the command to see other command's manual page? Správně Bodů 1,00 / Odpověď: man ! 1,00 Správná odpověď je: man https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 6 of 7 02_Seminar 1_summary: Náhled pokusu 06.12.2022 21:58 Úloha 14 What is the command to create a file? Správně Bodů 1,00 / Odpověď: touch ! 1,00 Správná odpověď je: touch Úloha 15 What is the command to print content of the file Správně Bodů 1,00 / a. print 1,00 b. echo c. cat ! d. console.log() e. printf() Vaše odpověď je správná. Správná odpověď je: cat. 03_Seminar 3_summary + ◀ 01_Introduction fun test Přejít na... processes ▶︎ https://moodle.czu.cz/mod/quiz/review.php?attempt=164340&cmid=35887 Page 7 of 7 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 03_Seminar 2_summary Započetí testu Úterý, 6. prosince 2022, 21.31 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.44 Délka pokusu 13 min. 21 sekund Známka 8,80 z možných 9,00 (97,78%) Úloha 1 Choose a command executing an interactive system-monitor process-viewer and process-manager Správně Bodů 1,00 / a. ps -ef 1,00 b. top! c. none of those d. cat /etc/passwd e. ps -aux Vaše odpověď je správná. Správná odpověď je: top. Úloha 2 What is pipeline for? Správně | Bodů 1,00 / 1,00 a. alternation (if the first one ends with an error, the second one is started) b. parallelization (both programs are running simultaneously) c. cooperation (the output of the first program is connected to the input of the second)! d. serialization (the second program is started after the end of the first one) Vaše odpověď je správná. Správná odpověď je: cooperation (the output of the first program is connected to the input of the second). https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 1 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 3 Choose correct statements about C programming in Unix operating systems Správně Bodů 1,00 / a. To run a program, we first have to compile it! 1,00 b. The intstruction to print a string to the standard output is a command echo c. We first have to include line #!/bin/bash d. A compiled program is lacking of execute permission so we have to assign it. Then we run./ e. To work correctly with command line we need to include a library ! f. cc -o a_file b_file.c will create a_file with compiled code! g. The intstruction to print a string to the standard output is a command print h. The file format of programs is.cpp i. The file format of programs is.sh j. A compiled program has already execute permission. We just run./! k. To run a program, we can use syntax./.c l. By returning integer zero we indicate a successful run of the program! m. instructions in C programming does not have to be terminated by ";" n. instruction return 1 is equal to return true o. A default output of cc command is an executable file a.out! p. Main function must have at least one argument q. The file format of programs is.c! r. The intstruction to print a string to the standard output is a command printf! s. cc program.c will compile the file with the same filename t. To use most of C instructions we don't have to include library Vaše odpověď je správná. Správné odpovědi jsou: The file format of programs is.c, To work correctly with command line we need to include a library , The intstruction to print a string to the standard output is a command printf, By returning integer zero we indicate a successful run of the program, To run a program, we first have to compile it, cc -o a_file b_file.c will create a_file with compiled code, A default output of cc command is an executable file a.out, A compiled program has already execute permission. We just run./ https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 2 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 4 Assign correctly commands with their functions Správně Bodů 1,00 / Rename a file mv ! 1,00 Move file to a different folder with different name mv / ! Move file to a different folder mv ! Remove empty directory rmdir ! Remove non-empty directory rm -r ! Remove a file rm ! Vaše odpověď je správná. Správná odpověď je: Rename a file → mv, Move file to a different folder with different name → mv /, Move file to a different folder → mv, Remove empty directory → rmdir, Remove non-empty directory → rm -r, Remove a file → rm. Úloha 5 Following command Správně ls /bin/*[0-9].w? Bodů 1,00 / 1,00 will list all files in /bin directory that: a. begins with any number of any character, includes number 0 or 9 and have format of two character, first one is w b. None of these c. begins with any number of any character, includes any number on last position before file ! format of two character, first one is w d. begins with asterisk, include any number and have format starting with w Vaše odpověď je správná. Správná odpověď je: begins with any number of any character, includes any number on last position before file format of two character, first one is w. https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 3 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 6 A command grep will: Správně Bodů 1,00 / a. Select first "n" lines from the input 1,00 b. Select a column of any order c. Select all lines that includes a pattern given as argument! d. Select all occurance of a pattern given in as argument Vaše odpověď je správná. Správná odpověď je: Select all lines that includes a pattern given as argument. Úloha 7 Assign permissions to the commands correctly. Správně Qeustionmark represents that we don't know the permission. Bodů 1,00 / 1,00 chmod u=rwx rwx-???-??? ! chmod o+w ???-???-?w? ! chmod 644 rw-r--r-- ! chmod 700 rwx------ ! chmod o+w chmod: missing operand after `o-x' ! chmod 341 -wxr----x ! Vaše odpověď je správná. Správná odpověď je: chmod u=rwx → rwx-???-???, chmod o+w → ???-???-?w?, chmod 644 → rw-r--r--, chmod 700 → rwx------, chmod o+w → chmod: missing operand after `o-x', chmod 341 → -wxr----x. https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 4 of 5 03_Seminar 2_summary: Náhled pokusu 06.12.2022 21:44 Úloha 8 Check correct statement about bash scripting: Částečně správně a. first line is #!/bin/bash! Bodů 0,80 / 1,00 b. While creating a script, the owner is given a permission to execute the file c. We can write down any instructions from any known programming language d. script file format is.sh e. Scripts in unix don't allow programming syntaxes such as IF statements or loops f. We can only run programs (commands) that are known in system variable PATH! g. To run a script, we first have to compile it h. script file format is.bash i. To run a script we can use a syntax./.sh! j. While creating a script, we have to assign ourselves a permission to execute the file! k. first line is to import libraries fro standard input and output Vaše odpověď je částečně správná. Vybrali jste správně 4. Správné odpovědi jsou: script file format is.sh , first line is #!/bin/bash, We can only run programs (commands) that are known in system variable PATH, While creating a script, we have to assign ourselves a permission to execute the file, To run a script we can use a syntax./.sh Úloha 9 What of following characters is pipeline? Správně Bodů 1,00 / a. _ 1,00 b. \ c. |! d. > e. / Vaše odpověď je správná. Správná odpověď je: |. ◀ 03_Seminar 3_summary + Přejít na... Example of exam test ▶︎ processes https://moodle.czu.cz/mod/quiz/review.php?attempt=164310&cmid=35889 Page 5 of 5 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Titulní stránka / Kurzy / EIE69E / 04_Tests & Quizes / 03_Seminar 3_summary + processes Započetí testu Úterý, 6. prosince 2022, 21.15 Stav Dokončeno Dokončení testu Úterý, 6. prosince 2022, 21.28 Délka pokusu 13 min. 11 sekund Body 16,00/17,00 Známka 18,82 z možných 20,00 (94,12%) Úloha 1 Assign commands with its functions Správně Bodů 1,00 / Not such command mkfile ! 1,00 Create a file touch ! Change directory cd ! Create a directory mkdir ! Správná odpověď je: Not such command → mkfile, Create a file → touch, Change directory → cd, Create a directory → mkdir. Úloha 2 What is the command to report a snapshot of the current running processes? Správně Bodů 1,00 / Odpověď: ps ! 1,00 Správná odpověď je: ps https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 1 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 3 Assign correctly Správně Bodů 1,00 / interactive process viewer top or htop ! 1,00 report a snapshot of the current processes. ps ! terminate running processes kill ! Správná odpověď je: interactive process viewer → top or htop, report a snapshot of the current processes. → ps, terminate running processes → kill. Úloha 4 "awk" command is for pattern scanning and processing language. Správně Write a command that will print the fifth column of the following text Bodů 1,00 / 1,00 a. awk {'print $5'}! b. awk {print $5} c. awk -d " " -f5 d. awk '{print $5}' e. awk $5 Správná odpověď je: awk {'print $5'}. Úloha 5 Type a command that will only filter lines that don't include number Správně Bodů 1,00 / Odpověď: grep [^0-9] ! 1,00 Správná odpověď je: grep [^0-9] https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 2 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 6 Assign commands correctly Správně Bodů 1,00 / head output the first part of files ! 1,00 grep print lines matching a pattern ! cut remove sections from each line of files ! tail output the last part of files ! sed stream editor for filtering and transforming text ! Správná odpověď je: head → output the first part of files, grep → print lines matching a pattern, cut → remove sections from each line of files, tail → output the last part of files, sed → stream editor for filtering and transforming text. Úloha 7 Using output of command ls as an argument of a command rm would be: Správně Bodů 1,00 / a. rm -ls 1,00 b. ls rm c. rm ls d. ls `rm` e. ls -rm f. rm `ls`! g. ls | rm h. rm rm | ls Správná odpověď je: rm `ls`. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 3 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 8 What is the correct syntax of the for loop in bash? Správně Bodů 1,00 / a. for (variable=; variable < ; variable ++) { ; } 1,00 b. ! for in do done Správná odpověď je: for in do done. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 4 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 9 Assign correctly IF statements Správně Bodů 1,00 / if [ -f 'foo$3' ]; then 1,00 echo "Unix" print "Unix" if 'foo$3' is a regular file ! fi if [ $foo -ge 3 ]; then echo "Unix" print "Unix" if variable foo is greater or equal to 3 ! fi if [ "$test" == "ge 3" ]; then echo "Unix" fi print "Unix" if the content of test variable is a string "ge 3" ! Správná odpověď je: if [ -f 'foo$3' ]; then echo "Unix" fi → print "Unix" if 'foo$3' is a regular file, if [ $foo -ge 3 ]; then echo "Unix" fi → print "Unix" if variable foo is greater or equal to 3, if [ "$test" == "ge 3" ]; then echo "Unix" fi → print "Unix" if the content of test variable is a string "ge 3". Úloha 10 Type a command that will find out how many instances of program sshd are running on the system Správně 1) list all processes using only one neccessarry modifier (standard syntax, not BSD) Bodů 1,00 / 1,00 2) filter lines with string sshd 3) google how to count lines in unix 4) link it to one command that you write down here Odpověď: ps -e | grep sshd | wc -l ! Správná odpověď je: ps -e | grep sshd | wc -l https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 5 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 11 Type ps -f Správně PPID is a parent process ID. Bodů 1,00 / 1,00 From the output we can tell following: a. processes bash and ps -f have the same PID b. processes bash and ps -f have no relationship when it comes to creating processes c. bash is a parent of ps -f process! d. process ps -f is a parent of the running bash Správná odpověď je: bash is a parent of ps -f process. Úloha 12 Write down a command that will list processses owned by a user root. Správně Use minimum of modifiers Bodů 1,00 / 1,00 Odpověď: ps -u root ! Správná odpověď je: ps -u root https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 6 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 13 1) Create c program infi.c Správně Paste following code: Bodů 1,00 / 1,00 #include #include int main () { while(1) {printf("Christmas is coming\n");} return 0; } 2) Compile and run the program For compiling and running program you have to use following: a. cc infi.c./infi.c b. chmod 766 infi.c./infi.c c. chmod 700 infi.c cc infi.c./infi.c cc d. cc infi.c!./a.out Správná odpověď je: cc infi.c./a.out. https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 7 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 14 1) Create c program infi.c Správně Paste following code: Bodů 1,00 / 1,00 #include #include int main () { while(1) {printf("Christmas is coming\n");} return 0; } You have just run the program. Terminate the program and choose what worked: a. CTRL + D b. CTRL + C ! c. kill a.out d. kill "Chritmas is coming" e. CTRL + ALT +DEL Správná odpověď je: CTRL + C. Úloha 15 Remove the string printf("Christmas is coming\n"); Správně Run the endless loop program in the background Bodů 1,00 / 1,00 (google how to run process in background in unix) type the command of running in background correctly assuming the name of compiled program is a.out Odpověď:./a.out & ! Správná odpověď je:./a.out & https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 8 of 9 03_Seminar 3_summary + processes: Náhled pokusu 06.12.2022 21:30 Úloha 16 Terminate the endless loop in background. Správně In order to do that we will: Bodů 1,00 / 1,00 a. find process name using ps aux | grep a.out kill b. Press CTRL + C c. Processes running in background cannot be terminated d. find PID using ps aux | grep a.out! kill Správná odpověď je: find PID using ps aux | grep a.out kill. Úloha 17 Remove string printf("Christmas is coming\n"). Nezodpovězeno Run the program again in the background. Počet bodů z 1,00 Type a command to bring the process in front Odpověď: " Správná odpověď je: fg 1 ◀ 02_Seminar 1_summary Přejít na... 03_Seminar 2_summary ▶︎ https://moodle.czu.cz/mod/quiz/review.php?attempt=164263&cmid=35888 Page 9 of 9 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Home / Courses / EIE69E / 04_Tests & Quizes / Mock Exam Test_2023_Practical part Started on Sunday, 3 December 2023, 12:43 PM State Finished Completed on Sunday, 3 December 2023, 12:45 PM Time taken 2 mins 2 secs Grade 0.00 out of 40.00 (0%) Question 1 Not answered Marked out of 4.00 Find a compressed archive program.tar.gz in directory /exam/example Write down the size of it (in bytes - 80%points, in megabytes - 100% points) Write down only a number, not the unit. Answer: https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 1/6 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Question 2 Not answered Marked out of 4.00 Extract the archive program.tar.gz located in /exam/example into your home directory. Hint: Elegant way - type a command that extracts archive directly into your home directory using option --directory Easy way - copy archive into your home directory. Extract it in the next step. Important option for command tar x... extract z... decompress gzip j... decompress bzip2 J... decompress xz f... file (must be included) --directory... allows to specify directory into which all files are extracted Write down the size of the file program.c (in bytes) Answer: Question 3 Not answered Marked out of 4.00 TASK_NUMBER: 03 Set permission to your home directory to ensure working with extracted file: chmod -R 755 /home/$USER Remove all files except program.c Hint: Elegant solution var.A - use command find, negation can be done with sign ! , option -delete will remove found occurances var.B - use command rm - negation can done with sign ! and placing the expansive expression into brackets () Easy solution create a temporary directory. Move file program.c into that directory. Remove all files in your home directory. Move program.c back into your home directory. Remove the temporary directory. Execute command below and enter the output into Moodle check_03 Answer: https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 2/6 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Question 4 Not answered Marked out of 4.00 Compile and run program program.c After the run you shall see a new file output.txt in your home directory Write down the size of the file in bytes. Answer: Question 5 Not answered Marked out of 4.00 In file output.txt, Number of lines that contains string UOS Number of lines starting with upper case letter Number of lines that contatins string UOS and ends with dot character. Number of lines that contains string papaya or Papaya Question 6 Not answered Marked out of 4.00 There is a running process in the system that was started by following command: /bin/bash tools/never_ending.sh Find the process and write down who ran the process. Answer: https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 3/6 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Question 7 Not answered Marked out of 4.00 TASK_NUMBER: 07 Create a directory bin in your home directory Create a file script.sh in directory ~/bin Ensure execute permission for owner of script.sh Execute command below and write down the output into Moodle check_07 Answer: Question 8 Not answered Marked out of 4.00 TASK_NUMBER: 08 Create a symbolic link named run in your home directory that will be linked to ~/bin/script.sh Execute command below and write down the output into Moodle check_08 Answer: https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 4/6 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Question 9 Not answered Marked out of 4.00 TASK_NUMBER: 09 Copy text below into your file ~/bin/script.sh ------------------------------------------------------------------------ #!/bin/bash # Get the script's own PID SCRIPT_PID=$$ # Export the PID as an environmental variable export SCRIPT_PID while true; do sleep 1 done ------------------------------------------------------------------------ Run the script in background using symbolic link run Execute commnad below and write down the output into Moodle check_09 Answer: Question 10 Not answered Marked out of 4.00 TASK_NUMBER: 10 Terminate process that you ran in the background Execute command below and write down the output into Moodle answer check_10 Answer: https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 5/6 12/3/23, 12:45 PM Mock Exam Test_2023_Practical part: Attempt review Question 11 Not answered Not graded Execute command below and copy the answer into Moodle. history You may also write down notes to your solution. Provided material is not part of evaluation unless your answer is wrong. ◄ 2020-2022_Generated Exam Test Jump to... Unix operating systems ► https://moodle.czu.cz/mod/quiz/review.php?attempt=843144&cmid=352801 6/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU Home / Courses / EIE69E / 04_Tests & Quizes / Mock_exam_theoretical Started on Friday, 5 January 2024, 9:10 AM State Finished Completed on Friday, 5 January 2024, 9:17 AM Time taken 7 mins 1 sec Marks 5.75/8.00 Grade 7.19 out of 10.00 (71.88%) Question 1 Complete Mark 0.75 out of 1.00 i-node Mark the true statements a. The i-node is assigned to a file when it is created b. The i-node stores, among other things, information about the file type, file ownership, and file access rights c. If the file was opened, its i-node records the mode of opening the file and the PID of the process that opened the file d. When a file is opened, the content of its i-node is copied to the i-node cache e. The i-node size is the same for all files and directories Vaše odpověď je částečně správná. You have correctly selected 3. https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 1/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU Question 2 Complete Mark 1.00 out of 1.00 Permissions Assume that you set access rights to rwx rwx r-x with the chmod command and then ran the program. Mark the true statements a. Each newly created file by the program will be executable by each user b. The chmod 775 command will set the permissions as required. c. Even if you're not the owner, you're able to run the program d. The chmod 755 command will set the permissions as required. e. Command chmod rwxrwxr-x will throw an error Vaše odpověď je správná. Question 3 Complete Mark 0.67 out of 1.00 Process states Mark the true statements: a. The process can go from the blocked state to the ready-to-run state or to the running state b. If the internal memory becomes completely full while the process is processing, the process is put into a zombie state c. A process in a zombie state can no longer be classified by the system for further processing d. If the running process uses up the allocated time quantum, the process is suspended and its state changes from the running state to the blocked state e. Processes in the ready-to-run state are processes that are waiting in the queue of the scheduler for processing Vaše odpověď je částečně správná. You have selected too many options. https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 2/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU Question 4 Complete Mark 1.00 out of 1.00 Regular expressions The contents of the line file ~/a is: Praha London Paris Hamburg 27.12005 TIME=14:30 moon sun mars Mark the true statements a. The command grep "^m" ~/a prints on standard output following line: moon sun mars b. The command grep "^m" ~/a prints the word: moon to standard output c. Only the third line of the file ~/a contains an instance of the regular expression ^m d. The command grep "^m" ~/a writes to the end of the file ~/a the line: moon sun mars e. The first and third lines of the file ~/a contain an instance of the regular expression ^m Vaše odpověď je správná. https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 3/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU Question 5 Complete Mark 0.00 out of 1.00 s-bits We have following output while listing details about file prog: $ ls -l prog -rwsrwSrwx 1 uos uos0 Dec 13 08:36 prog Mark the true statements: a. The user's s-bit is set for the prog file, the group's s-bit is not b. Only the individual owner of the file and a user who belongs to a different user group than the individual owner of the prog file have the right to run the prog file c. Both the user s-bit and the group s-bit are set for the prog file d. all users have the right to run to prog file e. t-bit will set the operating system automatically when the file is launched Vaše odpověď je chybná. Question 6 Complete Mark 0.67 out of 1.00 Shell variables Mark the true statements about shell variables: a. Content of variable ? is set by the user b. The value of a local variable can only be found in the shell in which it was defined and in the script that was run from that shell c. Variable ? is a local variable that contains the PID of the shell d. Variable ? is a local variable that contains the exit status of the last command e. The value of a local variable can only be found in the shell in which it was defined Vaše odpověď je částečně správná. You have selected too many options. https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 4/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU Question 7 Complete Mark 0.67 out of 1.00 Signals Mark the true statements about signals a. Signal 2 is sent by the keyboard driver when CTRL+Q is pressed b. There are 32 signals defined in the system c. Signal 2 is sent by the keyboard driver when CTRL+C is pressed d. With the help of signals, the running of the process can be paused and continued. e. The number of signals that processes will use can be set by the superuser after system startup Vaše odpověď je částečně správná. You have correctly selected 2. Question 8 Complete Mark 1.00 out of 1.00 System service fork() Suppose you compiled and ran program below: main() { fork(); fork(); pause() } Mark the true statements a. After the fork() service is called, the kernel creates a copy of the calling process that differs only in the return value of the system call b. The running of the parent and child processes are controlled by instructions in the program c. After processing the program in the system, 2 processes remain in the ready to run state and two processes in the blocked state d. The return value of the system call is: in the parent process the PID of the child process and in the child process the PID of the parent process e. The parent process is immediately blocked after calling fork() and waits for the child process to exit Vaše odpověď je správná. https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 5/6 1/5/24, 9:18 AM Mock_exam_theoretical: Attempt review | Moodle ČZU ◄ Mock exam_practial Jump to... Unix operating systems ► https://moodle.czu.cz/mod/quiz/review.php?attempt=948502&cmid=362271 6/6 Theoretical Questions: Question 1: Question 2: Question 3: Question 4 is missed Question 5: Question 6: Question 7: Unix Practical Tasks: 1 task: Task 2: Task 3: Task 4: Task 5: Task 6: Task 7: Home page / Courses / EIE69E / 04_Tests & Quizzes / Credit_test Starting the test Monday, January 13, 2025, 4:35 PM State Completed Test completion Monday, January 13, 2025, 4:42 PM Trial length 7 minutes 4 seconds Stamp 6.00 out of a possible 10.00 ( 60 %) Comment Unfortunately you have to take the credit test again Task 1 Correctly Points 1.00 / 1.00 To move to a subdirectory data located in current directory you will use the following command: Select one of the options offered: and. cd data b. go to data C. change date d. data E. mv./data The correct answer is: cd data. Task 2 Incorrectly Points 0.00 / 1.00 Suppose you list a directory and get the following output of ls -l. Which of the following commands will delete the folder old_logs? -rw-r--r-- 1 user user 378 Dec 23 10:54 2020-12-22_logs -rw-r--r-- 1 user user 378 Dec 23 10:53 2020-12-23_logs drwxr-xr- x 1 user user 4096 Dec 23 10:52 old_logs Select one of the options offered: and. delete -d old_logs b. rm old_logs C. We cannot remove a directory that is not empty d. rmdir old_logs E. rm -r old_logs Your answer is incorrect. The correct answer is: rm -r old_logs. Task 3 Correctly Points 1.00 / 1.00 Redirect both standard and error output of program prog1 into a file log : Select one of the options offered: and. prog1 2>1 > log b. prog1 >2> log C. prog1 > log >> log d. prog1 2> | log E. prog1 2>&1 > log The correct answer is: prog1 2>&1 > log. Task 4 Incorrectly Points 0.00 / 1.00 Find all lines beginning with a number in file data.txt : Select one of the options offered: and. find -P "[0-9]*" file.txt b. find -P "^\d" file.txt C. grep -P "[0-9]*" file.txt d. ls ^[0-9]* file.txt E. grep -P "^\d" file.txt The correct answer is: grep -P "^\d" file.txt. Task 5 Correctly Points 1.00 / 1.00 Choose the only correct way how to use ls with the option for long (detailed) output : Select one of the options offered: and. ls-l b. Ls-l C. ls -l d. ls-s E. ls -L The correct answer is: ls -l. Task 6 Correctly Points 1.00 / 1.00 What character is used as an escape character so the following character's special meaning is ignored: Select one of the options offered: and. @ b. S ame character as we want to use (eg ** will ignore *) C. ^ d. \ E. / The correct answer is: \. Task 7 Correctly Points 1.00 / 1.00 Create a directory programs in your current working directory: Select one of the options offered: and. mkdir programs b. newdir programs C. md programs d. make dir programs E. touch./programs The correct answer is: mkdir programs. Task 8 Incorrectly Points 0.00 / 1.00 What will be the result of running script.sh displayed below by running a command./script.sh xyz script1.sh: #!/bin/bash if [ $# -gt 1 ] then Many else echo Few fi Select one of the options offered: and. Both words will be printed out to the terminal b. A word "Few" will be printed out to the terminal C. A string "xyz" will be printed out to the terminal d. A word "Many" will be printed out to the terminal E. Script will throw an error The correct answer is: A word “Few” will be printed out to terminal. Task 9 Incorrectly Points 0.00 / 1.00 What are values of $1 and $2 in script.sh after running./script.sh *.txt in a directory displayed below: -rwxr-xr-x 1 user user 76 Jul 22 17:23 script1.sh -rw-rw-r-- 1 user user 16 Jul 22 17:37 data1.txt -rw-rw-r-- 1 user user 9 Jul 22 17:38 data2.txt -rw-rw-r-- 1 user user 25 Jul 23 10:12 data.csv Select one of the options offered: and. $1 = data1.txt data2.txt $2 = b. $1 = *.txt $2 = C. $1 = data1.txt $2 = data2.txt d. $1 = *.txt $2 = data1.txt data2.txt E. $1 = script.sh $2 = "data1.txt data2.txt" The correct answer is: $1 = data1.txt $2 = data2.txt. Task 10 Correctly Points 1.00 / 1.00 What permission type(s) is necessary in order to run a program: Select one of the options offered: and. read b. read AND execute C. execute d. write E. s-bit The correct answer is: execute. ← Examples to practice Go to... Testing Center →