Handout 7

Some Necessary Unix Commands I


Directory Listing

ls -al # list all files, long listing

What Directory am I Currently In

pwd # show present working directory

List the Contents of a file

cat file_name # list the contents of file file_name

Change Current Directory

cd directory_name # change pwd to directory_name (relative to pwd)

cd # return to users home directory

cd .. # move up one level (parent)in the directory tree

cd . # don't move

cd / # move to root (/) directory

cd ./directory_name # move to directory directory_name relative to pwd

cd ../directory_name # move to directory directory_name relative to parent of

# pwd

note: "." represents the current directory, ".." represents its parent

Delete a File

rm file_name # remove file file_name

Delete a Directory and All Files in It

rm -r directory_name # remove directory directory_name and all files in it

Create a Directory

mkdir directory_name

What is My Search Path

echo $PATH # note that $ is required to specify contents of variable PATH

set # show all environment variables (sh and ksh)

note that $ is required to specify contents of variable PATH

Reset My Search Path

PATH=/bin:/opt/bin:/usr/bin:/usr/ccs/bin:/usr/ucb:.

export PATH # make PATH available to subshells

. .profile # reset initial login definitions

Stop Current Process

<cntl> c

Change File Permissions

chmod 700 file_name # give file file_name read/write/execute permission to user

chmod 444 file_name # give file file_name read permission to user/group/world

chmod 001 file_name # give file file_name execute permission to world

chmod 777 file_name # give file file_name read/write/execute permission to

# user/group/world

Who is Logged On

who # show who is logged on

Output a Page At A Time

cat file_name | more # pipe output from cat to more

Translate Characters

tr "A-Z" "a-z" < file_name # convert all uppercase letters to lowercae in

# file file_name

tr ",:" "\011" < file_name # convert all commas to tabs in file file_name

cat file_name | tr ",:" "\011" # convert all commas to tabs in file file_name