adds lesson 1-3 exercizes
This commit is contained in:
parent
a8109e4c6f
commit
1bf0caa082
|
@ -0,0 +1,120 @@
|
||||||
|
# Lesson 1.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. How is Debian GNU/Linux different from Ubuntu? Name two aspects.
|
||||||
|
1. What are the most common environments/platforms Linux is used for? Name three different environments/platforms and name one distribution you can use for each.
|
||||||
|
1. You are planning to install a Linux distribution in a new environment. Name four things that you should consider when choosing a distribution.
|
||||||
|
1. Name three devices that the Android OS runs on, other than smartphones.
|
||||||
|
1. Explain three major advantages of cloud computing.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Considering cost and performance, which distributions are mostly suitable for a business that aims to reduce licensing costs, while keeping performance at its highest? Explain why.
|
||||||
|
1. What are the major advantages of the Raspberry Pi and which functions can they take in business?
|
||||||
|
1. What range of distributions does Amazon Cloud Services and Google Cloud offer? Name at least three common ones and two different ones.
|
||||||
|
|
||||||
|
# Lesson 1.2
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. For each of the following commands, identify whether it is associated with the Debian packaging system or the Red Hat packaging system:
|
||||||
|
* dpkg
|
||||||
|
* rpm
|
||||||
|
* apt-get
|
||||||
|
* yum
|
||||||
|
* dnf
|
||||||
|
1. Which command could be used to install Blender on Ubuntu? After installation, how can the program be executed?
|
||||||
|
1. Which application from the LibreOffice suite can be used to work with electronic spreadsheets?
|
||||||
|
1. Which open-source web browser is used as the basis for the development of Google Chrome?
|
||||||
|
1. SVG is an open standard for vector graphics. Which is the most popular application for editing SVG files in Linux systems?
|
||||||
|
1. For each of the following file formats, write the name of an application able to open and edit the corresponding file:
|
||||||
|
* png
|
||||||
|
* doc
|
||||||
|
* xls
|
||||||
|
* ppt
|
||||||
|
* wav
|
||||||
|
1. Which software package allows file sharing between Linux and Windows machines over the local network?
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. You know that configuration files are kept even if the associated package is removed from the system. How could you automatically remove the package named cups and its configuration files from a DEB based system?
|
||||||
|
1. Suppose you have many TIFF image files and want to convert them to JPEG. Which software package could be used to convert those files directly at the command line?
|
||||||
|
1. Which software package do you need to install in order to be able to open Microsoft Word documents sent to you by a Windows user?
|
||||||
|
1. Every year, linuxquestions.org promotes a survey about the most popular Linux applications. Visit https://www.linuxquestions.org/questions/2018-linuxquestions-org-members-choice-awards-128/ and find out which desktop applications are most popular among experienced Linux users.
|
||||||
|
|
||||||
|
# Lesson 1.3
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. What are — in a nutshell — the “four freedoms” as defined by Richard Stallman and the Free Software Foundation?
|
||||||
|
* freedom 0
|
||||||
|
* freedom 1
|
||||||
|
* freedom 2
|
||||||
|
* freedom 3
|
||||||
|
1. What does the abbreviation FLOSS stand for?
|
||||||
|
1. You have developed free software and want to ensure that the software itself, but also all future works based on it, remain free as well. Which license do you choose?
|
||||||
|
* CC BY
|
||||||
|
* GPL version 3
|
||||||
|
* 2-Clause BSD License
|
||||||
|
* LGPL
|
||||||
|
1. Which of the following licenses would you call permissive, which would you call copyleft?
|
||||||
|
* Simplified BSD License
|
||||||
|
* GPL version 3
|
||||||
|
* CC BY
|
||||||
|
* CC BY-SA
|
||||||
|
1. You have written a web application and published it under a free license. How can you earn money with your product? Name three possibilities.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Under which license (including version) are the following applications available?
|
||||||
|
* Apache HTTP Server
|
||||||
|
* MySQL Community Server
|
||||||
|
* Wikipedia articles
|
||||||
|
* Mozilla Firefox
|
||||||
|
* GIMP
|
||||||
|
1. You want to release your software under the GNU GPL v3. What steps should you follow?
|
||||||
|
1. You have written proprietary software and would like to combine it with free software under the GPL version 3. Are you allowed to do this or what do you have to consider?
|
||||||
|
1. Why did the Free Software Foundation release the GNU Affero General Public License (GNU AGPL) as a supplement to the GNU GPL?
|
||||||
|
1. Name three examples of free software, which are also offered as “Business Edition”, i.e. in a chargeable version.
|
||||||
|
|
||||||
|
# Lesson 1.4
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. You should use a “private window” in your browser if you want:
|
||||||
|
* To browse completely anonymous on the Internet
|
||||||
|
* To leave no trace on the computer you’re using
|
||||||
|
* To activate TLS to avoid cookie tracking
|
||||||
|
* In order to use DNT
|
||||||
|
* To use cryptography during data transmission
|
||||||
|
1. What is OpenStack?
|
||||||
|
* A project that allows the creation of private IaaS
|
||||||
|
* A project that allows the creation of private PaaS
|
||||||
|
* A project that allows the creation of private SaaS
|
||||||
|
* A hypervisor
|
||||||
|
* An open source password manager
|
||||||
|
1. Which of the below options are valid disk encryption softwares?
|
||||||
|
* RevealJS, EncFS and dm-crypt
|
||||||
|
* dm-crypt and KeePass
|
||||||
|
* EncFS and Bitwarden
|
||||||
|
* EncFS and dm-crypt
|
||||||
|
* TLS and dm-crypt
|
||||||
|
1. Select true or false for dm-crypt device encryption:
|
||||||
|
* Files are encrypted before being written to the disk
|
||||||
|
* The entire filesystem is an encrypted blob
|
||||||
|
* Only files and directories are encrypted, not symlinks
|
||||||
|
* Don’t require root access
|
||||||
|
* Is a block device encryption
|
||||||
|
1. Beamer is:
|
||||||
|
* An encryption mechanism
|
||||||
|
* A hypervisor
|
||||||
|
* A virtualization software
|
||||||
|
* An OpenStack component
|
||||||
|
* A LaTeX presentation tool
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Most distributions come with Firefox installed by default (if yours doesn’t, you will have to install it first). We are going to install a Firefox extension called Lightbeam. You can do that by either pressing Ctrl+Shift+A and searching for “Lightbeam” on the search field that will be shown on the tab opened, or by visiting the extension page with Firefox and clicking on the “Install” button: https://addons.mozilla.org/en-GB/firefox/addon/lightbeam-3-0/. After doing this, start the extension by clicking on its icon and start visiting some webpages on other tabs to see what happens.
|
||||||
|
1. What is the most important thing when using a password manager?
|
||||||
|
1. Use your web browser to navigate to https://haveibeenpwned.com/. Find out the purpose of the website and check if your email address was included in some data leaks.
|
|
@ -0,0 +1,273 @@
|
||||||
|
# Lesson 2.1.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Split the lines below into the components of command, option(s)/parameter(s) and argument(s):
|
||||||
|
* cat -n /etc/passwd
|
||||||
|
* ls -l /etc
|
||||||
|
* ls -l -a
|
||||||
|
* cd /home/user
|
||||||
|
1. Find what type the following commands are: (extenal commands or builtin)
|
||||||
|
* pwd
|
||||||
|
* mv
|
||||||
|
* cd
|
||||||
|
* cat
|
||||||
|
* exit
|
||||||
|
1. Resolve the following commands that use quotes:
|
||||||
|
* echo "$HOME is my home directory"
|
||||||
|
* touch "$USER"
|
||||||
|
* touch 'touch'
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. With one command and using brace expansion in Bash (review the man page for Bash), create 5 files numbered 1 to 5 with the prefix game (game1, game2, ...).
|
||||||
|
1. Delete all 5 files that you just created with just one command, using a different special character (review Pathname Expansion in the Bash man pages).
|
||||||
|
1. Is there any other way to make two commands interact with each other? What are those?
|
||||||
|
|
||||||
|
# Lesson 2.1.2
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Create a local variable **number**.
|
||||||
|
1. Create an environment variable **ORDER**, using one of the two above methods.
|
||||||
|
1. Display both the variable names and their contents.
|
||||||
|
1. What are the scopes of the previously created variables?
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Create a local variable **nr_files** and assign the number of lines found in the /etc/passwd file. Hint: Look into the command wc and command substitution and don’t forget about quotation marks.
|
||||||
|
1. Create an environment variable **ME**. Assign the **USERNAME** variable’s value to it.
|
||||||
|
1. Append the **HOME** variable’s value to **ME**, having the : delimiter. Display the contents of the **ME** variable.
|
||||||
|
1. Using the date example above, create a variable called **today** and assign the date for one of the time zones.
|
||||||
|
1. Create another variable called **today1** and assign the system’s date to it.
|
||||||
|
|
||||||
|
# Lesson 2.2
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Use the man command to find out what each command does:
|
||||||
|
* ls
|
||||||
|
* cat
|
||||||
|
* cut
|
||||||
|
* cd
|
||||||
|
* cp
|
||||||
|
* mv
|
||||||
|
* mkdir
|
||||||
|
* touch
|
||||||
|
* wc
|
||||||
|
* passwd
|
||||||
|
* rm
|
||||||
|
* rmdir
|
||||||
|
* more
|
||||||
|
* less
|
||||||
|
* whereis
|
||||||
|
* head
|
||||||
|
* tail
|
||||||
|
* sort
|
||||||
|
* tr
|
||||||
|
* chmod
|
||||||
|
* grep
|
||||||
|
1. Open the ls info page and identify the MENU.
|
||||||
|
* What options do you have?
|
||||||
|
* Find the option that allows you to sort the output by modification time.
|
||||||
|
1. Display the path to the first 3 README files. Use the man command to identify the correct option for locate.
|
||||||
|
1. Create a file called test in your home directory. Find its absolute path with the locate command.
|
||||||
|
1. Did you find it immediately? What did you have to do in order for locate to find it?
|
||||||
|
1. Search for the test file that you previously created, using the find command. What syntax did you use and what is the absolute path ?
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. There is one command in the table above that doesn’t have a man page. Which one is it and why do you think that the command doesn’t have a man page?
|
||||||
|
1. Using the commands in the table above, create the following file tree. The names that start with a capital are Directories and the ones in lower case are files.
|
||||||
|
```
|
||||||
|
User
|
||||||
|
├── Documents
|
||||||
|
| ├──Hello
|
||||||
|
| | ├──hey2
|
||||||
|
| | ├──helloa
|
||||||
|
| | └──ola5
|
||||||
|
| └──World
|
||||||
|
| └──earth9
|
||||||
|
├── Downloads
|
||||||
|
| ├──Music
|
||||||
|
| └──Songs
|
||||||
|
| ├──collection1
|
||||||
|
| └──collection2
|
||||||
|
├── Test
|
||||||
|
| └── passa
|
||||||
|
└── test
|
||||||
|
```
|
||||||
|
1. Display on the screen the present working directory, including the subfolders.
|
||||||
|
1. Search within the tree for all files that end with a number.
|
||||||
|
1. Remove the entire directory tree with a single command.
|
||||||
|
|
||||||
|
# Lesson 2.3.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. For each of the following paths, identify whether it is absolute or relative:
|
||||||
|
* /home/user/Downloads
|
||||||
|
* ../Reports
|
||||||
|
* /var
|
||||||
|
* docs
|
||||||
|
* /
|
||||||
|
1. Observe the following file structure. Note: Directories end with a slash (/) when tree is invoked with the -F option. You will need elevated privileges in order to run the tree command on the root (/) directory. The following is example output and is not indicative of a full directory structure. Use it to answer the following questions:
|
||||||
|
```
|
||||||
|
$ sudo tree -F /
|
||||||
|
|
||||||
|
/
|
||||||
|
├── etc/
|
||||||
|
│ ├── network/
|
||||||
|
│ │ └── interfaces
|
||||||
|
│ ├── systemd/
|
||||||
|
│ │ ├── resolved.conf
|
||||||
|
│ │ ├── system/
|
||||||
|
│ │ ├── system.conf
|
||||||
|
│ │ ├── user/
|
||||||
|
│ │ └── user.conf
|
||||||
|
│ └── udev/
|
||||||
|
│ ├── rules.d/
|
||||||
|
│ └── udev.conf
|
||||||
|
└── home/
|
||||||
|
├── lost+found/
|
||||||
|
└── user/
|
||||||
|
└── Documents/
|
||||||
|
|
||||||
|
12 directories, 5 files
|
||||||
|
```
|
||||||
|
* A user enters the following commands:
|
||||||
|
```
|
||||||
|
$ cd /etc/udev
|
||||||
|
$ ls -a
|
||||||
|
|
||||||
|
```
|
||||||
|
* What will be the output of the ls -a command?
|
||||||
|
1. Enter the shortest possible command for each of the following:
|
||||||
|
* Your current location is root (/). Enter the command to navigate to lost+found within the home directory (example):
|
||||||
|
* Your current location is root (/). Enter the command to navigate to the directory named /etc/network/.
|
||||||
|
* Your current location is /home/user/Documents/. Navigate to the directory named /etc/.
|
||||||
|
* Your current location is /etc/systemd/system/. Navigate to the directory named /home/user/.
|
||||||
|
1. Consider the following commands:
|
||||||
|
```
|
||||||
|
$ pwd
|
||||||
|
/etc/udev/rules.d
|
||||||
|
$ cd ../../systemd/user
|
||||||
|
$ cd ..
|
||||||
|
$ pwd
|
||||||
|
```
|
||||||
|
* What is the output of the final pwd command?
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Suppose a user has entered the following commands:
|
||||||
|
```
|
||||||
|
$ mkdir "this is a test"
|
||||||
|
$ ls
|
||||||
|
this is a test
|
||||||
|
```
|
||||||
|
* What cd command would allow you to enter this directory?
|
||||||
|
1. Try this again, but after typing in cd this, press the TAB key. What is now displayed on the prompt?
|
||||||
|
* This is an example of autocompletion, which is an invaluable tool not only for saving time, but for preventing spelling errors.
|
||||||
|
1. Try to create a directory whose name contains a \ character. Display the directory’s name with ls and delete the directory.
|
||||||
|
|
||||||
|
# Lesson 2.3.2
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Use the following file structure to answer the following three questions:
|
||||||
|
```
|
||||||
|
/
|
||||||
|
├── etc/
|
||||||
|
│ ├── network/
|
||||||
|
│ │ └── interfaces/
|
||||||
|
│ ├── systemd/
|
||||||
|
│ │ ├── resolved.conf
|
||||||
|
│ │ ├── system/
|
||||||
|
│ │ ├── system.conf
|
||||||
|
│ │ ├── user/
|
||||||
|
│ │ └── user.conf
|
||||||
|
│ └── udev/
|
||||||
|
│ ├── rules.d
|
||||||
|
│ └── udev.conf
|
||||||
|
└── home/
|
||||||
|
├── lost+found/
|
||||||
|
├── user/
|
||||||
|
│ └── Documents/
|
||||||
|
└── michael/
|
||||||
|
└── Music/
|
||||||
|
```
|
||||||
|
* What command will navigate into the network directory regardless of your current location?
|
||||||
|
* What command can user enter to navigate into their Documents directory from /etc/udev? Use the shortest possible path.
|
||||||
|
* What command can user enter to navigate into michael 's Music directory? Use the shortest possible path.
|
||||||
|
1. Consider the following output of ls -lh to answer the next two questions. Note that directories are indicated with a d at the beginning of the line.
|
||||||
|
```
|
||||||
|
drwxrwxrwx 5 eric eric 4.0K Apr 26 2011 China/
|
||||||
|
-rwxrwxrwx 1 eric eric 1.5M Jul 18 2011 img_0066.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 1.5M Jul 18 2011 img_0067.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 1.6M Jul 18 2011 img_0074.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 1.8M Jul 18 2011 img_0075.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 46K Jul 18 2011 scary.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 469K Jan 29 2018 Screenshot from 2017-08-13 21-22-24.png
|
||||||
|
-rwxrwxrwx 1 eric eric 498K Jan 29 2018 Screenshot from 2017-08-14 21-18-07.png
|
||||||
|
-rwxrwxrwx 1 eric eric 211K Jan 29 2018 Screenshot from 2018-01-06 23-29-30.png
|
||||||
|
-rwxrwxrwx 1 eric eric 150K Jul 18 2011 tobermory.jpg
|
||||||
|
drwxrwxrwx 6 eric eric 4.0K Apr 26 2011 Tokyo/
|
||||||
|
-rwxrwxrwx 1 eric eric 1.4M Jul 18 2011 Toronto 081.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 1.4M Jul 18 2011 Toronto 085.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 944K Jul 18 2011 Toronto 152.jpg
|
||||||
|
-rwxrwxrwx 1 eric eric 728K Jul 18 2011 Toronto 173.jpg
|
||||||
|
drwxrwxrwx 2 eric eric 4.0K Jun 5 2016 Wallpapers/
|
||||||
|
```
|
||||||
|
* When you run the command ls -lrS, what file will be at the beginning?
|
||||||
|
* Please describe what you expect to see as the output for ls -ad \*/.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Run the ls -lh command in a directory that contains subdirectories. Note the listed size of these directories. Do these file sizes seem correct to you? Do they accurately represent the contents of all files inside that directory?
|
||||||
|
1. Here is a new command to try: du -h. Run this command and describe the output that it gives you.
|
||||||
|
1. On many Linux systems, you can type in ll and get the same output as you would if you typed ls -l. Please note however that ll is not a command. For example, man ll will give you the message that no manual entry exists for it. This is an example of an alias. Why might aliases be useful to a user?
|
||||||
|
|
||||||
|
# Lesson 2.4
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Given the following, select the directories that would be created by the command mkdir -p /tmp/outfiles/text/today /tmp/infiles/text/today
|
||||||
|
```
|
||||||
|
$ pwd
|
||||||
|
/tmp
|
||||||
|
$ find
|
||||||
|
.
|
||||||
|
./outfiles
|
||||||
|
./outfiles/text
|
||||||
|
```
|
||||||
|
* /tmp
|
||||||
|
* /tmp/outfiles
|
||||||
|
* /tmp/outfiles/text
|
||||||
|
* /tmp/outfiles/text/today
|
||||||
|
* /tmp/infiles
|
||||||
|
* /tmp/infiles/text
|
||||||
|
* /tmp/infiles/text/today
|
||||||
|
1. What does -v do for mkdir, rm, and cp?
|
||||||
|
1. What happens if you accidentally attempt to copy three files on the same command line to a file that already exists instead of a directory?
|
||||||
|
1. What happens when you use mv to move a directory into itself?
|
||||||
|
1. How would you delete all files in your current directory that start with old?
|
||||||
|
1. Which of the following files would log_[a-z]\_201?\_\*\_01.txt match?
|
||||||
|
```
|
||||||
|
log\_3\_2017_Jan_01.txt
|
||||||
|
log_+_2017_Feb_01.txt
|
||||||
|
log_b_2007_Mar_01.txt
|
||||||
|
log_f_201A_Wednesday_01.txt
|
||||||
|
```
|
||||||
|
1. Create a few globs to match the following list of file names:
|
||||||
|
* doc100
|
||||||
|
* doc200
|
||||||
|
* doc301
|
||||||
|
* doc401
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Use the cp man page to find out how to make a copy of a file and have the permissions and modification time match the original.
|
||||||
|
1. What does the rmdir -p command do? Experiment with it and explain how it differs from rm -r.
|
||||||
|
1. **DO NOT ACTUALLY EXECUTE THIS COMMAND:** What do you think rm -ri /\* will do? **(HONESTLY, DO NOT ATTEMPT TO DO THIS!)**
|
||||||
|
1. Other than using -i, is it possible to prevent mv from overwriting destination files?
|
||||||
|
1. Explain the command cp -u.
|
|
@ -0,0 +1,168 @@
|
||||||
|
# Lesson 3.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. According to the extensions, which of the following tools were used to create these files?
|
||||||
|
* archive.tar
|
||||||
|
* archive.tgz
|
||||||
|
* archive.tar.xz
|
||||||
|
1. According to the extensions, which of these files are archives and which are compressed?
|
||||||
|
* file.tar
|
||||||
|
* file.tar.bz2
|
||||||
|
* file.zip
|
||||||
|
* file.xz
|
||||||
|
1. How would you add a file to a gzip compressed tar file?
|
||||||
|
1. Which tar option instructs tar to include the leading / in absolute paths?
|
||||||
|
1. Does zip support different compression levels?
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. When extracting files, does tar support globs in the file list?
|
||||||
|
1. How can you make sure a decompressed file is identical to the file before it was compressed?
|
||||||
|
1. What happens if you try to extract a file from a tar archive that already exists on your filesystem?
|
||||||
|
1. How would you extract the file archive.tgz without using the tar z option?
|
||||||
|
|
||||||
|
# Lesson 3.2.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. List the contents of your current directory, including the ownership and permissions, and redirect the output to a file called contents.txt within your home directory.
|
||||||
|
1. Sort the contents of the contents.txt file from your current directory and append it to the end of a new file named contents-sorted.txt.
|
||||||
|
1. Display the last 10 lines of the /etc/passwd file and redirect it to a new file in your user’s Documents directory.
|
||||||
|
1. Count the number of words within the contents.txt file and append the output to the end of a file field2.txt in your home directory. You will need to use both input and output redirection.
|
||||||
|
1. Display the first 5 lines of the /etc/passwd file and sort the output reverse alphabetically.
|
||||||
|
1. Using the previously created contents.txt file, count the number of characters of the last 9 lines.
|
||||||
|
1. Count the number of files called test within the /usr/share directory and its subdirectories. Note: each line output from the find command represents a file.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Select the second field of the contents.txt file and redirect the standard output and error output to another file called field1.txt.
|
||||||
|
1. Using the input redirection operator and the tr command, delete the dashes (-) from the contents.txt file.
|
||||||
|
1. What is the biggest advantage of only redirecting errors to a file?
|
||||||
|
1. Replace all recurrent spaces within the alphabetically sorted contents.txt file with a single space.
|
||||||
|
1. In one command line, eliminate the recurrent spaces (as done in the previous exercise), select the ninth field and sort it reverse alphabetically and non-case sensitive. How many pipes did you have to use?
|
||||||
|
|
||||||
|
# Lesson 3.2.1
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Using grep and the /usr/share/hunspell/en_US.dic file, find the lines that match the following criteria:
|
||||||
|
* All lines containing the word cat anywhere on the line.
|
||||||
|
* All lines that do not contain any of the following characters: sawgtfixk.
|
||||||
|
* All lines that start with any 3 letters and the word dig.
|
||||||
|
* All lines that end with at least one e.
|
||||||
|
* All lines that contain one of the following words: org , kay or tuna.
|
||||||
|
* Number of lines that start with one or no c followed by the string ati.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Find the regular expression that matches the words in the “Include” line and doesn’t match the ones in the “Exclude” line:
|
||||||
|
* Include: pot, spot, apot
|
||||||
|
* Exclude: potic, spots, potatoe
|
||||||
|
* Include: arp99, apple, zipper
|
||||||
|
* Exclude: zoo, arive, attack
|
||||||
|
* Include: arcane, capper, zoology
|
||||||
|
* Exclude: air, coper, zoloc
|
||||||
|
* Include: 0th/pt, 3th/tc, 9th/pt
|
||||||
|
* Exclude: 0/nm, 3/nm, 9/nm
|
||||||
|
* Include: Hawaii, Dario, Ramiro
|
||||||
|
* Exclude: hawaii, Ian, Alice
|
||||||
|
1. What other useful command is commonly used to search within the files? What additional functionalities does it have?
|
||||||
|
1. Thinking back at the previous lesson, use one of the examples and try to look for a specific pattern within the output of the command, with the help of grep.
|
||||||
|
|
||||||
|
# Lesson 3.3.1
|
||||||
|
|
||||||
|
1. The user types the following to their shell:
|
||||||
|
```
|
||||||
|
$ PATH=~/scripts
|
||||||
|
$ ls
|
||||||
|
Command 'ls' is available in '/bin/ls'
|
||||||
|
The command could not be located because '/bin' is not included in the PATH environment variable.
|
||||||
|
ls: command not found
|
||||||
|
```
|
||||||
|
* What has the user done?
|
||||||
|
* What command will combine the current value of PATH with the new directory ~/scripts?
|
||||||
|
1. Consider the following script. Notice that it is using elif to check for a second condition:
|
||||||
|
```
|
||||||
|
> /!bin/bash
|
||||||
|
|
||||||
|
> fruit1 = Apples
|
||||||
|
> fruit2 = Oranges
|
||||||
|
|
||||||
|
if [ $1 -lt $# ]
|
||||||
|
then
|
||||||
|
echo "This is like comparing $fruit1 and $fruit2!"
|
||||||
|
> elif [$1 -gt $2 ]
|
||||||
|
then
|
||||||
|
> echo '$fruit1 win!'
|
||||||
|
else
|
||||||
|
> echo "Fruit2 win!"
|
||||||
|
> done
|
||||||
|
```
|
||||||
|
* The lines marked with a > contain errors. Fix the errors.
|
||||||
|
1. What will the output be in the following situations?
|
||||||
|
```
|
||||||
|
$ ./guided1.sh 3 0
|
||||||
|
$ ./guided1.sh 2 4
|
||||||
|
$ ./guided1.sh 0 1
|
||||||
|
```
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Write a simple script that will check if exactly two arguments are passed. If so, print the arguments in reverse order. Consider this example (note: your code may look different than this, but should lead to the same output):
|
||||||
|
```
|
||||||
|
if [ $1 == $number ]
|
||||||
|
then
|
||||||
|
echo "True!"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
1. This code is correct, but it is not a number comparison. Use an internet search to discover how this code is different from using -eq.
|
||||||
|
1. There is an environment variable that will print the current directory. Use env to discover the name of this variable.
|
||||||
|
1. Using what you have learned in questions 2 and 3, write a short script that accepts an argument. If an argument is passed, check if that argument matches the name of the current directory. If so, print yes. Otherwise, print no.
|
||||||
|
|
||||||
|
# Lesson 3.3.2
|
||||||
|
|
||||||
|
## Guided Exercises
|
||||||
|
|
||||||
|
1. Read the contents of script1.sh below:
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]
|
||||||
|
then
|
||||||
|
echo "This script requires at least 1 argument."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $1 | grep "^[A-Z]*$" > /dev/null
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
echo "no cake for you!"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "here's your cake!"
|
||||||
|
exit 0
|
||||||
|
```
|
||||||
|
* What is the output of these commands?
|
||||||
|
```
|
||||||
|
./script1.sh
|
||||||
|
echo $?
|
||||||
|
./script1.sh cake
|
||||||
|
echo $?
|
||||||
|
./script1.sh CAKE
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
```
|
||||||
|
2. Read the contents of file script2.sh:
|
||||||
|
```
|
||||||
|
for filename in $1/*.txt
|
||||||
|
do
|
||||||
|
cp $filename $filename.bak
|
||||||
|
done
|
||||||
|
```
|
||||||
|
* Describe the purpose of this script as you understand it.
|
||||||
|
|
||||||
|
## Explorational Exercises
|
||||||
|
|
||||||
|
1. Create a script that will take any number of arguments from the user, and print only those arguments which are numbers greater than 10.
|
Loading…
Reference in New Issue