CST334 Tutorial Sheet 6 COMMANDS VARIATIONS

Forouzan Chapter 3,5,6 (Selected)

THE COMMAND LINE : a complete command = cmd [options] [arguments]

1. Type in the following commands, describe what they do.

a. ls -l Desktop/ display a long list of the directory Desktop

b. cp -i bio bio2 make a copy, but warn if you are about to overwrite bio2

c. rm -i bio bio2

d. cat bio

e. echo bio

f. tr aeiou AEIOU hit enter, then type letters

REDIRECTION: command < infile OR command > outfile OR command > outfile

2. Describe what the following commands do:

a. cat sends standard input to standard output until end of file marker

b. echo these words > save makes a file save containing: these words

c. cat < infile > outfile makes a copy of infile

d. ls -aF > outfile

e. ls -ld > outfile

PIPES: 1) cmd1 > temp 2) cmd2 temp 3) rm temp = cmd1 | cmd2

3. Describe what the following commands do:

a. ls -l | more takes a long list of your directory and displays it using more

b. cat bio | tr abc ABC display the contents of bio capitalizing all a b c

c. who | grep 'loginID' where loginID is somebody's usernam. See if they are logged in

d. who | sort | lpr don't type this!

WILD CARDS ? = 1 character , * = many or no characters, [ ] = range of characters

4. Assume you are in a directory which contains the following files:

bio bio1 bio2 bio3 bio4 biox mybio bio.txt

a. Which files will appear when you type: ls bio? (the '?' key is in the command)

b. Which files will appear when you type: ls bio*

c. Which files will be removed when you type: rm *bio

c. Which files will be displayed when you type: cat bio[1-4]

BACKGROUND

Describe how to run a program in the "background" use cmd &, or ^Z, bg %[job#]

Display a list of processes running ps, ps -u, ps aux

Tell how to bring the background program into the foreground jobs, fg %[job#]

Tell two ways to stop a program that is running in the background

Foreground the job (fg %[job#] and exit, or kill %[job#] or kill PID )

ACTIVITIES

1. Type man ls and experiment with the various options. Which option shows size?

2. now type: ls -l, ls -a, ls -A, ls -F and notice the different variations

3. What happens when you type ls -lAF what about: ls -FlA

4. Use cat to display several files on the screen at once: cat file1 file2 file3

5. Now use redirection to put the same three files into a single file named file_all

6. add one more file to the collection using the append > redirection

7. Use the ls -R / command with a pipe to display all files one page at time

8. Type this command: ls -al /* | sort -nr +4 | more what does it do?

9. Using wild cards, how would you use cat to show all the files ending in txt

10. How would you list any files with names containing the letter o

11. How would you show the contents of the files backgammon, backpacking, and blackjack

12. Open another window using putty, and start the Joe Editor.

13. In your first window, find out what the process ID number is for the Joe process

14. Kill the Joe Editor process from your first window