Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Create a file here named "out" that contains the last 15 lines of
the Unix password file, sorted in reverse.
(1) Use absolute paths for the input and output file names.
(2) Use the shortest possible relative paths for both the input
and output file names.
$ date >/etc/passwd
permission denied
$ cp foo /etc/passwd
permission denied
$ cat no-such-file
cannot open (or no such file)
$ sort <no-such-file
cannot open (or no such file)
-- How many arguments are passed by the shell to the commands given here:
$ tr a b <foo >bar
$ sort >bar foo
$ <foo head >bar
$ tail <foo bar
$ cat a b c >d e f g
$ wc a b c <d e f >g
-- What is the output of each of these command lines, and what is in the
file "foo" when the command finishes?
Hint: The answer is the same for all the command lines.
-- Note that the following command line sometimes works for small files:
$ date >foo
$ ln foo one
$ ln foo two
$ ln foo three
$ date >foo
$ ln foo one
$ ln one two
$ ln two three
$ date >foo
$ ln foo one
$ ln one two
$ ln one three
$ date >foo
$ ln foo new
$ ln foo new
$ ln foo new
How many Unix commands are necessary to remove all permissions from
a file that has five names?
After removing all permissions, try to copy one of the above file
names to another file. Which program issues the error message, and why?
-- Compare these two command sequences and explain how they differ, if they
do differ:
$ mkdir my dir
-- How do you append to a file, so that you can put the output of several
commands into the same file without losing what was there before?
-- What is wrong with this command to mail the contents of existing file
abcd.txt to user alleni?
Rewrite the above command to work, and remove the unnecessary "cat".
-- What is wrong with this command for copying abcd.txt into file foo?
List the exact command names and arguments for all the commands
being used in the above pipeline.
$ cp foo >bar
(Hint: How many arguments are passed to cp? How many are required? RTFM)
-- What is wrong with the following command for creating file bar?
What will be the output on the screen? What will be in file "bar"?
(Hint: How many arguments are passed to cp? How many are required? RTFM)
-- What is wrong with the following command for copying file foo to file bar?
What will be the output on the screen? What will be in file "bar"?
(Hint: How many arguments are passed to cp? How many are required? RTFM)
What is the actual output (on standard output) of the part of the command
line before (to the left of) the pipe?
-- Rewrite the following command line (from page 172 of the textbook)
to get rid of the useless "cat" command:
Let programs open their own files, or let the shell do it.
Don't use "cat" unnecessarily.