User Tools

Site Tools


os_cp:exercises-shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

os_cp:exercises-shell [2024/04/04 00:49] (current)
jkonczak utworzono
Line 1: Line 1:
 +In the exercises, one may also provide names of intractive programs (e.g., ''​htop''​ for process management, but if one chooses so, then one has to specify what needs to be done after starting the program in order to solve the exercise.
 +\\
 +For instance, if the exercise states //Provide a command, that will let an already running process called ''​expensiveComputations''​ use only the zeroth CPU core//, then the correct asnwers are, among others:\\
 +//''​taskset -c 0 -p $(pgrep expensiveComputations)''//,​\\
 +or //start ''​htop'',​ look up ''​expensiveComputations''​ with the shortcut ''/'',​ press '​a'​ to change affinity//, \\
 +or even concisely //''​htop'',​ ''/​expensiveComputations'',​ ''​a''//​.
 +
 +To do some of the exercises, one has to create files/​directories mentioned in the exercise.
 +
 +--------------------
 +
 +**~~#~~. Introduction to Unix-like operating systems. Getting help. Browsing filesystem.**
 +
 +~~#.#~~. Using the system manual for ''​bash'',​ provide which switch to the ''​ulimit''​ bash built-in command controls the maximum number of open files.
 +
 +~~#.#~~. Provide what is the page titled ''​random''​ in fourth section of the system manual about.
 +
 +~~#.#~~. One of the manual pages titled ''​signal''​ explains what is the ''​SIGILL''​ signal. Find this fragment and provide the explanation (comment).
 +
 +~~#.#~~. Look up in the system manual for the ''​yt-dlp''​ program an option that extracts only audio from the given link, and provide a command that will download only audio from %%https://​www.youtube.com/​watch?​v=de2Hsvxaf8M%%.
 +
 +~~#.#~~. Provide a command, that will log you SSH sever available at the ''​alt.org''​ address as the user ''​nethack''​.
 +
 +~~#.#~~. Provide a command, that logs you via SSH on the computer named ''​slurm''​ as your current user, without providing the username within the command((You can verify if your command works issuing it from the polluks server)).
 +
 +~~#.#~~. Provide a command, that outputs the current working directory. ​
 +
 +~~#.#~~. Provide a command, that enters the directory ''​db''​ located in the directory ''​var''​ that is directly in the root directory.
 +
 +~~#.#~~. Provide a command, that changes the directory to the ''​Documents''​ directory that is one directory up from your working directory.
 +
 +~~#.#~~. Provide a single command, that displays the contents of ''​.config''​ and ''​.local''​ directories that both are in yout home directory.
 +
 +~~#.#~~. Provide a command, that displays all files (including the hidden files) in the ''/​tmp''​ directory.
 +
 +~~#.#~~. Provide a command, that lists files in the ''/​usr/​lib64/​python/''​ directory so that the size of files are shown.
 +
 +~~#.#~~. Tell what is the size in MB  of the file ''/​usr/​bin/​gdb''​ and provide the command you used to tell that.
 +
 +~~#.#~~. Provide a command, that displays the contents of the ''​elementary school''​ directory which is a subdirectory of the ''​old photos''​ directory (both directories have a space in the name).
 +
 +~~#.#~~. Provide a name of the most recently modified file in the ''/​var/​log''​ directory and provide the command you used to learn that.
 +--------------------
 +
 +**~~#~~. Editing line in console. Console text editors.**
 +
 +~~#.#~~. Copy the file ''/​home/​jkonczak/​so/​old_mcdonald_mistyped.txt''​ elsewhere, and run the ''/​home/​jkonczak/​so/​old_mcdonald_check.sh //​your_new_filename//''​. Correct the spelling mistakes in the file, and provide the output of ''​md5sum < //​your_new_filename//''​ command.
 +--------------------
 +
 +**~~#~~. File operations.**
 +
 +~~#.#~~. Provide a single command that creates a directory ''​2024''​ in a directory ''​data'',​ creating thereby the ''​data''​ directory if it's missing.
 +
 +~~#.#~~. Provide a single command that creates directories ''​moje obrazy''​ and ''​moja muzyka''​.
 +
 +~~#.#~~. Provide a command, that remove an empty directory ''​Downloads''​.
 +
 +~~#.#~~. Provide a command, that creates a (hard) link named ''​commandHistory''​ to the file ''​.bash_history''​.
 +
 +~~#.#~~. Provide a single command that creates a (hard) link to files ''​~/​.config/​mimeapps.list''​ and ''​.config/​htop/​htoprc''​ in your home directory.
 +
 +~~#.#~~. Provide a command, that creates a symbolic link to the file ''/​sys/​devices/​system/​cpu/​cpu0/​cpufreq/​scaling_cur_freq''​ named ''​cpu0_frequency''​ in the current directory.
 +
 +~~#.#~~. Provide a command, that creates a symbolic link named ''​up''​ that points to the parent directory of the current directory. ​
 +
 +~~#.#~~. Provide a command, that copies all files with the ''​.jpg''​ extension form the directory ''​pictures''​ to the directory ''/​tmp/​a''​.
 +
 +~~#.#~~. Provide a command, that copies the directory ''​.local''​ from your home directory alongside with its contents to the desktop((which is usually the directory ''​Desktop''​ in your home directory)) with the name ''​the local files''​.
 +
 +~~#.#~~. Podaj komendę (wykonywaną z katalogu domowego), którą stworzysz kopię pliku ''​.bashrc''​ pod nazwą ''​.bashrc.bak''​ tak, by kopia miała tę samą datę modyfikacji co oryginał.
 +
 +~~#.#~~. Provide a command, that moves all files with the ''​*.txt''​ extension from your home directory to a ''​notes''​ directory.
 +
 +~~#.#~~. Provide a command, that amends the name of the file ''​haunted hose.png''​ to ''​haunted house.png''​.
 +
 +~~#.#~~. Provide a command, that amends the name of the ''​soembdoy''​ directory that is located in the ''/​tmp''​ directory to ''​somebody''​.
 +
 +~~#.#~~. Provide a command, that removes the ''​temporary file''​ file from the ''/​tmp''​ directory.
 +
 +~~#.#~~. Provide a command, that removes all contents from the ''​.cache''​ directory located in your home directory (without removing the directory itself).
 +
 +~~#.#~~. Provide a command, that removes write-protected file ''​readOnly''​ without asking for confirmation.
 +
 +~~#.#~~. Provide a command, that removes all files with the extensions ''​.toc'',​ ''​.nav''​ and ''​.aux''​ in the current directory.
 +
 +~~#.#~~. Provide a command, that removes all files which name starts with ''​try''​ and ends with ''​.c''​ from the directory ''​programming''​.
 +--------------------
 +
 +**~~#~~. Processes.**
 +
 +~~#.#~~. Provide a command, that runs the ''​lsof''​ program and measures its run time.
 +
 +~~#.#~~. Provide the process identifier of your current shell and provide the command you used to learn that.
 +
 +~~#.#~~. Provide the name of the parent process of the process ''​X''​ (''​X''​ is a program that draws '​windows'​ in [[http://​x.org/​|X Window System]]). If you solve the exercises on polluks, look up parent of the ''​pickup''​ process.
 +
 +~~#.#~~. Provide the list of arguments that were passed to the ''​ntpd''​ process running in the system.
 +
 +~~#.#~~. Provide the name of the user that started the ''​rpcbind''​ program.
 +
 +~~#.#~~. Provide the name of the program that uses most space in the main memory with its non-shared files (that is, consider //​__res__ident set size// only). Provide the command you used to learn that.
 +
 +~~#.#~~. Run in another terminal the command ''​sleep 1h'',​ and in yet another ''​sleep 2h''​. Provide a command, that will tell the process identifier of the process sleeping for an hour.
 +
 +~~#.#~~. Run in another terminal the command ''​sleep 1h''​. Provide a command, that will terminate the process from another terminal.
 +
 +~~#.#~~. Run in another terminal the command ''​mkpasswd''​. Provide a command, that will send a ''​FPE''​ signal to the process.
 +
 +~~#.#~~. Run in another terminal the command ''​mkpasswd''​. Provide commands, that will send a ''​HUP''​ signal to the shell in which the ''​mkpasswd''​ process is running.
 +--------------------
 +
 +**~~#~~. Users. File Permissions.**
 +
 +~~#.#~~. Provide a command, that displays your username.
 +
 +~~#.#~~. Provide a command, that displays to which groups the current user belongs.
 +
 +~~#.#~~. Provide a command, that displays to which groups the ''​root''​ user belongs.
 +
 +~~#.#~~. Provide to which user and which group the file ''/​dev/​console''​ belongs and provide the command you used to learn that.
 +
 +~~#.#~~. Provide to which user and which group the ''/​var/​spool/​clientmqueue''​ directory belongs((such directory exists on polluks)) and provide the command you used to learn that.
 +
 +~~#.#~~. Tell and justify whether the user ''​aiXYZ''​ belonging to the group ''​students''​ can display the contents of the file ''/​home/​jkonczak/​so/​obscure/​mooo''​ on polluks.
 +
 +~~#.#~~. Tell and justify whether the user ''​aiXYZ''​ belonging to the group ''​students''​ can display the contents of the file ''/​home/​jkonczak/​so/​obscure/​mooo''​ on polluks((depending on your approach, this may be tricky)).
 +
 +~~#.#~~. Tell and justify whether the user ''​foo''​ belonging to the group ''​staff''​ can display the contents of the directory ''/​home/​jkonczak/​so/​dir''​ on polluks.
 +
 +~~#.#~~. Tell which users can see the contents of the file ''​.bash_history''​ in your home directory.
 +
 +~~#.#~~. Provide a command, that revokes the users that do not belong to your group permission to read the file ''​our secret data.txt''​.
 +
 +~~#.#~~. Provide a command, that forbids access (read, write and execute) to your file ''​~/​public_html/​index.php''​ (belonging to the group ''​students''​) to other students, but does not forbid access to the http server (that does not belong to the grup ''​students''​)((Files that are put in the ''​public_html''​ subdirectory of the home directory of the user //​username//​ are accessible at the URL %%https://​sirius.cs.put.poznan.pl/​~%%//​username//​%%/​%%.)).
 +
 +~~#.#~~. Provide a single command that sets the permissions to the file ''​access_log''​ so that the group can only write to the file, you can only read it, and the remaining users have no access to the file.
 +
 +~~#.#~~. Provide a command, that changes the permissions to the ''/​tmp/​myDir''​ directory so that the users apart from you can display the file ''/​tmp/​myDir/​pub.txt'',​ but cannot list the files in the ''/​tmp/​myDir''​ directory.
 +
 +~~#.#~~. Provide a command, that lets the user ''​jkonczak''​ belonging to the groups ''​staff''​ and ''​lindev''​ read and execute the ''​exercise.sh''​ file in your home directory on polluks, but forbids the user ''​ai11111''​ belonging to the group ''​students''​ reading the file.
 +
 +~~#.#~~. Tell when the contents of the file ''/​etc/​sudoers''​ has been modified most recently.
 +
 +~~#.#~~. Tell when the metadata of the file ''/​etc/​sudoers''​ have been modified most recently.
 +
 +~~#.#~~. Tell when the file ''/​var/​log/​wtmp''​ has been created((the exercise is doable if the filesystem records file birth dates; it is the case on polluks)).
 +
 +~~#.#~~. Provide a command, that changes the date od th last modification of the file ''​treaty''​ to ''​1992-2-7 11:​55''​
 +
 +--------------------
 +
 +**~~#~~. Searching for files.**
 +
 +~~#.#~~. Provide a command, that searches for all files that contain the word ''​plasma''​ in your home directory.
 +
 +~~#.#~~. Provide a command, that searches for all directories which contain their name the string ''​qt'',​ ignoring the letter case.
 +
 +~~#.#~~. Provide a command, that searches for all ordinary files that end with ''​.jpg''​ or ''​.jpeg''​ in the directories ''​Downloads''​ and ''​Dekstop''​ in your home directory.
 +
 +~~#.#~~. Provide a command, that searches for all files with size greater than 1MB that were modified within last week.
 +
 +--------------------
 +
 +**~~#~~. Redirections.**
 +
 +~~#.#~~. Provide a command, that executes and measures the run time of ''​lsof''​ command and puts the result of ''​lsof''​ in a file ''​lsof.log''​
 +
 +~~#.#~~. Provide a command, that appends the current date to the file ''​lsof.log''​.
 +
 +~~#.#~~. Provide a command, that displays the contents of the file ''/​etc/​protocols''​ prepended with line numbers.
 +
 +~~#.#~~. Provide commands that, by means of redirections,​ create a file named ''​1''​ with numbers from 1 to 5 (each in separate line), and file ''​5''​ with numbers starting from 5, incremented by 5, up to 25 (each in separate line).
 +
 +~~#.#~~. Provide a command, that displays the contents of the files created in the previous exercise side by side.
 +
 +~~#.#~~. Provide a single command, that displays the contents of the files created in the previous exercise one after another.
 +
 +~~#.#~~. Provide a command, that created a file ''​message''​ containing the text ''​Premission denined''​ using redirections.
 +
 +~~#.#~~. Provide a command, that executes the command ''​find /​var''​ and discards the error messages.
 +
 +~~#.#~~. Provide a command that will execute the command ''​strace -e '​openat'​ ls ~''​ so that the result of the ''​ls''​ command ends up in the ''​ls.out''​ file, and the (output to standard error) messages of the ''​strace''​ program end up in the ''​ls.strace''​ file. 
 +
 +~~#.#~~. Provide a command, that runs in the background the program ''​glxgears''​ and discards all its output.
 +
 +~~#.#~~. Provide a command, that runs ''​wc''​ replacing its stadard output with the file ''/​etc/​resolv.conf''​.
 +
 +~~#.#~~. Provide a command, that tuns ''​bc''​ and passes to the standard input of that program the tow following lines: ''​(4^4)^4''​ and ''​4^(4^4)''​.
 +
 +--------------------
 +
 +**~~#~~. Pipes. Filters.**
 +
 +~~#.#~~. The file ''/​proc/​cpuinfo''​ contains information about CPUs.
 +Provide a pipeline that displays the clock speed of each CPU (all values ​​in MHz).
 +<​small>​ \\ Example command output:<​code>​
 +800.000
 +3345.481
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that tells which combinations of access permission
 +appear in the ''/​etc/''​ directory and how many times each of these combinations
 +is present there.
 +<​small>​ \\ Example command output:<​code>​
 +       2 rw-r-----
 +     102 rw-r--r--
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that looks up in the English dictionary (''/​usr/​share/​myspell/​en_GB.dic''​)
 +eight-character words ending with ''​less''​.
 +<​small>​ \\ Example command output:<​code>​
 +careless
 +Erchless
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that looks up in the English dictionary (''/​usr/​share/​myspell/​en_GB.dic''​)
 +words ending with ''​more''​ and starting with a lowercase letter.
 +<​small>​ \\ Example command output:<​code>​
 +claymore
 +evermore
 +
 +</​code></​small>​
 +
 +~~#.#~~. The ''/​dev/​urandom''​ file is a random data generator.
 +Provide a pipeline that, by filtering the file, displays a random 32-digit hexadecimal number.
 +<​small>​ \\ Example command output:<​code>​
 +05f5a888fe12ae981539adf3de9f3762
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that, by using ''/​dev/​urandom'',​ generates a list of
 +10 passwords, each 8 characters long, composed of lowercase letters and an underscore.
 +<​small>​ \\ Example command output:<​code>​
 +qtoemmiy
 +rjcpu_cl
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that, counts how many ''​bash''​ processes are currently running (for all users).
 +<​small>​ \\ Example command output:<​code>​
 +8
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that outputs a list the 5 most frequently issued
 +commands with arguments from the shell history.
 +<​small>​ \\ Example command output:<​code>​
 +       5 make
 +       5 rm -rf *
 +       9 cd ..
 +      14 ./9
 +      48 ls
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that outputs a list of the 5 most common file extensions in the /var/log/ directory.
 +Skip files without extension.
 +Consider all following the first dot as an extension.
 +<​small>​ \\ Example command output:<​code>​
 +      15 log
 +       5 gz
 +       2 log-20200927
 +       2 log-20200501.gz
 +       2 log-20200401.gz
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that outputs a list of the 5 most common file extensions in the /var/log/ directory.
 +Skip files without extension.
 +Consider all following the last dot as an extension.
 +<​small>​ \\ Example command output:<​code>​
 +      18 log
 +      16 gz
 +       3 old
 +       2 log-20200927
 +       1 wtmp
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that outputs a list of the three users with the most processes running.
 +Skip the root user.
 +<​small>​ \\ Example command output:<​code>​
 +     163 user
 +       7 distcc
 +       2 sddm
 +</​code></​small>​
 +
 +~~#.#~~. Provide a command that finds out which header file in the directory ''/​usr/​include/''​ contains the
 +declaration of the function ''​SHA512_Init''​ declaration .
 +
 +~~#.#~~. Provide a pipeline that counts how many ''#''​ characters are in the file found in the previous exercise.
 +<​small>​ \\ Example command output:<​code>​
 +36
 +</​code></​small>​
 +
 +~~#.#~~. Provide a command that displays the file from the previous exercise, skipping lines starting with '#'​.
 +
 +~~#.#~~. The ''/​etc/​services''​ file contains known port names for the transport layer protocols.
 +Provide a command that outputs the names of the protocols that have any named ports (the second column).
 +<​small>​ \\ Example command output:<​code>​
 +udp
 +tcp
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that displays the number of hidden files and directories in your home directory.
 +<​small>​ \\ Example command output:<​code>​
 +172
 +</​code></​small>​
 +
 +~~#.#~~. The 'ip --statistics link show br0' command displays
 +the number of bytes and packets sent and received by the network card.
 +Provide a pipeline that will display only the number of bytes sent and received (in separate lines).
 +<​small>​ \\ Example command output:<​code>​
 +1345718968
 +686011084
 +</​code></​small>​
 +
 +~~#.#~~. Provide the five process IDs in the system that have the largest number child processes.
 +Provide a pipeline that you used to learn this.
 +<​small>​ \\ Example command output:<​code>​
 +2
 +1
 +4120
 +3912
 +4108
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that tells how many users present in the ''/​etc/​passwd''​ file
 +use the ''​bash''​ shell.
 +<​small>​ \\ Example command output:<​code>​
 +13
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that outputs the names of files ending with ''​.h''​ that are
 +included from any of the files in the ''/​usr/​include/​infiniband/''​ directory.
 +<​small>​ \\ Example command output:<​code>​
 +arpa/inet.h
 +byteswap.h
 +emmintrin.h
 +
 +</​code></​small>​
 +
 +~~#.#~~. Provide a pipeline that filters the output of 'ping -i 0.5 -c 10 put.poznan.pl',​ to display only the rtt times themselves.
 +answers.
 +<​small>​ \\ Sample command output:<​code>​
 +1.20
 +0.654
 +
 +0.776
 +0.760
 +</​code></​small>​
 +
 +--------------------
 +
 +**~~#~~. Scripting - basics.**
 +
 +~~#.#~~. Provide the first line of an ordinary shell script that tells the operating system to interpret the file with ''/​bin/​sh''​ program.
 +
 +~~#.#~~. The file ''​setup''​ contains commands that initialize certain shell variables. Provide a command that executes the contents of this file in current shell so that the variables become available.
 +
 +~~#.#~~. Provide a command that calculates md5sum of the combined output of the command ''​lsusb''​ and the output of the command ''​date +%D''​.
 +
 +~~#.#~~. Provide a command that redirects the combined output of the commands ''​date''​ and ''​lsof''​ to a file ''​lsof.latest.log''​.
 +
 +~~#.#~~. Provide a fragment of the script that creates a directory ''​results''​ and exits id creating the directory failed. You must not use ''​if''​ statement or any loop.
 +
 +--------------------
 +
 +**~~#~~. Job control.**
 +
 +~~#.#~~. Provide a keyboard shortcut that will normally interrupt and end the foreground process.
 +
 +~~#.#~~. Provide a keyboard shortcut that will normally stop (i.e. put to sleep) the foreground process.
 +
 +~~#.#~~. Run the ''​xterm''​ program from the terminal. Stop the program with the appropriate shortcut. Provide a command that will resume the xterm process in background (i.e. so that you can continue to use both the current terminal and the xterm program).
 +
 +~~#.#~~. Provide a command, that runs the command ''​perl -e "​system'​fortune'​while sleep 5"''​ in background.
 +
 +~~#.#~~. Provide a command, that moves the process running in background to foreground.
 +
 +~~#.#~~. Start ''​mkpasswd''​ in background first, and then start ''​sleep 50''​ in background. Provide a command that resumes the ''​mkpasswd''​ as a foreground process.
 +
 +~~#.#~~. Provide a command, that lists the processes running in background in the current shell.
 +
 +--------------------
 +
 +**~~#​~~. ​ Environment variables.**
 +
 +~~#.#~~. Provide a command, that sets the variable ''​TEXT''​ to the value ''​That'​s "​the"​ value''​ (with all quotes intact).
 +
 +~~#.#~~. Provide a command, that sets the variable ''​FOO''​ to the value ''​baz''​ so that programs run in this shell see the value of ''​FOO''​. (You can verify this by running the ''​perl -e 'print "​Correct!\n"​ if $ENV{"​FOO"​} == "​baz"'​%%%%''​ command).
 +
 +~~#.#~~. Provide a command that lists all currently set variables.
 +
 +~~#.#~~. Provide a fragment of shell script that checks if there are four arguments, and if not, then prints an error message and quits the script.
 +
 +~~#.#~~. Provide a fragment of shell script that checks if the first argument names an existing file and the second argument names an existing directory, and if not, then prints an error message and quits the script.
 +
 +~~#.#~~. Provide a fragment of shell script that checks if the second argument is greater than the second argument, and if not, then prints an error message and quits the script.
 +
 +~~#.#~~. Provide a fragment of shell script that assigns to variable ''​DEST''​ the value of the second arguments if at least two arguments were provided, and ''​./​destination/''​ otherwise.
 +
 +~~#.#~~. Provide a fragment of shell script that calls a program ''​cat''​ with argument ''​-nv''​ and full list of arguments of this script. <​small>​(That is, if the script was run as ''​./​script foo "baz bar"'',​ then the fragment shall call ''​cat -nv foo "baz bar"''​.)</​small>​
 +
 +--------------------
 +
 +**~~#~~. Command substitution and arithmetic expansion.**
 +
 +~~#.#~~. Provide a command that outputs ''​There are //N// files in your home directory''​ with ''//​N//''​ being replaced with the actual number.
 +
 +~~#.#~~. Provide a script that creates if necessary and opens in the default editor the file ''​notes_//​DATE//​.txt'',​ where ''//​DATE//''​ is replaced by the current date (e.g., as output by ''​date +%m_%d''​).
 +
 +
 +~~#.#~~. The ''​truncate --size //N// //​f//''​ command resizes (creating if necessary) to //N// byte the file //f//. Provide a command that resizes the file ''​3m2k1b''​ to a size of 3MB+2kB+1B (that is, 3*1024*1024+2*1024+1).
 +
 +~~#.#~~. Provide a single command that outputs a random number greater or equal 100 and lesser than 1000. Use the ''​RANDOM''​ environment variable.
 +
 +--------------------
 +
 +**~~#~~. Reading input from user.**
 +
 +~~#.#~~. Write a shell script that reads two numbers from standard input and outputs their sum and product.
 +
 +~~#.#~~. Write a fragment of a shell script that reads first name and last name from standard input until both are provided, outputting diagnostic messages if the user did not provide one of the names.
 +
 +--------------------
 +
 +**~~#~~. Control flow statements.**
 +
 +~~#.#~~. Provide commands that write for every file with the <​tt>​.rc</​tt>​ extension in the <​tt>/​etc</​tt>​ directory its name or path followed by its first and last line.
 +
 +~~#.#~~. Provide a shell script that requires two arguments, and draws a rectangle of given width and height.
 +\\
 +<​small>​ Example output of ''​./​script.sh 15 4'':<​code>​
 +##############​
 +#            #
 +#            #
 +##############​
 +</​code>​
 +</​small>​
 +
 +~~#.#~~. Provide a shell script that assumes that each its argument is a file name. For each file, the script shall count the number of lines beginning with ''#''​ in each file. If there are no such lines, the script shall output ''​No comments in //​filename//'',​ and shall output ''​There are //N// comments in //​filename//''​.
 +
 +~~#.#~~. Provide a shell script that accepts a single argument being a directory name. The script goes through each file in the directory, and checks its mime type (with the command ''​file --mime-type --brief //​filename//''​). If the mime type starts with ''​image'',​ the scripts displays the file name and its size.
 +
 +~~#.#~~. Provide a shell script that repeatedly checks if the file ''​log''​ exists, and as soon as the file appears, calls ''​tail -f log''​.
 +
 +~~#.#~~. Provide a shell script that acts as a timer. The script shall accept one argument, the number of seconds. The script shall output ''//​M//​ minutes and //N// seconds remaining''​ every second, and shall call ''​xmessage expired''​ when the time runs out.
 +
 +~~#.#~~. Provide shell commands that output all powers of two that are smaller than the value of the process identifier of the current shell.
 +\\
 +<​small>​ Example output:<​code>​
 +0 1
 +1 2
 +2 4
 +3 8
 +4 16
 +...
 +</​code>​
 +</​small>​
 +
 +~~#.#~~. Provide shell commands (that include a loop) that check if the files
 +''​log.0'',​ ''​log.1'',​ ''​log.2'',​ ... exist.
 +Upon the first filename ''​log.//​i//''​ that refers to a non-existent file, the
 +loop shall finish and that name shall be assigned to a variable ''​LOGFILE''​.
 +
 +
 +~~#.#~~. Provide a shell function named ''​maketar''​ that, when run as ''​maketar //​foo//'',​ will execute ''​tar cf //foo//.tar //​foo//''​.
 +
 +~~#.#~~. Provide a shell function named ''​systemStatus''​ that displays current date, runs ''​uptime''​ and ''​free -m'',​ and outputs two empty lines.
 +
 +~~#.#~~. Provide a command that will cause the shell to generate a random fortune whenever the user presses Ctrl+c
 +
 +~~#.#~~. Provide a fragment of a shell script that will remove file ''​tmpfile''​ whenever the script terminates.
 +
 +
 +
 +~~META:
 +language = en
 +~~
  
os_cp/exercises-shell.txt · Last modified: 2024/04/04 00:49 by jkonczak