The Joy of Unix

changing your password | navigating the shell | files & directories | permissions | other people | special characters | OOOPS | text editors | compilers
| return to resources |

 
Changing your password:
passwd Do this ASAP!

Cruising the Shell:
cd moves you to your home directory
cd directoryname moves you to that directory named directoryname
cd .. moves you to the parent of the current directory
pwd displays the path of the working (current) directory
ls displays a listing of files in the current directory
ls -a displays all files, including hidden files such as .profile and .login *
* Attempting to modify any of these special files can wreak havoc on your environment if you don't know what you are doing!
ls -l displays more information on each file, including permissions
r command r will search command buffer as you type and will substitute a match.. can save time when executing same command many times
clear clears the screen
script filename starts a log file of your Unix session and writes it to filename. end the script by typing control-d
man commandname displays documentation for that command, use space bar to move f rom page to page
man -k word displays all commands where word is a keyword
help commandname similar to man, less technical
exit End the Unix session.
logout may also work

Working with Files and Directories:
pwd
displays your present directory
mkdir directoryname creates a subdirectory off of the current directory named directoryname
rmdir directoryname removes the directory named directoryname from the current directory (the directory being removed must be empty first)
cp filel file2 copies filel to file2
cp -i filel file2 copies filel to file2. prompts for confirmation if file2 already exists
cp fname dname copies file fname into directory dname
mv fname dname
moves file fname into directory dname
mv fname1 fname2
renames file fname1 as fname2
rm filename deletes filename
rm - i filename prompts for y or n before deleting file
lpr ppname fname prints the file fname to the printer pname
lpq -ppname shows the printer queue (including job numbers) for pname
lprm ppname jobnumber removes job number jobnumber from pname's job queue
more filename shows the contents of filename, one page at time, use the spacebar to see the next page, q to quit....
ex:  ls –l | more also can be used as a "pipe" to control system output
page filename a little more versatile than more, press ‘-' to go back a page or type a number to go to that page
cat filename will display contents of filename
cat file1 file2 > file3 concatenates file1 and file2 into file3

Permissions:
Access to files and directories is controlled through the granting and revoking of permissions. You must have permission to read (r), write (w) or execute (x) a file (even your own!), and similarly you must have permission to view filenames (r), add or delete files (w), or search through (x) a directory. The owner (creator) of a file or directory can assign permissions to himself, to all members of a specific group, or to everyone. You can view permissions for files by performing a long listing (ls -l).
The permissions will look something like this: _rwxrw_r_ _
The first space is only there to differentiate different types of objects (blank for file, d for directory, l for a link). The following three characters (r w x) are the permissions for the owner aka user (u) of the file. In this case the user has read (r), write (w) and execute (x) permissions. The next three characters (r _ _) are the permissions for other members of the owner's group (g). They have permission to read (r) and write (w). The last three characters are the permissions for everyone else (o). They only have read (r) permission.
chmod u=rwx,g=rw,o=r filename Sets the above permissions for filename
chmod o+w filename Grants write privileges for filename to others
Octal notation: Each group of 3 permissions is assigned a 3 digit binary value: 22 21 20 r w x 
for example:
_ _ _= 0 = no permissions 
_ _ 1 = 1 = execute permission only 
_ 1 _ = 2 = write permission only 
1 _ _ = 4 = read permission only 
1 _ 1 = 1 + 4 = 5 = execute and read permission only 
1 1 1 = 4 + 2 + 1 = 7 = read, write and execute permissions.
chmod 777 filename Grants all permissions to everyone for filename, using octal notation

In general, your directory permissions should be set to: r w x _ _ _ _ _ _ (700). Permissions to your no non-executable files should be set to r w _ _ _ _ _ _ _ (600), and permissions for executable files should be set to r w x _ _ _ _ _ _ (700). This will protect your work from being copied or vandalized by others.

Other People:
finger username
Will display when username was last on, if they have mail, and their profile.
talk username
Displays if username is on, if so allows you to write back and forth in real time.

Special Characters:
The following characters have special meaning in Unix and should not be used in filenames: & ; | * ? ' " [ ] ( ) $ < > { } ^ # \ / 

OOOPS:
If you need to stop a currently executing command (process),
kill anumber kills the process with the PID number anumber.
ki1l -9 anumber kills the process and all associated processes.
ps -u username displays all current processes (and their PID's) belonging to username
ps -lu username displays more info about username's current processes
control-u kills the current command line (before you hit enter)
control-c may interrupt the current process
control-d exits some processes (such as script)
control-z sends a process to the background
control-h, backspace, delete erase a character

Being a VIP (a VI (editor) Person)
vi One of the most powerful text editors in the UNIX environment.
Some of the most common VI editing commands

Other Editors:
pico Easy to use, multiline editing capability. 
Editing commands are a subset of the emacs commands
emacs Very powerful development environment, including a text editor.

Compilers:
Gnu Compiler:
g++ filename.cpp Compile filename.cpp and create an executable file, a.out
g++ -c filename.cpp Compile only (create object file)
g++ -Wall filename.cpp Compile filename.cpp and list all warnings
g++ filename.cpp -o newname Compile filename.cpp and create executable newname
HP Compiler:
Check the online manual (man CC)

<== Return to Resources