Exam (ECE/SS2022/G2): Do A Lot With Files And Directories

Precondition: Logged-In To Remote/Exam Computer

../../../../../../_images/cloud-computer.jpg
  • Public key deployed to remote computer (see SSH: Public Key Authentication)

  • Logged in to remote computer

    $ ssh -p 2020 firstname.lastname@jfasch.bounceme.net
    

Danger

The exam must be done on the remote computer

Take care to not accidentally execute the following steps on your local machine!

Create Exam Skeleton (5 Points)

  • In your home directory, create a subdirectory exam-01.

  • In the ~/exam-01 directory, create an empty (“skeleton”) tree as follows,

$ tree ~/exam-01/
~/exam-01/
├── business-cards
├── private-place
└── public-place

Create Business Cards (10 Points)

In the directory ~/exam-01/business-cards, create a file my-credentials.card that contains, line by line,

  • Your user name

  • Your user ID (uid)

  • The name and ID of your primary group (gid)

  • The names and IDs of your supplementary groups (groups)

In the case of user joerg.faschingbauer, that file would look like this:

$ cat ~/exam-01/business-cards/my-credentials.card
joerg.faschingbauer
1020
joerg.faschingbauer 1020
ece20 1021

Hint

See Login? What Is That? for how to find out who you are.

Hint

You use the >> operator to append a line to an existing file (or to create that file if it doesn’t exist):

$ echo 8020 Graz >> somefile.txt

Public Place (10 Points)

Tune the permissions of the ~/exam-01/public-place directory in a way that

  • You can

    • look and cd into it

    • create files in it

    • remove files from it

  • Your fellow members of the ece20 group can

    • look and cd into it

    • create files in it

    • remove files from it

  • Nobody else can do any of the above

Hint

You use the -d option (together with -l of course) to the ls command to view the permissions of the directory itself, not its contents.

For example, this shows the initial - not-yet-tuned - permissions of the directory:

$ pwd
/home/joerg.faschingbauer/exam-01
$ ls -ld public-place/
drwxr-xr-x 2 joerg.faschingbauer joerg.faschingbauer 4096 Mar 24 07:00 public-place/

Private Place (10 Points)

Tune the permissions of the ~/exam-01/private-place directory in a way that

  • You can

    • look and cd into it

    • create files in it

    • remove files from it

  • Nobody else can do any of the above

Shared File in Public Place (10 Points)

  1. Create a file completely-open.txt in ~/exam-01/public-place in a way that

    • It contains the phrase “Hello teacher”

      $ cat ~/exam-01/public-place/completely-open.txt
      Hello teacher
      
    • You can modify/write that file

    • Your fellow members of ece20 can only read it, but not write it

  2. Create another file completely-open-removable.yesno in ~/exam-01/public-place that contains either yes or no, answering the following question:

    Would any member of the ece20 group be able to remove completely-open.txt?

Make A Backup Of ~/exam-01 (15 Points)

Goal

  • Transfer what you created (i.e. the entire contents of the remote ~/exam-01 directory) to your local machine.

  • Use the scp command for this task

  • But read on! Do not start!!

Think

  • What would be the command to do this?

  • Note that we were extremely picky to restrict permissions in most parts of the tree. How would you preserve those valuable permissions across the remote copy?

    (Hint: read the scp manual page, and find out about the -p option.)

  • Create a file backup-command.sh in ~/exam-01/ containing that command.

  • Make this file executable for all users, but otherwise preserve its default permissions that it had initially.

  • Finally, execute the scp command on your local machine

Dependencies

cluster_linux Linux cluster_linux_basics Linux Basics cluster_linux_basics_intro Introduction: Concepts and Terminology cluster_linux_basics_exercises Exercises/Exams: Linux Basics cluster_linux_basics_shell The Shell (Bash - “Bourne Again Shell”) cluster_linux_basics_shell_exercises The Shell - Exercises cluster_linux_basics_shell_exercises_cp_mv_mkdir_rm Exercises: Create/Copy/Move/Remove linux_basics_intro_process Processes, Scheduling, Address Spaces linux_basics_intro_overview Overview linux_basics_intro_process->linux_basics_intro_overview linux_basics_exercises_FH_SS2022_EXAM_01_G2 Exam (ECE/SS2022/G2): Do A Lot With Files And Directories linux_basics_shell_ls Directory Listings: The ls Command linux_basics_exercises_FH_SS2022_EXAM_01_G2->linux_basics_shell_ls linux_basics_shell_cp Copying: cp linux_basics_exercises_FH_SS2022_EXAM_01_G2->linux_basics_shell_cp linux_basics_shell_exercises_cp_mv_mkdir_rm_mkdir_p_rm_r Exercise: mkdir linux_basics_exercises_FH_SS2022_EXAM_01_G2->linux_basics_shell_exercises_cp_mv_mkdir_rm_mkdir_p_rm_r linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files Exercise: Create Files (I/O Redirection) linux_basics_exercises_FH_SS2022_EXAM_01_G2->linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files linux_basics_shell_paths Absolute and Relative Paths linux_basics_shell_commandline Commandline linux_basics_shell_paths->linux_basics_shell_commandline linux_basics_shell_file_dir_create_rm Creating And Removing Files and Directories linux_basics_shell_file_dir_create_rm->linux_basics_shell_paths linux_basics_shell_cwd Current Working Directory linux_basics_shell_file_dir_create_rm->linux_basics_shell_cwd linux_basics_shell_commandline->linux_basics_intro_overview linux_basics_shell_special_paths Special Paths linux_basics_shell_special_paths->linux_basics_shell_paths linux_basics_shell_ls->linux_basics_intro_overview linux_basics_shell_ls->linux_basics_shell_paths linux_basics_shell_ls->linux_basics_shell_special_paths linux_basics_shell_ls->linux_basics_shell_cwd linux_basics_shell_cwd->linux_basics_intro_process linux_basics_shell_cwd->linux_basics_shell_paths linux_basics_shell_cwd->linux_basics_shell_commandline linux_basics_shell_cp->linux_basics_shell_paths linux_basics_shell_cp->linux_basics_shell_file_dir_create_rm linux_basics_shell_exercises_cp_mv_mkdir_rm_mkdir_p_rm_r->linux_basics_shell_file_dir_create_rm linux_basics_shell_exercises_cp_mv_mkdir_rm_mkdir_p_rm_r->linux_basics_shell_cwd linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files->linux_basics_shell_paths linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files->linux_basics_shell_file_dir_create_rm linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files->linux_basics_shell_cwd linux_basics_shell_exercises_cp_mv_mkdir_rm_echo_create_files->linux_basics_shell_exercises_cp_mv_mkdir_rm_mkdir_p_rm_r