Class Test 1 Unix Software Tools ANSWERS HERE ARE THE

advertisement
Class Test 1 Unix Software Tools ANSWERS
HERE ARE THE ANSWERS TO THE CLASS TEST. Some of the answers are not given
as I want to encourage you to type in the commands and check for yourself. As
usual, any questions or problems, mail me or ask me when you see me.
NAME:___________________ STUDENT NUMBER:____________________
Write clearly. If you mean $ and write S, that is incorrect. If you mean dot (clearly
put a dot). Assume you are on the university machines.
1. cd ../; cd .; cd /; cd ~; What directory are you currently in? ~ or home, not / or
root
2. List all the files in the current directory with .txt extension? ls *.txt
3. What ‘files’ are always present in any directory? What are their names and what
do they represent? How would you list all the files in a directory except these
default files? . (current) and .. (parent)
4. In your home directory you usually have a number of hidden files associated with
your shell (e.g. bash). For example the files
.bash_history .bash_logout .bashrc .bash_profile.
What command could you use to list only these files (i.e. files starting with a “dot
bash”)? ls .*bash* or ls .bash* NOT ls *bash*
5. The above 4 files are “hidden”, indicated by the dot (these are also called “dot
files”). Can we have hidden directories? YES do ls –lA in your home directory
6. What command would you use to see what read/write/execute permissions a file
has e.g. file.txt? ls – l file.txt
7. List as many ways as you can think of to get help on Unix/Linux? man
command, man –k keyword help, aprospos, whatis , man bash
8. Given a regular ascii file test.data, what does the command
cut –f1- test.data do? It prints all! –f1 would print the first column
9. What does the following achieve (i.e. what files will be created, what is their
contents and which directory will you be in?). cd /; echo echo > echo.txt; cd;
home (~) directory, and no file as no write permissions in root (/) directory.
10.You type alias alias=’’ and alias unalias=’’.(in both cases it is single quote and
single quote, not a double quote) Will this cause a problem? Can you recover
from this? No problem.
11.Explain the following. The command cat says that hello.txt does not exist, but
when ls is executed, it says there is a file. Why is this?
$cat hello.txt
cat: hello.txt: No such file or directory
$ls -l hello.txt
-rw-r--r--
1 zlizjw1 Domain U
38 Feb 19 11:33 hello.txt
The contents of the file is “No such file or directory”
12. Issue chmod 742 file1.txt. What are the permissions after? rwxr---w13. Issue chmod u-x file2.txt. What are the permissions after? rw-r---w14. You have a java program (big.java) you want to run but it is “big” and will take
a lot of processor time. If you run it with the command java big you may slow down
the work of other people. How would you run the program to be kind or fair or polite
to other people? nice -19 java big & OR use top and renice it from there.
15. A process is running out of control. List all the command you could try to stop
the program. List them in the order you would try them (i.e. the safest first, and the
harshest last). ^z, ^c, stop [job number], kill -9 or -15 process id
16. If we issue the command mkdir myDir then echo $? and get the value 0, what
can we say happened? $?=0 last command was successful, so the dir was created.
17. echo hello > hello.txt ; echo bye.txt > hello.txt; echo bye >> hello.txt
What files are created, and what it the final contents? File is hello.txt, contexts are
18. Which of the following are equal? ls –la; ls –l –a; ls –al; ls –a –l; all same
19. ls | uniq | wc and ls | wc should give the same output – why? The uniq
command does nothing as all filenames in a dir are unique.
20. What command would you use to remove a file –file.txt (note “-“).
____________________________________________________________
21. What permissions does a file normally receive? rw-r—r--
Download