BARE-BONED USE OF UNIX/LINUX


Use Putty or another shh client to enter a UNIX/Linux system on which you have an account.
If you need to install it on your own PC,
http://www.chiark.greenend.org.uk/~sgtatham/putty/

Fill out the dialog box: with the computer name- loki.cs.kent.edu or hermes.cs.kent.edu; be sure ssh is checked; and if you wish, make the font larger by changing Windows appearance. See slides for a picture.

Login with your departmental username and password. Note the password does not show.

Logging out: Type
logout
Hint: If logout doesn't work, try exit, bye, or quit.

Big Hint: Think lower case at all times! Linux is case-sensitive!
Note- initially learn the commands marked in red.

Using an editor to create files: Typically vi, vim, pico, emacs, or xemacs is used.
See my easy-guide-to-vim.doc
or
http://vimdoc.sourceforge.net/
http://vimdoc.sourceforge.net/htmldoc/usr_toc.html
http://www.xemacs.org/

If you have never used emacs or xemacs, I recommend learning vim which is simple to use. .

Naming a directory in your account:
Absolute name: The entire path such as ~username/aname/bname/cname
Relative name: If you are in aname, you can name bname as just bname or cname as bname/cname

Wildcards: Often file or directory names can be partially specified with wildcards.
? - matches 1 character

Example:
m?file matches mafile, mbfile, etc.
* - matches any number of characters

Example:
m*file matches mafile, mxyzfile, maaaabbbbbccccfile, etc.
ls - list the contents of the a directory

Examples:
ls list contents of current directory
ls -l list contents of current directory along with additional information
ls .. list contents of parent directory
ls ~username/aname/bname list contents of a subdirectory
ls -a list hidden files which start with a period

cd - change directory

Examples:
cd .. move up to the parent directory
cd web move to the directory where you will build your web structure
cd ~username move to the top level of the directory tree for username
cd aname move down the tree to directory aname

mkdir - make a new directory

Example:
mkdir aname aname is created as a subdirectory of the one you are in

rmdir - remove an empty directory - note: It must be empty

Example:
rmdir aname

cat - print the contents of a text file on the screen

Examples:
cat myfile print the text file myfile on the screen
Note: Linux does not require extensions on your files, but you can use them to keep track of the contents.
cat thisfile.txt print the text file thisfile.txt on the screen

tail - print the last 10 lines of a text file on the screen

Example:
tail thisfile.txt

head - print the first 10 lines of a text file on the screen

more - print the contents of a text file on the screen, one screen full at a time.
Advance by hitting the space bar and end by typing q

Examples:
more myfile
… <space bar> (To see another page)
… <space bar> (and another one - as many as you wish)
q (to quit)

rm - remove (i.e.delete) a file (not a directory)

Examples:
rm myfile
rm -i myfile Asks for confirmation that you really want to delete

man someword - look for documentation that contains the specified word - i.e. help

Example:
man ls
Note: To exit man, type a q

apropos someword - searches a database of commands and displays all that use the word in the description of the command. Use to find a command for which you don't know the name.

Example:
apropos rename

pwd - give the path of the working (i.e. current) directory

passwd - change your password. You will be prompted for the old password and twice for the new one. Please select good, strong passwords.

find - locate a file by name. The search can be started at any directory.

Examples:
find / -name myfile.txt -print start searching in root directory /
find . -name myfile.txt -print start searching in current directory

mv - move (rename) file1 to file2

Example:
mv file1 ~username/dir1/dir2/file2

cp - copy file1 to file2

Example:
cp file1 ~username/dir1/dir2/file2

ps - list the process IDs of processes you are running.
Note: If, for example, power is lost during a session, your process won't die on its own or if you kill your Putty window without logging out. When you reenter, use who to see if your username appears twice. If it does, you need to remove the process:

First try a
kill PID where PID is the process ID (take the lower one or you will knock yourself off.)
If that doesn't work, try
kill -9 -1 which kills off all process that you can including your current session.
(System privileged individuals should NEVER use this in superuser mode!)

diff - see the differences between two files

Example:
diff file1 file2

who - list the usernames of other users logged onto the system, when they logged in, and where they were located.

File protections and ls command:
When you do a ls command, you will see entries to the left such as
drwx------
rwxrwxrwx
The entries with a d in front are directories, The second one is a file. (There are other possibilities, but we don't need those here.)

Protection is set in groups of three with
r - has read privilege
w - has write privilege
x - (for files) can be executed; (for directories can cd to it and ls it.
1st group - owner of file
2nd group - group to which owner belongs (we're not really using these)
3rd group - world

So, drwx------ means only the owner can read, write to, and execute (i.e. cd etc.) for this directory.
rwxrwxrwx means everyone can read, write, and execute this file.

chmod - change the protection on a file
u = user
g = group
o = others

Examples:
chmod o+r myfile grant read permission to all
chmod go-rwx myfile deny read, write, and execute permission to my group and others

Pipes:
cmd1 | cmd2| …| cmdk
UNIX/Linux has the philosophy that many small utilities should be provided and the user can then "connect" these through a piping mechanism so that the output of one command becomes the input to another command (provided the two are compatible). There is no limit as to the number of commands that can be strung together this way and, as you might guess, extremely powerful commands can be built with this mechanism.

Examples:
last | tail display the tail (i.e. last 10 lines) of the login file

grep - pattern matcher
This is an extremely powerful command and we will only demonstrate really simple uses here. It is often used in a pipe to select only certain entries.

Examples:
Suppose you want a list of all the times JDoe has logged into the system:
last | grep JDoe
Suppose a file, myfile, contains names of individuals and their phone numbers. You want all lines that contain phone numbers with a 330-672 exchange
grep 330-672 myfile

Redirection - Later