layouts half of the linux fun ex
This commit is contained in:
parent
9f964c757b
commit
50dcad0a9b
|
@ -4,78 +4,81 @@
|
|||
|
||||
## 12.9. practice: commands and arguments
|
||||
|
||||
1. How many arguments are in this line (not counting the command itself). touch '/etc/cron/cron.allow' 'file 42.txt' "file 33.txt"
|
||||
2. Is tac a shell builtin command ?
|
||||
3. Is there an existing alias for rm ?
|
||||
4. Read the man page of rm, make sure you understand the -i option of rm. Create and remove a file to test the -i option.
|
||||
5. Execute: alias rm='rm -i' . Test your alias with a test file. Does this work as expected ?
|
||||
6. List all current aliases.
|
||||
7a. Create an alias called 'city' that echoes your hometown.
|
||||
7b. Use your alias to test that it works.
|
||||
8. Execute set -x to display shell expansion for every command.
|
||||
9. Test the functionality of set -x by executing your city and rm aliases.
|
||||
10 Execute set +x to stop displaying shell expansion.
|
||||
11. Remove your city alias.
|
||||
12. What is the location of the cat and the passwd commands ?
|
||||
1. How many arguments are in this line (not counting the command itself). `touch '/etc/cron/cron.allow' 'file 42.txt' "file 33.txt"`
|
||||
2. Is `tac` a shell builtin command ?
|
||||
3. Is there an existing alias for `rm`?
|
||||
4. Read the man page of `rm`, make sure you understand the `-i` option of rm. Create and remove a file to test the -i option.
|
||||
5. Execute: `alias rm='rm -i'` . Test your alias with a test file. Does this work as expected?
|
||||
6. List all current aliases.
|
||||
7a. Create an alias called `city` that echoes your hometown.
|
||||
7b. Use your alias to test that it works.
|
||||
8. Execute `set -x` to display shell expansion for every command.
|
||||
9. Test the functionality of `set -x` by executing your city and rm aliases.
|
||||
10 Execute `set +x` to stop displaying shell expansion.
|
||||
11. Remove your city alias.
|
||||
12. What is the location of the `cat` and the `passwd` commands?
|
||||
13. Explain the difference between the following commands:
|
||||
* echo
|
||||
* /bin/echo
|
||||
14. Explain the difference between the following commands: echo Hello echo -n Hello
|
||||
15. Display A B C with two spaces between B and C.
|
||||
(optional)16. Complete the following command (do not use spaces) to display exactly the following output:
|
||||
* `echo`
|
||||
* `/bin/echo `
|
||||
14. Explain the difference between the following commands:
|
||||
* `echo Hello`
|
||||
* `echo -n Hello `
|
||||
15. Display A B C with two spaces between B and C.
|
||||
16. (optional) Complete the following command (do not use spaces) to display exactly the following output:
|
||||
```
|
||||
4+4 =8
|
||||
10+14 =24
|
||||
17. Use echo to display the following exactly: ??\\
|
||||
```
|
||||
17. Use `echo` to display the following exactly: `??\\`
|
||||
|
||||
## 13.9. practice: control operators
|
||||
|
||||
0. Each question can be answered by one command line!
|
||||
1. When you type passwd, which file is executed ?
|
||||
2. What kind of file is that ?
|
||||
3. Execute the pwd command twice. (remember 0.)
|
||||
4. Execute ls after cd /etc, but only if cd /etc did not error.
|
||||
5. Execute cd /etc after cd etc, but only if cd etc fails.
|
||||
6. Echo it worked when touch test42 works, and echo it failed when the touch failed. All on one command line as a normal user (not root). Test this line in your home directory and in /bin/ .
|
||||
7. Execute sleep 6, what is this command doing ?
|
||||
8. Execute sleep 200 in background (do not wait for it to finish).
|
||||
9. Write a command line that executes rm file55. Your command line should print 'success' if file55 is removed, and print 'failed' if there was a problem.
|
||||
(optional)10. Use echo to display "Hello World with strange' characters \ * [ } ~ \ \ ." (including all quotes)
|
||||
1. When you type `passwd`, which file is executed?
|
||||
2. What kind of file is that?
|
||||
3. Execute the `pwd` command twice. (remember 0.)
|
||||
4. Execute `ls` after `cd /etc`, but only if `cd /etc` did not error.
|
||||
5. Execute `cd /etc` after `cd etc,` but only if `cd etc` fails.
|
||||
6. Echo `it worked` when `touch test42` works, and echo `it failed` when the touch failed. All on one command line as a normal user (not root). Test this line in your home directory and in `/bin/`.
|
||||
7. Execute `sleep 6`, what is this command doing ?
|
||||
8. Execute `sleep 200` in background (do not wait for it to finish).
|
||||
9. Write a command line that executes `rm file55`. Your command line should print `success` if file55 is removed, and print `failed` if there was a problem.
|
||||
10. (optional) Use echo to display `"Hello World with strange' characters \ * [ } ~ \ \ ."` (including all quotes)
|
||||
|
||||
## 14.13. practice: shell variables
|
||||
|
||||
1. Use echo to display Hello followed by your username. (use a bash variable!)
|
||||
2. Create a variable answer with a value of 42.
|
||||
3. Copy the value of $LANG to $MyLANG.
|
||||
4. List all current shell variables.
|
||||
5. List all exported shell variables.
|
||||
6. Do the env and set commands display your variable ?
|
||||
6. Destroy your answer variable.
|
||||
7. Create two variables, and export one of them.
|
||||
8. Display the exported variable in an interactive child shell.
|
||||
9. Create a variable, give it the value 'Dumb', create another variable with value 'do'. Use echo and the two variables to echo Dumbledore.
|
||||
1. Use echo to display `Hello` followed by your `username`. (use a bash variable!)
|
||||
2. Create a variable `answer` with a value of 42.
|
||||
3. Copy the value of `$LANG` to `$MyLANG`.
|
||||
4. List all current shell variables.
|
||||
5. List all exported shell variables.
|
||||
6. Do the `env` and `set` commands display your variable?
|
||||
6. Destroy your answer variable.
|
||||
7. Create two variables, and export one of them.
|
||||
8. Display the exported variable in an interactive child shell.
|
||||
9. Create a variable, give it the value `Dumb`, create another variable with value `do`. Use `echo` and the two variables to `echo Dumbledore`.
|
||||
10. Find the list of backslash escaped characters in the manual of bash. Add the time to your PS1 prompt.
|
||||
|
||||
## 15.3. practice: shell embedding
|
||||
|
||||
1. Find the list of shell options in the man page of bash. What is the difference between set -u and set -o nounset?
|
||||
2. Activate nounset in your shell. Test that it shows an error message when using non-existing variables.
|
||||
3. Deactivate nounset.
|
||||
4. Execute cd /var and ls in an embedded shell. The echo command is only needed to show the result of the ls command. Omitting will result in the shell trying to execute the first file as a command.
|
||||
5. Create the variable embvar in an embedded shell and echo it. Does the variable exist in your current shell now ?
|
||||
6. Explain what "set -x" does. Can this be useful ?
|
||||
(optional)7. Given the following screenshot, add exactly four characters to that command line so that the total output is FirstMiddleLast.
|
||||
[paul@RHEL4b ~]$ echo First; echo Middle; echo Last
|
||||
8. Display a long listing (ls -l) of the passwd command using the which command inside an embedded shell.
|
||||
1. Find the list of shell options in the man page of bash. What is the difference between `set -u` and `set -o nounset`?
|
||||
2. Activate `nounset` in your shell. Test that it shows an error message when using non-existing variables.
|
||||
3. Deactivate `nounset`.
|
||||
4. Execute `cd /var` and `ls` in an embedded shell. The echo command is only needed to show the result of the ls command. Omitting will result in the shell trying to execute the first file as a command.
|
||||
5. Create the variable `embvar` in an embedded shell and echo it. Does the variable exist in your current shell now ?
|
||||
6. Explain what `set -x` does. Can this be useful ?
|
||||
7. (optional) Given the following screenshot, add exactly four characters to that command line so that the total output is `FirstMiddleLast`. `[paul@RHEL4b ~]$ echo First; echo Middle; echo Last`
|
||||
8. Display a long listing (`ls -l`) of the `passwd` command using the `which` command inside an embedded shell.
|
||||
|
||||
## 16.12. practice: shell history
|
||||
|
||||
1. Issue the command echo The answer to the meaning of life, the universe and everything is 42.
|
||||
1. Issue the command `echo The answer to the meaning of life, the universe and everything is 42.`.
|
||||
2. Repeat the previous command using only two characters (there are two solutions!)
|
||||
3. Display the last 5 commands you typed.
|
||||
4. Issue the long echo from question 1 again, using the line numbers you received from the command in question 3.
|
||||
5. How many commands can be kept in memory for your current shell session ?
|
||||
6. Where are these commands stored when exiting the shell ?
|
||||
7. How many commands can be written to the history file when exiting your current shell session ?
|
||||
5. How many commands can be kept in memory for your current shell session?
|
||||
6. Where are these commands stored when exiting the shell?
|
||||
7. How many commands can be written to the history file when exiting your current shell session?
|
||||
8. Make sure your current bash shell remembers the next 5000 commands you type.
|
||||
9. Open more than one console (by press Ctrl-shift-t in gnome-terminal, or by opening an extra putty.exe in MS Windows) with the same user account. When is command history written to the history file ?
|
||||
|
||||
|
@ -83,19 +86,19 @@
|
|||
|
||||
1. Create a test directory and enter it.
|
||||
2. Create the following files : (the last one has 6 characters including a space)
|
||||
* file1
|
||||
* file10
|
||||
* file11
|
||||
* file2
|
||||
* File2
|
||||
* File3
|
||||
* file33
|
||||
* fileAB
|
||||
* filea
|
||||
* fileA
|
||||
* fileAAA
|
||||
* file(
|
||||
* file 2
|
||||
* `file1`
|
||||
* `file10`
|
||||
* `file11`
|
||||
* `file2`
|
||||
* `File2`
|
||||
* `File3`
|
||||
* `file33`
|
||||
* `fileAB`
|
||||
* `filea`
|
||||
* `fileA`
|
||||
* `fileAAA`
|
||||
* `file(`
|
||||
* `file 2`
|
||||
3. List (with ls) all files starting with file
|
||||
4. List (with ls) all files starting with File
|
||||
5. List (with ls) all files starting with file and ending in a number.
|
||||
|
@ -107,30 +110,30 @@
|
|||
11. List (with ls) all files that start with f or F and end with 3 or A.
|
||||
12. List (with ls) all files that start with f have i or R as second character and end in a number.
|
||||
13. List all files that do not start with the letter F.
|
||||
14. Copy the value of $LANG to $MyLANG.
|
||||
15. Show the influence of $LANG in listing A-Z or a-z ranges.
|
||||
16. You receive information that one of your servers was cracked, the cracker probably replaced the ls command. You know that the echo command is safe to use. Can echo replace ls ? How can you list the files in the current directory with echo ?
|
||||
17. Is there another command besides cd to change directories ?
|
||||
14. Copy the value of `$LANG` to `$MyLANG`.
|
||||
15. Show the influence of `$LANG` in listing A-Z or a-z ranges.
|
||||
16. You receive information that one of your servers was cracked, the cracker probably replaced the `ls` command. You know that the `echo` command is safe to use. Can echo replace ls ? How can you list the files in the current directory with echo?
|
||||
17. Is there another command besides `cd` to change directories?
|
||||
|
||||
## 18.9. practice: input/output redirection
|
||||
|
||||
1. Activate the noclobber shell option.
|
||||
2. Verify that noclobber is active by repeating an ls on /etc/ with redirected output to a file.
|
||||
3. When listing all shell options, which character represents the noclobber option ?
|
||||
4. Deactivate the noclobber option.
|
||||
5. Make sure you have two shells open on the same computer. Create an empty tailing.txt file. Then type tail -f tailing.txt. Use the second shell to append a line of text to that file. Verify that the first shell displays this line.
|
||||
6. Create a file that contains the names of five people. Use cat and output redirection to create the file and use a here document to end the input.
|
||||
1. Activate the `noclobber` shell option.
|
||||
2. Verify that `noclobber` is active by repeating an `ls` on `/etc/` with redirected output to a file.
|
||||
3. When listing all shell options, which character represents the `noclobber` option ?
|
||||
4. Deactivate the `noclobber` option.
|
||||
5. Make sure you have two shells open on the same computer. Create an empty tailing.txt file. Then type `tail -f tailing.txt`. Use the second shell to append a line of text to that file. Verify that the first shell displays this line.
|
||||
6. Create a file that contains the names of five people. Use `cat` and output redirection to create the file and use a here document to end the input.
|
||||
|
||||
## 19.13. practice: filters
|
||||
|
||||
1. Put a sorted list of all bash users in bashusers.txt.
|
||||
2. Put a sorted list of all logged on users in onlineusers.txt.
|
||||
3. Make a list of all filenames in /etc that contain the string conf in their filename.
|
||||
4. Make a sorted list of all files in /etc that contain the case insensitive string conf in their filename.
|
||||
5. Look at the output of /sbin/ifconfig. Write a line that displays only ip address and the subnet mask.
|
||||
1. Put a sorted list of all bash users in `bashusers.txt`.
|
||||
2. Put a sorted list of all logged on users in `onlineusers.txt`.
|
||||
3. Make a list of all filenames in `/etc` that contain the string `conf` in their filename.
|
||||
4. Make a sorted list of all files in `/etc` that contain the case insensitive string `conf` in their filename.
|
||||
5. Look at the output of `/sbin/ifconfig`. Write a line that displays only ip address and the subnet mask.
|
||||
6. Write a line that removes all non-letters from a stream.
|
||||
7. Write a line that receives a text file, and outputs all words on a separate line.
|
||||
8. Write a spell checker on the command line. (There may be a dictionary in /usr/share/dict/ .)
|
||||
8. Write a spell checker on the command line. (There may be a dictionary in `/usr/share/dict/`.)
|
||||
|
||||
## 20.11. practice: basic Unix tools
|
||||
|
||||
|
@ -146,19 +149,19 @@
|
|||
6. Here are two commands that do the same thing: copy `*.odf` files to /backup/ . What would be a reason to replace the first command with the second ? Again, this is an important question.
|
||||
* `cp -r /data/*.odf /backup/`
|
||||
* `find /data -name "*.odf" -exec cp {} /backup/ \;`
|
||||
7. Create a file called loctest.txt. Can you find this file with locate ? Why not ? How do you make locate find this file ?
|
||||
8. Use find and -exec to rename all .htm files to .html.
|
||||
9. Issue the date command. Now display the date in YYYY/MM/DD format.
|
||||
10. Issue the cal command. Display a calendar of 1582 and 1752. Notice anything special ?
|
||||
7. Create a file called `loctest.txt`. Can you find this file with `locate`? Why not? How do you make locate find this file ?
|
||||
8. Use `find` and `-exec` to rename all .htm files to .html.
|
||||
9. Issue the `date` command. Now display the date in YYYY/MM/DD format.
|
||||
10. Issue the `cal` command. Display a calendar of 1582 and 1752. Notice anything special ?
|
||||
|
||||
## 22.19. practice: vi(m)
|
||||
|
||||
1. Start the vimtutor and do some or all of the exercises. You might need to run aptitude install vim on xubuntu.
|
||||
2. What 3 key sequence in command mode will duplicate the current line.
|
||||
1. Start the `vimtutor` and do some or all of the exercises. You might need to run `aptitude install vim` on xubuntu.
|
||||
2. What 3 key sequence in command mode will duplicate the current line.
|
||||
3. What 3 key sequence in command mode will switch two lines' place (line five becomes line six and line six becomes line five).
|
||||
4. What 2 key sequence in command mode will switch a character's place with the next one.
|
||||
5. vi can understand macro's. A macro can be recorded with q followed by the name of the macro. So qa will record the macro named a. Pressing q again will end the recording. You can recall the macro with @ followed by the name of the macro. Try this example: i 1 'Escape Key' qa yyp 'Ctrl a' q 5@a (Ctrl a will increase the number with one).
|
||||
6. Copy /etc/passwd to your ~/passwd. Open the last one in vi and press Ctrl v. Use the arrow keys to select a Visual Block, you can copy this with y or delete it with d. Try pasting it.
|
||||
6. Copy `/etc/passwd` to your `~/passwd`. Open the last one in vi and press Ctrl v. Use the arrow keys to select a Visual Block, you can copy this with y or delete it with d. Try pasting it.
|
||||
7. What does dwwP do when you are at the beginning of a word in a sentence ?
|
||||
|
||||
## 23.9. practice: introduction to scripting
|
||||
|
|
Loading…
Reference in New Issue