Skip to content

Commit 0814b20

Browse files
committed
added solutions to exercises
1 parent f6c1de1 commit 0814b20

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

mkdocs/docs/HPC/linux-tutorial/beyond_the_basics.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ For example, to see the number of files in a directory, we can pipe the
8383
(`stdout`) output of `ls` to `wc` (**w**ord **c**ount, but can also be used to
8484
count the number of lines with the `-l` flag).
8585
<pre><code>$ <b>ls | wc -l</b>
86-
42
86+
42
8787
</code></pre>
8888

8989
A common pattern is to pipe the output of a command to `less` so you
@@ -521,25 +521,45 @@ overwrite any pragmas present in the script.
521521
522522
## Exercises
523523
524-
1. Create a file that contains this message: "Hello, I am &lt;user&gt;",
525-
where `<user>` is replaced by your username. Don't cheat by using an
526-
editor, use a command to create the file.
527524
528-
2. Use another command to add this line to the same file: "I am on
529-
system &lt;hostname&gt; in directory &lt;current&nbsp;directory&gt;". Words
530-
between `<>` should be replaced with their value (hint: use
531-
environment variables).
525+
??? abstract "Create a file `hello.txt` that contains this message: 'Hello, I am [user]'"
526+
```bash
527+
echo "Hello, I am $USER" > hello.txt
528+
```
532529
533-
3. How many files and directories are in `/tmp`?
530+
??? abstract "Use another command to add this line to the same file: 'I am on system [hostname] in directory [current directory]'"
531+
```bash
532+
echo "I am on system $(hostname) in directory $(pwd)" >> hello.txt
533+
```
534534
535-
4. What's the name of the 5th file/directory in alphabetical order in
536-
`/tmp`?
535+
??? abstract "How many files and directories are in /tmp?"
536+
```bash
537+
ls /tmp | wc -l
538+
```
537539
538-
5. List all files that start with `t` in `/tmp`.
540+
??? abstract "What's the name of the 5th file/directory in alphabetical order in /tmp?"
541+
```bash
542+
ls /tmp | sort | head -5 | tail -1
543+
```
539544
540-
6. Create a file containing "My home directory &lt;home&gt; is available
541-
using $HOME". `<home>` should be replaced with your home directory,
542-
but `$HOME` should remain as-is.
545+
??? abstract "List all files that start with 't' in /tmp."
546+
```bash
547+
ls /tmp/t*
548+
```
543549
544-
7. How many processes are you currently running? How many are you
545-
allowed to run? Where are they coming from?
550+
??? abstract "Create a file containing 'My home directory <home> is available using $HOME'."
551+
```bash
552+
echo "My home directory $HOME is available using \$HOME" > home_info.txt
553+
```
554+
555+
??? abstract "How many processes are you currently running? How many are you allowed to run? Where are they coming from?"
556+
```bash
557+
echo "Number of processes currently running:"
558+
ps -u $USER | wc -l
559+
560+
echo "Maximum number of processes allowed:"
561+
ulimit -u
562+
563+
echo "Processes currently running:"
564+
ps -u $USER
565+
```

0 commit comments

Comments
 (0)