Quiz Space

System Commands OPPE 1: September 2023, Set 1 (September 2023 term)

Question 1

+15 marksProgramming

Error Handling requires one to understand exit status implementation. Write a function which will echo "Success" if there are 3 arguments passed to it and print all the three arguments. The exit status of any more or less arguments passed to the function should end up in exit status of 1.

Hint: Use return keyword

Question 2

+15 marksProgramming

Sanjay is a professional photographer who capture photos of items for various clients. The photos database has thousands of photos collected each year. The photographs are stored in jpg format using YYYYMMDD_HHMMSS.jpg naming convention. For his backup purpose he wants to organize his data by moving the photos to a new directory created using monthYear (Ex: Jan2021) format (thus 12 directory for each year). Write a shell script which will create folders based on the image name and creates and moves it to the respective month directory.

Hint:

$ date --help
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display date and time in the given FORMAT.
With -s, or with [MMDDhhmm[[CC]YY][.ss]], set the date and time.

Mandatory arguments to long options are mandatory for short options too.
  -d, --date=STRING          display time described by STRING, not 'now'
...

FORMAT controls the output.  Interpreted sequences are:

  %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
  %C   century; like %Y, except omit last two digits (e.g., 20)
  %d   day of month (e.g., 01)
  %D   date; same as %m/%d/%y
  %e   day of month, space padded; same as %_d
  %F   full date; like %+4Y-%m-%d
  %g   last two digits of year of ISO week number (see %G)
  %G   year of ISO week number (see %V); normally useful only with %V
  %h   same as %b
  %H   hour (00..23)
  %I   hour (01..12)
  %j   day of year (001..366)
  %k   hour, space padded ( 0..23); same as %_H
  %l   hour, space padded ( 1..12); same as %_I
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %N   nanoseconds (000000000..999999999)
  %p   locale's equivalent of either AM or PM; blank if not known
  %P   like %p, but lower case
  %q   quarter of year (1..4)
  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
  %R   24-hour hour and minute; same as %H:%M
  %s   seconds since the Epoch (1970-01-01 00:00 UTC)
  %S   second (00..60)
  %t   a tab
  %T   time; same as %H:%M:%S
  %u   day of week (1..7); 1 is Monday
  %U   week number of year, with Sunday as first day of week (00..53)
  %V   ISO week number, with Monday as first day of week (01..53)
  %w   day of week (0..6); 0 is Sunday
  %W   week number of year, with Monday as first day of week (00..53)
  %x   locale's date representation (e.g., 12/31/99)
  %X   locale's time representation (e.g., 23:13:48)
  %y   last two digits of year (00..99)
  %Y   year
  %z   +hhmm numeric time zone (e.g., -0400)
  %:z  +hh:mm numeric time zone (e.g., -04:00)
  %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
  %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic time zone abbreviation (e.g., EDT)

...
Examples:
Convert seconds since the Epoch (1970-01-01 UTC) to a date
  $ date --date='@2147483647'

Show the time on the west coast of the US (use tzselect(1) to find TZ)
  $ TZ='America/Los_Angeles' date

Show the local time for 9AM next Friday on the west coast of the US
  $ date --date='TZ="America/Los_Angeles" 09:00 next Fri'

...

Question 3

+15 marksProgramming

Write a bash script which works on output of ls -li to produce an output which will have unique list of files which are not softlinks and has only one file for multiple hardlinks present.

Note: The final output should be sorted by ascending order of inode number.

Hint: Output of the ls -li is given in a file sample.txt. sample.txt File

   12 -rwxr-xr-x 1 root root 1113504 Apr 18  2022 bash
   13 -rwxr-xr-x 1 root root  716464 Mar 13  2018 btrfs
   14 -rwxr-xr-x 1 root root  375952 Mar 13  2018 btrfs-debug-tree
   15 -rwxr-xr-x 1 root root  371856 Mar 13  2018 btrfs-find-root
   16 -rwxr-xr-x 1 root root  396432 Mar 13  2018 btrfs-image
   17 -rwxr-xr-x 1 root root  375952 Mar 13  2018 btrfs-map-logical
   18 -rwxr-xr-x 1 root root  371856 Mar 13  2018 btrfs-select-super
   19 -rwxr-xr-x 1 root root  371856 Mar 13  2018 btrfs-zero-log
   20 lrwxrwxrwx 1 root root       5 Mar 13  2018 btrfsck -> btrfs
   21 -rwxr-xr-x 1 root root  375952 Mar 13  2018 btrfstune
   22 -rwxr-xr-x 3 root root   34888 Jul  4  2019 bunzip2
   23 -rwxr-xr-x 1 root root 2062296 Nov 25  2021 busybox
   22 -rwxr-xr-x 3 root root   34888 Jul  4  2019 bzcat
   24 lrwxrwxrwx 1 root root       6 Jul  4  2019 bzcmp -> bzdiff
   25 -rwxr-xr-x 1 root root    2140 Jul  4  2019 bzdiff
   26 lrwxrwxrwx 1 root root       6 Jul  4  2019 bzegrep -> bzgrep
   27 -rwxr-xr-x 1 root root    4877 Jul  4  2019 bzexe
   28 lrwxrwxrwx 1 root root       6 Jul  4  2019 bzfgrep -> bzgrep
   29 -rwxr-xr-x 1 root root    3642 Jul  4  2019 bzgrep

3 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the System Commands OPPE 1 Sept 2023 Set 1 paper

The IIT Madras BS System Commands (System Commands) OPPE 1 paper sat on Sept 2023, in the September 2023 term, set 1: 6 questions for 105 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureSystem Commands OPPE 1 Sept 2023 Set 1 at a glance
TermSeptember 2023 term
SubjectSystem Commands
Course codeBSSE2001
Questions6
Marks105
Duration180 min
Programming6
Official paperOPPE 1, Sep 2023 Set 1
Negative markingNo negative marking.
Updated

Other sets that day

Same OPPE 1, other subjects

More System Commands