[cs631apue] Some questions on midterm....

Jan Schaumann jschauma at stevens.edu
Sat Oct 5 14:17:36 EDT 2013


Tejas Nadkarni <tnadkarn at stevens.edu> wrote:
 
> - How important is variable column width that's dynamic to the content like
> the system 'ls' implementation does - this is specific to the -l
> longformat. Is this required and will points be deducted? Mine uses fixed
> widths which work for nearly every condition but obviously large file sizes
> will throw it off. Want to check before I invest more time in it

It's not functionally crucial, but you should try to make an effort to
handle this.

As noted before, we are writing system tools conceptually suitable for
inclusion in the OS as a core component.  If you used the command
provided by the system, and it garbled the output or took obvious short
cuts, you'd likely think less of the system.  Formatting etc. tends to
reflect on the overall care paid to the program.

> - What is the point of the '-d' flag?

The '-d' flag is useful when you want to display certain entries without
recursing into them should they happen to be directories.  Suppose you
want to get the long listing information of all entries starting with
the letter 'b' under '/':

ls -l /b*

will open the /bin directory and instead give you the information about
the files in that directory.

ls -ld /b*

will do the right thing.


> It's not clear if all we're doing is printing out the path or cwd and
> exiting?

You should, as the manual page states, list directories encountered as
plain files (and not list their contents, as you would without the '-d'
flag) and not follow symbolic links given as arguments.

ln -s / foo
ls foo
ls -ld foo
ls -d foo

> - the extra credit to implement -c that's for ls with the short format
> right? i.e. not -l because we have to multi-column output for '-l' already.
> I'm assuming then that -c is only valid without -l

Correct.  '-c' changes the default output format of your program from
'-1' to match that of the system provided ls(1).


> Currently mine just prints out the files/directories as it traverses
> based on sort. Any thoughts?

I'm not sure I understand your question correctly, but: Your program
needs to show the user which files belong to which directory.  That is,
a single list of all files without any indication of what subdirectory
they were found in would not be reasonable.

For example:

mkdir -p dir/subdir/subsubdir
touch dir/file dir/subdir/file dir/subdir/subsubdir/file
ls -R
.:
dir

./dir:
file  subdir

./dir/subdir:
file  subsubdir

./dir/subdir/subsubdir:
file


allows the user to see which files exist where.  If you printed

ls -R
dir
file  subdir
file  subsubdir
file

then it would be confusing for the user to figure out which 'file'
resides where.


If you meant something else, perhaps show examples of your program's
output versus the system command's.

-Jan


More information about the cs631apue mailing list