Vi Editor Commands 11111

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

UNIX COMMANDS FILE COMMANDS DIRECTORY COMMANDS SYMOLIC LINKS TERMINAL COMMANDS HELP COMMANDS INFORMATION COMMANDS USEFUL

CSHELL SYMBOLS PERMISSIONS AND FILE STORAGE (UNIX) PERMISSIONS AND FILE STORAGE (ANDREW) PROCESSES PRINTING ENVIRONMENT CUSTOMIZING NETWORKING X-APPLICATIONS UNIX FILTERS

This handout is a quick reference for useful unix commands. It is not complete nor is it intended to replace manual pages or unix books.

Recomended Reference : Unix in a Nutshell.

Orientation 2002

FILE COMMANDS
touch Create a new file. Usage: touch <filename> Usage: Copy files. Usage: cp [options] <source-filename> <destination-filename> cp [options] <source-filepath > <destination filepath> Options: -r recursively copy directory structures.

cp

mv

Move or Rename files or directories. Usage: mv [options] <old-filepath> <new-filepath> mv [options] <old-filename> <new-filename> Options: -i query user for confirmation. Remove files. Usage: rm [options] <filname> Options: -r recursively remove directory structures. -i query user for confirmation. View complete file content. cat <filename> View file contents in sections determined by the size of the terminal. Usage: more <filename> View file contents in sections determined by the size of the terminal. Has more options and search features than more. Usage: less [options] <filename> Reduces the size of the file. and adds the extension .Z Usage: compress <filename>. Restores a compressed file. Usage: uncompress <filename> Usage:
2

rm

cat

more

less

compress

uncompress

Orientation 2002

gzip

Compresses files and adds the .gz extension. provides more compression than compress. Usage: gzip [options] <filename> Options: -d expands a compressed file. Expand files compresses by gzip. Usage: gunzip [options] <filename.gz> Options: -c write on standard output and keep file unchanged. Expands a file (compressed by gzip or compress) and sends it to standard output. Original file remain unchanged. zcat <filename> Archives and extracts files to and from a single file called a tarfile. Usage: tar [options] <archive-directory> <filename> Usage: tar [options] <filename> Options: x Extracts the file. c creates a new tarfile r appends files into a tarfile. f stores files in or extracts files into an archive. f - store outcome in standard output or input , used for redirection. Eg: tar cf ~hoda/archive myfile.tar to archive a file Eg: tar xf filename.tar to extract a file

gunzip

zcat

tar

DIRECTORY COMMANDS
cd Change directory. Usage: cd <filename> Eg: cd my-directory cd go to home directory cd .. go up one directory cd go backwards to the last directory visited. Print working directory on the terminal. List the content of a directory. Usage: ls [options] or ls [options] <directory-path> Options: -l list all files in long format.
3

pwd ls

Orientation 2002

(permissions, users, filesize,date, and time are displayed). -a list all files including those beginning with a . -F list files distinguishing directories/ executables* symbolic links@ -R recursively list subdirectories encountered. mkdir Create a new directory. Usage: mkdir <directory-path> Remove a directory if its empty. Usage: rmdir <directory-path>

rmdir

SYMBOLIC LINKS
ln Create symbolic links between files or between directories. Usage: ln [options] <filepath> <link-name> ln [options] <directorypath> <link-name> Options: -s allows linking across file systems and allows the display of the links name upon ls -l. Eg: ln -s course-file mylink Eg: ln -s course-directory mylink

TERMINAL COMMANDS
clear echo: Clears the terminal. Write a string to standard output. Usage: echo string or echo string Repeats commands. Usage: repeat <number> <command>

repeat

HELP COMMANDS
man Displays the manual page for the selected command. Usage: man <command-name>
4

Orientation 2002

help

Opens the default web browser in the andrew unix help web site. http://polaris.andrew.cmu.edu/help/sys=sun4_55/env=gamma/TopPage Displays the man page and help files ont he terminal. Usage: rtfm <command-name>

rtfm

INFORMATION COMMANDS
history Lists the commands typed during the session. Options: -r displays the list in reverse. Displays the computers or servers name on the terminal. Displays who is on the system. Displays the invoking user.

hostname who who am i

wc

Counts and displays the number of lines, words and characters of a file. Usage: wc [options] <filename> Options: -c count character only. -l count lines only. -w count words only. to be completed by students to be completed by students Displays the command description. Usage: whatis <command> to be completed by students to be completed by students

date cal whatis

whereis which

Orientation 2002

id tty uname

Displays the user id and the group id of the invoking user. Displays users terminal name. Displays the current unix system name. Options: -n gives the computer name

USEFUL CSHELL SYMBOLS


| Pipe the output of a command to be processed by another command. Usage: command1 |command2 Eg: ls -l | more more file-name | grep pattern more filename | wc Redirect output........ to file (overwrite ). Usage: command > filename Eg: wc filename > new-file Append (the result of the command) to the end of the file. Usage: command >> file-name Eg: pwd >> existing-file Take the input for the command from a file. Usage: command1 < filename. Run process in the backgound so that the shell remains active. Usage: program-name & program-name filename & Separate commands on the same line. Usage: command1 ; command2 Eg: pwd ; ls Match a string of zero or more characters. Eg: cp * copy all files
6

>

>>

<

&

Orientation 2002

cd publ* cd *tory cp *.* ?

go to any directory that begins with publ go to any directory which ends with tory copy all files that contain a dot

Match a single character. Eg: grep d?n filename display all lines that contain dan, don, din, dgn, ect.

[]

Match any of the enclosed characters. Eg: grep [abc] filename grep [a-z] filemane Hyphen is used to specify a range. Anything thats starts with a $ is a variable. Begin comments (used in the Cshell script files). Home directory symbol. Eg: cd ~ go to home directory of the current user. cd ~rob go tot home directory of user rob. Home directory . The history commands. !! Redo last command. !str Redo the last command that starts with str. !23 Redo the 23rd command. !-2 Redo the (last command -2) Quick modifier for the last command. Usage: ^mistake^correction. The logical and symbol : execute first command then if successful, the second command. Usage: <command1> && <command2>
7

$var # ~

$home !

&&

Orientation 2002

||

The OR symbol : executes the first command or, if it fails, the second command. Usage: <command1> || <command2> Runs a compiled program. Usage: ./ program-name

./

PERMISSIONS AND FILE STORAGE (UNIX)


chmod Set the permission on a file or a directory. Usage: chmod [options] <who> <opcode> < permission> <filename> Options: -R Recursively updates permisions within a directory structure. Who: u user g group o other a all Opcode: + add permission. remove permission. Permission: r read w write x execute Eg: chmod a +rwx public-file adds permissions of read write and execute to all. Eg: chmod go -wx my-file removes write and execute to group and others. Change the password. Displays the amount of free and used disk space. Displays the amount of disk usage. Displays the amount of disk space used. Options: -v Display user's quota on all file systems.

passwd df du quota

Orientation 2002

PERMISSIONS AND FILE STORAGE (ANDREW)


fs quota fs lq Checking your percentage disk usage on your andrew account. Lists the amount and percentatge of disk usage on your andrew account. Lists access control lists for directories. Usage: fs la or fs la <directory-name> Sets access control lists for directories. Usage: Usage: fs sa <directory> <user> <permission> Eg: Eg: fs sa <directory-name > system:anyuser rl. Permissions: r l i d w a

fs la

fs sa

read list insert delete modify administrative

PROCESSES
ps Displays the active processes. Includes the process number, process name and process time. Options: -a Terminates a process. Usage: kill [options] <process-number> Options: control z bg
Orientation 2002

kill

-9

absolute kill.

Stops a current process. Restarts process in the baground.


9

exec

Executes a command in place of the current shell which terminates. Usage: exec command-name.

PRINTING
lpr Sends a job to the printer. Usage: lpr- P <printer-name> <file-name> Options: -n specifies the number of copies. Eg: lpr -P triglyph -3 myfile prints 3 copies of myfile on trilyph Displays the printer queue including the job number. Usage: lpq -P <printer-name> Removes a job from the printer queue. Usage: lprm -P <printer-name> <job-number>

lpq

lprm

print

Sends the job to the printer. Usage: print -P <printer-name> <file-name>

ENVIRONMENT
env Show all the environment variables. Usage: env Some Environment variables: HOME : home directory PATH: search path for commands TERM: terminal type USER: username DISPLAY: the name of the machine to which the display is sent. SHELL: the current shell PWD: the current directory. EDITOR : the default text editor Show all or specified environment variable. Usage: printenv printenv <variable-name> will print only this variable

printenv

Orientation 2002

10

setenv

Sets a particular environment variable. Usage: setenv <variable-name> <value> Eg: setenv EDITOR emacs. setenv DISPLAY bernini.arc.cmu.edu:0.0

CUSTOMIZING
alias Creates a shortcut for a command or series of commands. Usage: alias displays all specified aliases. Usage: alias <shortcut> <series of commands> To include command line arguments in the alias \!* for the all command line arguments \!^ for the first argument \!$ for the last argument Eg: alias h history alias janus xhost + ; telnet janus.arc.cmu.edu alias rm rm -i alias my-term xterm -title \!* -bg ivory -fg black

unalias

Removes the alias from its bound commands. Usage: unalias <shortcut>

set

Sets variables in current shell. Usage: set <variable>=<value> echo $variable will print out the value of the variable. Usage: set: displays all the set variables in the shell. Removes value form the variable. Usage: unset <variable> Set the option for a terminal. Usage: stty erase <desired-key> character erase stty kill <desired-key> whole line erase stty werase <desired-key> word erase

unset

stty

Orientation 2002

11

set filec

If filec is set, any partially typed filename can be expanded to its full name whenever esc key is pressed. Usage: set filec Sets the prompt of the terminal. Usage: set prompt=<value>. Eg: set prompt=[hoda] set prompt="\!% will show command number set prompt="<`pwd`> " will show working directory Change Shell. Usage: chch <username> <newshell> Eg: chsh hoda tcsh. Reads commands from a file. Used to reload an updated .cshrc file into the current working shell. Usage: source filename.

set prompt

chsh

source

NETWORKING
telnet Connects to a remote computer. Essential telnetting steps: xhost + telnet <remote-hostname> setenv DISPLAY <local-hostname>:0.0 Eg: telnet janus.arc.cmu.edu Gives permission to all clients to establish remote connections with a server and display its output to its terminal. Usage: xhost + xhost - removes permision from all clients. Allows the remote host to display its x-applications onto the local terminal. Usage: setenv DISPLAY <local-hostname or IP address>:0.0; Eg: setenv DISPLAY bernini.arc.cmu.edu:0.0 setenv DISPLAY 128.2.120.96:0.0

xhost +

setenv DISPLAY

Orientation 2002

12

ftp

File transfer program: Allows the get and put of files between computer accounts. Usage: ftp <remote-hostname> Inside ftp: put <local-filename> get <remote-filename> mget <filename>gets multiple files. eg: mget * mput <filename> puts multiple files. eg mput * lcd changes the local directory. help lists all ftp commands. quit or bye exits ftp. Display information about local or remote users. Usage: finger <user-name> finger <user-id>

finger

talk write

to be completed by students to be completed by students.

X-APPLICATIONS
xterm Opens a terminal window. Options: -name gives a name to the terminal. -title displays a title on the terminal. -bg specifies background color. -fg specifies foreground color. -e gives a command to be executed. -g specifies the geometry in the format . <length> x <width > + <x-coord> + <y-coord of top left point> Eg: xterm -name janus -title janus -bg ivory -fg blue & xterm-e telnet janus.arc.cmu.edu & xterm -g 90x28+640+600 &

Orientation 2002

13

xclock dclock

to be completed by students Displays a digital clock. Options: -bg - fg - g -date Eg: dclock -date "%d %m %y" & Opens emacs editor. Usage: xemacs & xemacs filename &

xemacs / emacs

UNIX FILTERS
grep Search a file for a matching pattern or regular expression. Usage: grep [options] <regular-expression> <file-name> Options: -n print lines and line numbers -v prints all the lines that do not contain the expression. Eg: grep [a-z]*.C filename grep *[SITE]* filename A variation of grep that maches a text-string and does-not support regular expressions. Eg: fgrep <string> <file-name> to be completed by students to be completed by students to be completed by students to be completed by students Search the system for filenames. Usage: find <pathname> <condition> Eg: find /home/hoda -name seed Splits a file into several files of equal length. Usage: split [options] <filename> <outfile>. Options: -n specifies the number of lines per file. Another variation of split is csplit which splits the file using a speci14

fgrep

spell sort head tail find

split

Orientation 2002

fied expression as a splitting point. cmp Compare 2 files. Usage: cmp <file1> <file2> Reports the lines that differ between 2 files Usage: diff <file> <file2> A database operator that joins the common lines of two sorted files. Usage: join <file1> <file2>

diff

join

Orientation 2002

15

You might also like