Complete this assignment by downloading this HTML file and editing it (using a text editor---not a special HTML editor). Wherever you see emphasized text (e.g. "Your name" and "Your Student Number" above) you should insert your own text, as appropriate. Submit via D2L at the end of the lab period.
Solve the following questions using some of the text tools:
ls
, cat
, grep
,
sort
, uniq
, head
, and
tail
and the commands date
,
pwd
, and echo
and command line
expansion. All of the questions can be solved with one command
line.
Write a command line that produces:
The product of 3 times 45 is 135.
An arithmetic expansion must be used to calculate 135.
(hint: at least use echo
)
Change this with your answer
Make a directory name ~/tmp/a
. Provide a
command line that produces the following (assume the current
directory is ~/tmp/a
). The current month, day,
and year should also be displayed.
At January 21, 2015 the current directory is ~/tmp/a.
You must employ echo, date, and pwd.
Change this with your answer
Change into the directory containing the
words1
-- words5
files (see lab 2).
Write a command line that produces:
The number of occurrences of 'xy' in word1 is 102
The command should search word1
with
grep
for xy
. (hint: use grep -c
with other commands)
Change this with your answer
Change into the directory containing the
words1
-- words5
files (see lab 2).
Write a command line that produces:
The string 'xy' appears in words1 and words2 197 times.
(hint: use an arithmetic expansion)
Change this with your answer
Change into the directory containing the
words
file. Write a command line that
produces:
The number of occurrences of 'st' in the first 100 lines of words is 3.
Change this with your answer
Documentation about history expansion is found by man
bash
and search for HISTORY EXPANSION
.
In a terminal window, execute the following commands:
% history -c
% cd $HOME
% mkdir testA
% cd testA
% echo "Time $(date +'%H:%M')" >> log
% echo "-----" >> log
% echo "Second Time $(date +'%H:%M')" >> log
Please type no other commands for the moment.
Determine what command gets executed by:
% !!
Change this with your answer
Determine what command gets executed by:
% !-2
Change this with your answer
Save your history with the command:
% history -w
Provide a command line to count the number of
echo
commands in the
~/.bash_history
file. Do not use
wc
.
Command:
Change this with your answer
Command(s) Output:
Change this with your answer
Provide a command line show all the echo
commands in the ~/.bash_history
file.
Command:
Change this with your answer
Command(s) Output:
Change this with your answer
What history expansion command would search backwards for
the most recent mkdir
command?
Change this with your answer
What key
on the keyboard can be struck to
display the last command and then allow the command to be
edited?
Change this with your answer
Show the command(s) and their output used to determine the following:
The permissions and location of the sudo
command (hint: use which
to determine the
location).
Command(s):
Change this with your answer
Command(s) Output:
Change this with your answer
The permissions and location of the ps
command.
Command(s):
Change this with your answer
Command(s) Output:
Change this with your answer
Execute the following commands
% mkdir $HOME/test-3; cd $HOME/test-3;
% echo "Time: $(date +'%H:%M') $(pwd)" > ts
% chmod ugo-rwx ts
% chmod u+r ts
Show the command and its output used to determine the
contents of ts
.
Command:
Change this with your answer
Command(s) Output:
Change this with your answer
Show the command and output used to determine the
permissions of ts
.
Command:
Change this with your answer
Command(s) Output:
Change this with your answer
What command would change the permission to allow all
users read access? Use the non-octal options for
chmod
.
Command:
Change this with your answer
Show the new permissions:
Command:
Change this with your answer
Command(s) Output:
Change this with your answer
What is the octal version of this chmod
command?
Command:
Change this with your answer
Execute the following commands:
% cd /tmp
% mkdir -p /tmp/dir1/dir2
% chmod a-w /tmp/dir1
% rmdir /tmp/dir1/dir2
Explain why the rmdir
command fails. What
permission should be changed to allow the rmdir
command to succeed?
Change this with your answer