Examples

This is a list of examples on various topics covered during the course. You will see the prompt "tree1:~>" in all the examples, simulating that we are logged onto the machine named tree1. Your prompt will most likely not have "tree1" but the name of a different computer. The user in these examples is joesmo. The first line is the command being demonstrated, followed by subsequent command prompt(s) that display the result.

File System Commands

pwd shows you to print your working directory.
tree1:~> pwd
tree1:~> /afs/ir.stanford.edu/users/j/o/joesmo

ls lists the files and directories (called subdirectories) within your present working directory.
tree1:~>ls
tree1:~> APPLES happy.txt secret.txt FRIENDS
ls -l is used the same way and displays full information, including access information.

cd allows you to change directories. Let's move to the subdirectory APPLES.
tree1:~> cd APPLES
tree1:~/APPLES>
Using cd . will always return you to your home directory. Using cd .. will take you to the directory one level up (the directory in which your current directory is in). mkdir (making a new directory) and rmdir (deleting a directory) work the same way.

mv allows you to rename a directory or move it elsewhere. Let's move a file called fruit.txt in the APPLES directory into our home directory ("~").
tree1:~/APPLES>mv fruit.txt ~
tree1:~/APPLES>cd .
tree1:~>ls
tree1:~>APPLES happy.txt secret.txt FRIENDS fruit.txt

cp allows you to copy a file. Let's copy fruit.txt to pear.txt
tree1:~>cp fruit.txt pear.txt
tree1:~>ls
tree1:~>APPLES happy.txt secret.txt FRIENDS fruit.txt pear.txt

rm allows you to delete a file. Let's delete pear.txt.
tree1:~>rm pear.txt
tree1:~>ls
tree1:~>APPLES happy.txt secret.txt FRIENDS fruit.txt

more displays a file until the screen is filled and then displays the next screen when you hit space.
tree1:~>more fruit.txt

this is a paper about fruit.
x
x
x
x
x
x
x
x
--MORE--(34%)
less has the same syntax, but allows you to move forward and back through the file.

Setting Permissions
There are two ways to set permission. Here are examples of both ways. We are simulating setting permissions for fruit.txt.

chmod-method 1.
tree1:~>chmod u=rwx go=r fruit.txt
tree1:~>ls -l fruit.txt
-rwxr--r-- 1 joesmo 37 22016 Oct 8 01:29 fruit.txt

chmod-numerical method. (r=4, w=2, x=1)
tree1:~>chmod 744 fruit.txt
tree1:~>ls -l fruit.txt
-rwxr--r-- 1 joesmo 37 22016 Oct 8 01:29 fruit.txt

Transferring files through FTP

An FTP scenario - getting a file mm.txt and sending a file fruit.txt
tree1:~>ftp transfer.stanford.edu
Connected to transfer.stanford.edu.
220 transfer.Stanford.EDU FTP server (Version 4.162 Tue Nov 1 10:50:37 PST 1988) ready.
Name (transfer.stanford.edu:joesmo): joesmo (*or press enter*)
331 Password required for joesmo.
Password: (*enter password, typing is hidden and will not show up on screen*)
230 User joesmo logged in.
ftp> cd /afs/ir.stanford.edu/users/t/h/thumper
250 CWD command successful.
ftp>ls
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
mm.txt
peek.txt
PEN
FILES
226 Transfer complete.
116 bytes received in 0.063 seconds (1.79 Kbytes/s)
ftp>get mm.txt (*leave local name blank if you want it to be the same as the remote name)
local: mm.txt remote: mm.txt
22027 bytes received in 0.035 seconds (607.87 Kbytes/s)
ftp> put fruit.txt
local: fruit.txt remote: fruit.txt
22027 bytes sent in 0.0046 seconds (4692.57 Kbytes/s)
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
mm.txt
peek.txt
PEN
FILES
fruit.txt
226 Transfer complete.
116 bytes received in 0.063 seconds (1.79 Kbytes/s)
ftp>quit
221 Goodbye.
tree1:~>ls
tree1:~>APPLES happy.txt secret.txt FRIENDS fruit.txt mm.txt

(Un)Compressing and (Un)Archiving Files

tar cvf - creates archives with little compression.
tree1:~> tar cvf new.tar fruit.txt happy.txt secret.txt
fruit.txt
happy.txt
secret.txt
tree1:~>ls
tree1:~>APPLES happy.txt secret.txt FRIENDS fruit.txt mm.txt new.tar

gzip - compresses files
tree1:~> gzip new.tar
tree1:~>
tree1:~>ls
tree1:~> APPLES happy.txt secret.txt FRIENDS fruit.txt mm.txt new.tar.gz

tar xvfz - uncompresses and unarchieves (z as a switch = gunzip)
tree1:~> tar xvfz new.tar.gz
fruit.txt
happy.txt
secret.txt


[The Birth of UNIX] [How the Organization Works] [Navigating through UNIX] [Transfering Information Through Middlemen] [Exercising UNIX Influence at Home] References]
© Tina Hsiu-man Young, Nov. 1999

1