CSE150 Operating Systems (Spring semester 2008): Linux usage basics
The following exercises are intended to get you acquainted, by way of examples, with using Linux from the shell's command line: pipes (|), redirection (<,>,<<,>>,1>,2>, etc.), foreground/background processes (&), wildcards (*,?), signals, etc. Open a single terminal window and then avoid running things from menus, use just the command line in that window. You will find the following commands useful (to find out about usage, syntax and parameters from the manual pages for, say grep, type man grep):
- Files and directories: cp, mv, rm, mkdir, rmdir, cd, pwd, ls, mount, ln. Start with these first, by creating and removing files, links and directories, and exploring directories (e.g. look at /usr/bin, /usr/include, /bin, /dev, /etc).
- Editors: vi, xemacs.
- File viewing/modifying: cat, more, less, head, tail, cut, paste, grep, wc, sort, uniq, diff.
- Programming tools: gcc, make, as, ld.
- Permissions: chmod, chown, chgrp.
- Processes: ps, top, kill.
- Shells: sh, bash.
- Other system tools: which, date, who.
- Disk usage, CPU usage: df, du, time.
- Others: file, find, sleep.
- Sending signals interactively (besides kill):
- Ctrl-C (kill; try while running ping www.ucmerced.edu)
- Ctrl-Z (suspend; try while running vi, see background processes with jobs and return with %1)
- Ctrl-S (pause, continue with Ctrl-Q; try while running ping www.ucmerced.edu)
- Ctrl-D (EOF; try with cat > f.txt or directly from the shell prompt).
For the questions below, I suggest you open a separate terminal window (xterm &) and run top there showing only your own processes while you work on another terminal window. That way you can see how processes created in the latter appear in top.
- What do these do?
- ls /usr/bin/x?a*
- ls -l /usr/bin > f1.txt
- find /usr/bin -name "x*" -print | more
- (ls -l ; date ; pwd ) > f2.txt
- ls -l ; date ; pwd > f3.txt
- ls -l > f4.txt; date ; pwd >> f3.txt
- ls -a ~/
- ls -i
- head -5 /usr/include/stdio.h | tail -1 | cut -c 8-12
- date | cut -c 12-16
- cat /usr/include/stdio.h > /dev/null
- ping www.ucmerced.edu
- echo "Today is `date | cut -c -10`."
- who | wc -l
- sleep 5 ; echo "I'm awake"
- (sleep 5 ; echo "I'm awake") &
- ls -l /usr/bin/x* | more
- ls -l /usr/bin | grep x | more
- du -sh /usr/*
- du -sh /usr/* 2> /dev/null
- time sleep 5
- echo $HOME
- echo $myvar
- myvar="1 2 3"; echo $myvar
- echo "date" | sh
- How to do the following?
- Show the third line of /etc/passwd.
- List all files in the current directory that contain a dot (.) in their name.
- List the processes from user root.
- Given a file f1.txt, make it readable by all, writable by the group and executable by the owner.
- Create a background process xterm and then kill it.
- Start vi, suspend it, show today's date, resume with vi.
- Consider another operating system you may be familiar with (e.g. Windows or MacOS). How would you do any of the things above?
Miguel A. Carreira-Perpinan
Last modified: Wed Feb 13 18:04:49 PST 2008
UC Merced |
EECS |
MACP's Home Page