(Tutorials) A Linux quizzz…

June 4, 2010

Linux command line quizzz

Results as of 7 juli 2017 after 299 attempts:

   0 questions good:    24 times
   1 question  good:    35 times
   2 questions good:    52 times
   3 questions good:    51 times
   4 questions good:    43 times
   5 questions good:    29 times
   6 questions good:    25 times
   7 questions good:    17 times
   8 questions good:    14 times
   9 questions good:     8 times
  10 questions good:     1 time

So become number 2 to get all 10 questions right (in one try)!

Explanation you find after submitting.


Note: a GNU/Linux system is assumed with bash as the shell.

Your name and/or email (not obligated):
(name/email will never be displayed)

1) What is the difference in using single quotes (') or double quotes (") for the shell?






2) How do you remove the file -i ? Remember laziness is one of the virtues of a Linux sysadmin.






3) Explain the diff in output between the following two commands:
~$ wc -l < /etc/passwd
42
~$ wc -l /etc/passwd
42 /etc/passwd
~$






4) User bob does do the following:
~$ ls -l showall
ls: cannot access showall/bla.txt: Permission denied
total 0
-????????? ? ? ? ?            ? bla.txt
~$
What's wrong here?






5) I want to backup the contents of the directory (not the directory itself) '/home/gates/My Documents' into the directory /var/backup/gates using rsync and I want to exclude the directory '/home/gates/My Documents/My Pictures' in the backup.
What is the correct command?






6) Consider the following:
~$ find /etc -type f  -name pam* > pamfiles
find: `/etc/ssl/private': Permission denied
find: `/etc/cups/ssl': Permission denied
~$ sudo !!
sudo find /etc -type f -name pam* > pamfiles
[sudo] password for bob:
~$ cat pamfiles
~$
What? No pam installed on this Linux system?






7) What happens here:
~$ sort
a
A
a
A
~$






8) You want to grep only the lines with *all* single alphanumerical characters enclosed by a single pair of square brackets. Thus, if you for example have the lines:
[a][6][z][4][u]
[a]b[c][d]
[a][b][c][d][e]
a[bc]d
only the first and third line are shown. Which command will do this:






9) What does the following command do:
find / -name '*-' | xargs -d "\n" -r rm






10) Last but not least (thanks to Felix!): we know we can use diff to diff the contents of two files:
diff file1 file2
But can you diff the output of two commands (in one single command)?







tags:

Follow comments via the RSS Feed | Leave a comment

19 Comments to "A Linux quizzz…"

  1. eMBee wrote:

    8a is missing a closing ‘

    i have to remember xargs -d, that’s useful.
    same with the named pipes. didn’t know they can be constructed that way.

    question 6 is mean 🙂

    greetings, eMBee.

  2. eigenaar wrote:

    Thank you for the correction of 8a! Bad mistake.. 🙁
    And also thank you for taken your time to fill in this quiz!

    And yes, 6 is quite mean….sorry…. 😉

    Oscar.

  3. Idontlikemultiplechoice wrote:

    Can we use man pages to answer the questions or are we supposed to know all that by heart?

    Q5: Nice anecdote, but is it really indicative of sysadmin wizardry?

    Q8,9: No way without the manual

    Personally, I think it would be more interesting to test whether somebody understands the concepts and knows how to find answers. Unfortunately, this is unlikely to be possible with a web form…

  4. eigenaar wrote:

    You may use man-pages. And you even may use a terminal (although that’s a bit more cheating then the man-pages ;-))

    I changed Q5.

  5. John Lauro wrote:

    For problem 4, I see the ????? more often if the file is deleted while you are doing the ls. With permission denied error you don’t get the file to be listed outside the permission denied error.

    For number 10, it depends how you define one command.

    diff `diff file1 file2 >d1 ; echo d1` `diff file3 file4 >d2 ; echo d2`

    Specifying cmd1 and cmd2 for process substitution is still 3 cmds if you count the above as more than 1.

  6. Ivan D'hond wrote:

    Aaaaaaaargh!

  7. eigenaar wrote:

    I changed Q5.

  8. msarmadi wrote:

    I have another one if you are interested. How to create a scheduled job, say backup.sh, to run only in last thursday of each month, say 01:00 AM.

  9. msarmadi wrote:

    I forgot to mention, I really enjoyed the quiz. Thanks for sharing.

  10. eigenaar wrote:

    Thank you!
    00 01 * * 4 [ $(date +”%m”) -ne $(date -d 7days +”%m”) ] && /path/to/backup.sh
    I really like the question, nice!

  11. eigenaar wrote:

    @msarmadi: thank you again! 🙂

  12. msarmadi wrote:

    Another classic one: What is happening we remove a big file, say a 2GB runaway log, but disk is not freed up?

  13. eigenaar wrote:

    Nice, I know the answer but think I’m gonna use it in a “sysadmin quizzz”, thank you! So no “spoiler alert” here ;-). Well ok: proces is still running 😉 This is different behaviour compared to windows.

  14. msarmadi wrote:

    There are other possibilities. Not just one.

  15. Alessandro Selli wrote:

    Question #1:
    «Everything within single quotes is ignored by the shell. Within double quotes everything is ignored except the backslash (\), dollar-sign ($) and back-ticks (`).»
    The exclamation mark character “!” too is not literal when it is between double quotes and history expansion is not disabled.
    I would not say that double or single quotes are ignored, rather that they are literal. Ignored means that that they are there or not there does not make any difference. Literal characters are always accounted for, instead.

    Question #4:
    chmod(1) man page calls “search bit” the “x” flag that is set on a directory, not execution bit: you cannot execute directories, never, you could access or traverse them with the cd command to search items in them or in their subdirectories.

    Question #7:
    «This is what you expect: first a then A.»
    This answer is right: I do expect first a then A in my localized environment. It would be wrong if it stated: “Correct: a always sorts before A”.

  16. eigenaar wrote:

    True for the exclamation mark. I changed it.
    I don’t say the quotes are ignored but *within* the quotes is ignored.

    You are also right the x-bit on directories is called the search-bit. But everybody knows the x-bit is meant when talking about execute permission for a directory. Changed it anyway because it’s more precise.

    And indeed Q7 is questionable. I changed it.

    Thank you for the helpfull comments! (and congrats with the excellent score! ;-)).

  17. Alessandro Selli wrote:

    I regret I did not become the 2nd record-breaker, though! 🙂

  18. Erik wrote:

    Hey eigenaar,

    Thanks for the quiz!

    On question 5 you state that the directory to exclude is named ‘/home/gates/My Documents/My Pictures’ but the “correct” answer has the capitalization wrong (/My pictures)….

    Cheers,

    Erik

  19. eigenaar wrote:

    @Erik: you are absolutely right! Bad mistake from me and thanks for correcting! I updated the answer.

    Kind regards,
    Oscar

Leave Your Comment

 
"The problem here is 100% between the chair and the keyboard"

Powered by Wordpress. Theme by Shlomi Noach, openark.org
© 2017 KwaLinux Trainingen | Algemene voorwaarden | KvK: 10147727 | Disclaimer