Skip to content
Snippets Groups Projects
UNIX_HPX_exercise_instructions.md 3.41 KiB
Newer Older
Fanny Wegner's avatar
Fanny Wegner committed
## Exercise 1 - Navigating the filesystem on command line

**Objective:** get familiar with navigating the directory tree and listing
the content of directories.

1. **Print your current working directory** with the `pwd` command. This will
   show you where you currently are in the directory tree.

2. **Navigate to the `exercises/` directory** (the one you unpacked from the
   zip archive file). If you are already in the `exercises/` directory,
   navigate to its parent with `cd ..` and then come back to it.

3. **Try to run the command `cd .`**. What happens? What does the `.` stand
   for?

4. **List the content** of the `exercises/` directory with `ls`, `ls -l`,
   `ls -lh`, and `ls -lha`.
   * What do the `-l`, `-h` and `-a` options do?
   * **Hint:** you can use `man ls` to display the help for the `ls` command.
     To exit the help, simply type `q` on your keyboard.
   * *Note:* one-letter options can be grouped together, so `ls -lha` is the
      same as `ls -l -h -a`.
   * *Note:* some options have both a "short" and a "long" form. E.g. `ls -a`
     is the short form for `ls --all`.
Fanny Wegner's avatar
Fanny Wegner committed


<br>
<details><summary><b>Exercise solution</b></summary>
<p>

1. Printing the current working directory:

    ```sh
    pwd
    ```

2. Navigate to the current directory, or navigate in and out of it.

    ```sh
    # If you are not already in the practicals directory.
    # Note: in the command below, you need to replace /path/to/directory/ with
    #       the actual absolute or relative path of the directory where your
    #       "practicals" directory is located.
    cd /path/to/directory/exercises
    pwd

    # If you are already in the practicals directory.
    cd ..                # Change to parent directory.
    pwd                  # 
    ls -l                #
    cd exercises/   # Go back into the practicals/ directory.
    ```

3. The `.` symbol is a shortcut for the current directory. So running `cd .`
   has no effect since it simply changes to the same directory we are already
   in.

   The `.` shortcut is useful in some situations. E.g. if you want to copy
   a file to the current directory you can do `cp /file/to/copy .`, or you
   can run an executable located in the current directory with `./run_me.sh`.


4. Listing the content of the `exercises/` directory with different `ls`
   options. the effect of the different options is described in the comments
   of the code block below.

    ```sh
    ls       # Prints the names of files and directories
    ls -l    # List content of the subdirectory in "long listing" format. This
             # provides additional details for each file/directory, such as
             # its permissions, its size and its last modified date.
    ls -lh   # Adding the "-h" option displays file sizes in "human readable"
             # format. The size of files are shown in kB, MB, GB, instead of
             # their size in bytes (octets).
    ls -lha  # Adding the "-a" option additionally displays hidden files and
             # directories. These are files/directories whose name starts with
             # a dot ".". The "-a" is the 
             # Hidden files are often used to store program configurations.
    ```

   **Tip:** It is possible to define a shorthand for longer commands that you use often, a so called `alias`. On Science Cluster, there are already some pre-defined useful aliases, among them `ll` (standing for `ls -lFh`) and `la` (standing for `ls -lA`).



</p>
</details>
<br>