Ticked _compressed Past Paper PDF
Document Details
Tags
Summary
This document contains practice questions and answers related to Linux and Unix commands, mainly focused on shell scripting and file manipulation. The questions cover topics such as file handling, directory operations, process management, and other common commands within Linux and Unix shells. The questions themselves contain code snippets for testing command knowledge.
Full Transcript
## Technical Foundation for - ### 30. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 29. Shell Program - What will be the output of the below code when `str = programming` and `c = g`...
## Technical Foundation for - ### 30. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 29. Shell Program - What will be the output of the below code when `str = programming` and `c = g`? ```bash read -p "Enter a string (str): " str read -p "Enter a character (c): " c len=$(echo "$str" | wc -c) len=$(expr $len - 1) x=1 while [ $x -le $len ] do a=$(echo "$str" | cut -c $x) if [ "$a" == "$c" ]; then echo $x fi x=$(expr $x + 1) done ``` - 4 ### 28. Scripting - What will the below given code do? ```bash #!/bin/sh if [ $1 ] then while read folder do files=$(ls $folder | wc -l) if [ $files -eq 0 ] then rmdir $folder fi done fi ``` - Takes a name of a folder, and delete all sub folders of size 0. ### 27. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "$(counter)" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 26. Unix Scripts - What will be the output of the below code when `p = 12` and `q = 14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 25. Linux: Example - Which command is used to display the number of words in the file named `example.txt`? - `wc -w example.txt` ### 24. Linux: Following - What is the output of the following command? `find /-type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 23. Linux: Permissions - What command is used to change the permissions of a file or directory in Linux? - `chmod` ### 22. Linux: Open Files - Which of the following commands is used for setting the maximum number of open files in the system? - `ulimit -n` ### 21. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 21. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 22. Statement - What is true about the below `ls -il` listing? ``` 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt 145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt 268394 -rw-rw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt ``` - There is one physical file with 2 hard links. ### 23. Linux: Permissions - What command is used to change the permissions of a file or directory in Linux? - `chmod` ### 24. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 25. Linux: Following - What is the output of the following command? `find /-type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 26. Linux: Directory - What is the output of the following command? `grep -r "Hello" /path/to/directory` - Displays all the files containing the string "Hello". ### 27. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 1. Linux: Purpose - What is the purpose of the command `chmod 777 file.txt`? - Gives all users full read/write/execute permissions to the file. ### 4. To/Backup/ Directory - Which command will copy all `.jpg` files from the current directory to `/backup/` directory? - `find . -iname "*.jpg" | xargs -i cp {} /backup/` ### 6. Linux: Remove - What command is used to remove a directory and its contents in Linux? - `rm -r` ### 8. In Current Directory - Which command will generate an archive of all files in the current directory? - `cpio -ov archive.cpio` ### 12. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello" ### 15. EGREP Command - Which statement is true for `egrep` command with option `-n`? - Prefix each line of output with the line number within its input file. ### 10. Statement - What is true about the below `ls -il` listing? ``` 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt 145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt 268394 -rw-rw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt ``` - There is one physical file with 2 hard links. ### 7. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 9. Linux: Directories - What command is used to list all files and directories in the current directory in Linux? - `ls` ### 11. Unix: Output - What is the output of the following command: `grep -oE '([0-9]+-)+' file.txt`? - All the hyphen-separated numbers are in `file.txt`. ### 13. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "${counter}" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 14. Linux: Awk - What is the output of the following command? `awk '{print $1}' file.txt | sort -n` - The line count of `file.txt` ### 3. Linux: Following - What is the output of the following command? `find / -type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 5. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 11. Unix: Output - What is the output of the following command: `grep -OE '([0-9]+-)+' file.txt`? - All the hyphen-separated numbers are in `file.txt`. ### 13. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "${counter}" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 1. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 2. Unix Scripts - What will be the output of the below code when `p = 12` and `q = 14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 15. EGREP Command - Which statement is true for `egrep` command with option `-n`? - Prefix each line output with the line number within its input file. ### 28. Linux: Name - What is the output of the following command: `echo $awk`? - `awk` ### 27. Unix Scripts - What will be the output of the below code when `p=12` and `q=14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 4. To/Backup/ Directory - Which command will copy all `.jpg` files from the current directory to `/backup/` directory? - `find . -iname "*.jpg" | xargs -i cp {} /backup/` ### 6. Linux: Remove - What command is used to remove a directory and its contents in Linux? - `rm -r` ### 8. In Current Directory - Which command will generate an archive of all files in the current directory? - `cpio -ov archive.cpio` ### 12. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello". ### 7. Delta Echo Foxtrot - What will be the output of following command: `$ echo "The process id is" \(\$\$\$\$\)`? - The process id is ### 10. Linux: Device - What is the purpose of the `/dev/null` device file in Linux? - To discard any data written to it. ### 9. Kill the Process - Which command kill the process but allows the process to "clean up" before exiting? - `kill -TERM [pid]` ### 8. File Contains - The files `/var/run/utmp` and `/var/log/wtmp` contains which of the following? - Logs for users logins and logouts ### 17. UNIX: Complex File - How would you change the permissions of `file.txt` to be read-only for the user, and not accessible by group and others? - `chmod 400 file.txt` ### 9. Data Linux - How many data streams does every linux command line program have? - 3 ### 15. UNIX: Advanced File - In a UNIX shell script, which command sequence creates a new file named `data.txt` and writes `Hello, World` into it? - `echo "Hello, World" > data.txt` ### 17. UNIX: Complex File - How would you change the permissions of `file.txt` to be just read-only for the user, and not accessible by the group and others? - `chmod 400 file.txt` ### 21. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 22 Statement - What is true about the below `ls -il` listing? ``` 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt 145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt 268394 -rw-rw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt ``` - There is one physical file with 2 hard links. ### 23. Linux: Permissions - What command is used to change the permissions of a file or directory in Linux? - `chmod` ### 24. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 25. Linux: Following - What is the output of the following command? `find /-type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 26. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello" ### 27. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 28. Linux: Name - What is the output of the following command: `echo $awk`? - `awk` ### 29. Shell Program - What will be the output of the below code when `str = programming` and `c = g`? ```bash read -p "Enter a string (str): " str read -p "Enter a character (c): " c len=$(echo "$str" | wc -c) len=$(expr $len - 1) x=1 while [ $x -le $len ] do a=$(echo "$str" | cut -c $x) if [ "$a" == "$c" ]; then echo $x fi x=$(expr $x + 1) done ``` - 4 ### 30. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 1. Linux: Purpose - What is the purpose of the command `chmod 777 file.txt`? - Gives all users full read/write/execute permissions to the file. ### 2. Unix Scripts: - What will be the output of the below code when `p = 12` and `q = 14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 3. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 4. To/Backup/ Directory - Which command will copy all `.jpg` files from the current directory to `/backup/` directory? - `find . -iname "*.jpg" | xargs -i cp {} /backup/` ### 5. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 6. Linux: Remove - What command is used to remove a directory and its contents in Linux? - `rm -r` ### 7. Delta Echo Foxtrot - What will be the output of following command: `$ echo "The process id is" \(\$\$\$\$\)`? - The process id is ### 8. In Current Directory - Which command will generate an archive of all files in the current directory? - `cpio -ov archive.cpio` ### 9. Linux: Directories - What command is used to list all files and directories in the current directory in Linux? - `ls` ### 10. Linux: Device - What is the purpose of the `/dev/null` device file in Linux? - To discard any data written to it. ### 11. Unix: Output - What is the output of the following command: `grep -OE '([0-9]+-)+' file.txt`? - All the hyphen-separated numbers are in `file.txt`. ### 12. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello" ### 13. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "${counter}" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 14. Linux: Awk - What is the output of the following command? `awk '{print $1}' file.txt | sort -n` - The line count of `file.txt` ### 15. EGREP Command - Which statement is true for `egrep` command with option `-n`? - Prefix each line output with the line number within its input file. ### 16. UNIX: File Manipulation - In UNIX, what is the primary use of the `grep` command? - To search text in files. ### 17. UNIX: Complex File - How would you change the permissions of `file.txt` to be read-only for the user, and not accessible by group and others? - `chmod 400 file.txt` ### 18. Linux: Following - What is the output of the following command? `find / -type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 19. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 20. Statement - What is true about the below `ls -il` listing? ``` 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt 145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt 268394 -rw-rw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt ``` - There is one physical file with 2 hard links. ### 21. Linux: Permissions - What command is used to change the permissions of a file or directory in Linux? - `chmod` ### 22. Linux: Open Files - Which of the following commands is used for setting the maximum number of open files in the system? - `ulimit -n` ### 23. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 24. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 25. Linux: Following - What is the output of the following command? `find /-type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 26. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello". ### 27. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 28. Linux: Name - What is the output of the following command: `echo $awk`? - `awk` ### 29. Shell Program - What will be the output of the below code when `str = programming` and `c = g`? ```bash read -p "Enter a string (str): " str read -p "Enter a character (c): " c len=$(echo "$str" | wc -c) len=$(expr $len - 1) x=1 while [ $x -le $len ] do a=$(echo "$str" | cut -c $x) if [ "$a" == "$c" ]; then echo $x fi x=$(expr $x + 1) done ``` - 4 ### 30. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 1. Linux: Purpose - What is the purpose of the command `chmod 777 file.txt`? - Gives all users full read/write/execute permissions to the file. ### 2. Unix Scripts: - What will be the output of the below code when `p = 12` and `q = 14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 3. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 4. To/Backup/ Directory - Which command will copy all `.jpg` files from the current directory to `/backup/` directory? - `find . -iname "*.jpg" | xargs -i cp {} /backup/` ### 5. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 6. Linux: Remove - What command is used to remove a directory and its contents in Linux? - `rm -r` ### 7. Delta Echo Foxtrot - What will be the output of following command: `$ echo "The process id is" \(\$\$\$\$\)`? - The process id is ### 8. In Current Directory - Which command will generate an archive of all files in the current directory? - `cpio -ov archive.cpio` ### 9. Linux: Directories - What command is used to list all files and directories in the current directory in Linux? - `ls` ### 10. Linux: Device - What is the purpose of the `/dev/null` device file in Linux? - To discard any data written to it. ### 11. Unix: Output - What is the output of the following command: `grep -OE '([0-9]+-)+' file.txt`? - All the hyphen-separated numbers are in `file.txt`. ### 12. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello" ### 13. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "${counter}" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 14. Linux: Awk - What is the output of the following command? `awk '{print $1}' file.txt | sort -n` - The line count of `file.txt` ### 15. EGREP Command - Which statement is true for `egrep` command with option `-n`? - Prefix each line output with the line number within its input file. ### 16. UNIX: File Manipulation - In UNIX, what is the primary use of the `grep` command? - To search text in files. ### 17. UNIX: Complex File - How would you change the permissions of `file.txt` to be read-only for the user, and not accessible by group and others? - `chmod 400 file.txt` ### 18. Linux: Following - What is the output of the following command? `find / -type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 19. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 20. Statement - What is true about the below `ls -il` listing? ``` 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt 145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt 268394 -rw-rw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt 619880 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt ``` - There is one physical file with 2 hard links. ### 21. Linux: Permissions - What command is used to change the permissions of a file or directory in Linux? - `chmod` ### 22. Linux: Open Files - Which of the following commands is used for setting the maximum number of open files in the system? - `ulimit -n` ### 23. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 24. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 25. Linux: Following - What is the output of the following command? `find / -type f -name "*.txt" -size +5M -user root 2>/dev/null` - List of all files with .txt extension, size greater than 5MB and owned by root user in the root directory and sub-directories ### 26. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello". ### 27. Linux: Owner - Which command can be used to create a new file with read-write permissions for the owner only, named `newfile.txt` in the current directory? - `touch newfile.txt; chmod 600 newfile.txt` ### 28. Linux: Name - What is the output of the following command: `echo $awk`? - `awk` ### 29. Shell Program - What will be the output of the below code when `str = programming` and `c = g`? ```bash read -p "Enter a string (str): " str read -p "Enter a character (c): " c len=$(echo "$str" | wc -c) len=$(expr $len - 1) x=1 while [ $x -le $len ] do a=$(echo "$str" | cut -c $x) if [ "$a" == "$c" ]; then echo $x fi x=$(expr $x + 1) done ``` - 4 ### 30. Linux: Null - What is the output of the following command: `pthread_cond_init(&my_cond, NULL);` - Initializes a new condition variable named `my_cond`. ### 1. Linux: Purpose - What is the purpose of the command `chmod 777 file.txt`? - Gives all users full read/write/execute permissions to the file. ### 2. Unix Scripts: - What will be the output of the below code when `p = 12` and `q = 14`? ```bash read p read q x='expr $p + $q' echo $x ``` - 26 ### 3. Linux: Head - What does the command `ls -1 | head -n +5` do? - Lists the first 5 files in the current directory, displaying details including file permissions and ownership. ### 4. To/Backup/ Directory - Which command will copy all `.jpg` files from the current directory to `/backup/` directory? - `find . -iname "*.jpg" | xargs -i cp {} /backup/` ### 5. Linux: Directory - Which of the following is the root directory of a Linux system? - `/` ### 6. Linux: Remove - What command is used to remove a directory and its contents in Linux? - `rm -r` ### 7. Delta Echo Foxtrot - What will be the output of following command: `$ echo "The process id is" \(\$\$\$\$\)`? - The process id is ### 8. In Current Directory - Which command will generate an archive of all files in the current directory? - `cpio -ov archive.cpio` ### 9. Linux: Directories - What command is used to list all files and directories in the current directory in Linux? - `ls` ### 10. Linux: Device - What is the purpose of the `/dev/null` device file in Linux? - To discard any data written to it. ### 11. Unix: Output - What is the output of the following command: `grep -OE '([0-9]+-)+' file.txt`? - All the hyphen-separated numbers are in `file.txt`. ### 12. Linux: Directory - What is the output of the following command: `grep -r "Hello" /path/to/directory`? - Displays all the files containing the string "Hello". ### 13. Linux: Shared - What is the output of the following command? ```bash declare -i shared_var=0 declare -i num_threads=4 declare -i counter=0 Increment() { while true do if [[ "${counter}" -ge 100000 ]]; then break fi shared_var=$((shared_var + 1)) counter=$((counter + 1)) done } main() { for ((i=0; i<num_threads; i++)) do increment & done wait echo "Shared variable: ${shared_var}" } main ``` - Shared variable: 400000 ### 14. Linux: Awk - What is the output of the following command? `awk '{print $1}' file.txt | sort -n` -