1. Home
  2. Docs
  3. Beginning UNIX on Raven
  4. Answers
  5. Answers to final knowledge check

Answers to final knowledge check

1. How would you change your password?


2. What does the command cd ~ do?

Changes your working directory to your home directory.

3. How can you change from /home/pi/files to /home/pi/newfiles using a relative path?

cd ../newfiles

4. What command will list all text files (.txt) in a directory showing their file sizes in an easily readable form?

ls –lh *.txt

5. What command will show you the first 10 lines of a file?

head file.txt

6. What about the first 25 lines?

head –n 25 file.txt

7. How about the last 12?

tail –n 12 file.txt

8. How can you find out how to use a new command?

command --help

man command

9. What command file will rename file1.txt to file2.txt?

mv file1.txt file2.txt

10. How can you move /home/pi/files/file1/txt to the /home/pi directory ?

mv ~/files/file1.txt ~/file1.txt

11. How can you delete all text (.txt) files in a directory?

rm *.txt

12. How about deleting all files that have the same format (file1.txt, files2.txt etc)?

rm file*.txt

13. How can you list all the lines in a file which contain the word raspberry or Raspberry?

grep -i raspberry file.txt

14. How can you count the number of lines in a file that contain the word pi?

grep pi file.txt | wc -l

15. What command will append the output from a program called analyse to a file called output.txt?

analyse >> output.txt

16. How can you create a new directory called newdir?

mkdir newdir

17. How can you count up the number of files in your home directory with a .txt suffix?

ls *.txt | wc -l

18. How can you scroll though your output.txt file?

less output.txt

19. How can you find out what all the files in your directory may contain?

file *

20. How can you redirect the output from a program called analysis to both a file called output.txt and also show it on screen?

analysis | tee output.txt