Unix command list

What is UNIX:

UNIX is an operating system. Most people are familiar with Windows, which is also an operating system. An operating system is a program that runs your computer and lets you use the computer. UNIX is different from Windows in that it favors efficiency over user-friendliness, hence the lack of pretty graphics in UNIX. There are many flavors of UNIX, including Apples, Linux and Suns. For more information, just do a search online and you'll find many sites explaining the history of UNIX.


Because of efficiency, the main way UNIX users get around in UNIX is via a command line where you type in commands to tell the computer to do things. Though the lack of point and click may be counter intuitive, this method is actually faster than point-and-click once you become fast at typing out commands.


Getting to UNIX:

If you are on a Windows machine, you can connect to the Computer Science department's UNIX machine. There are two common ways to do this: telnet and ssh. Telnet is not secure and your password can be exposed, moreover some things such as emacs which sometimes does not show up right in telnet. SSH is secure and protects your password, and will usually display things like emacs properly.


Telnet: Go to Start -> Run -> and type : telnet popeye.cs.iastate.edu.

If you are off campus, you have to telnet to isua.cs.iastate.edu first.


SSH: There should be a program called PuTTy on the Windows machine (if not, download it here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). Go to New, put in popeye.cs.iastate.edu for the address and make sure the SSH box is checked. Click connect and you should be prompted for your username and password :-) If you are off campus, see the telnet section above for information on how to connect to popeye.


Common Commands You'll Use Frequently:


cd: means “change directory.” cd directory-you-want-to-go-into

cd .. : this will change your directory up one level. Note the space between cd and “..” For example you can type cd ../../../ to go up 3 levels.

rm: remove a file. rm filename-to-remove

rm -r: remove recursively. This will remove everything including subdirectories. You can use the -r command for lots of other commands.

man: means “manual”, this brings up a help file on any command. eg. man rm. You can press / when in manual mode to search for a particular word or letter.


**Every command has a number of options you can add to it to tune it for the task you want to do. These are called flags. For example the “remove recursively” example above, rm-r, is the command rm with the flag -r to make it remove recursively. Look up a manual or site for complete information on all the flags available to a command.


ls: list the files in the current directory. Usually, directories and files will have different colored text.

ls -l: list the files to include extra information such as “last modified”. Great for proving to a professor you indeed did submit your homework on time. (it's a true story!)


mkdir: stands for “make directory”. mkdir foldername

rmdir: stands for “remove directory” rmdir folder-to-remove


tar: extract tar balls. These are archived files, and they are commonly used with gzip to compress them after archiving (see below). To extract tar files, the most common command is “tar -xvf filename”. To tar up a folder/file, usually “tar -cvf filename” is used. Note that sometimes the computer will decompress gzip for you, so you'll have to modify the flags with the tar command accordingly.


-x stands for extract. -v is “verbose” meaning to print out all the names of the files extracted. -f specifies filename. -c means “create”.


gzip: compress a file. These are UNIX equivalents of zip files in Windows. Commonly used with tar, so you'll often see a linux file named with extension “.gz.tar”


cp: stands for “copy”, use this command to copy files. “cp source destination”. To use the same filename as the source, use a fullstop for the destination, eg: “cp sourcefile .”


mv: stands for “move”. In some flavors of UNIX, you have to use mv to rename a file. For example, mv source destination. To rename, simply do the same except source is the original filename and destination is the new name. Other flavors of UNIX have the command “rename”.


*: this is not a command but a common character you'll use. It most commonly means “wildcard”, for example if you want to delete all files with the filename .jpg, you just have to say “rm *.jpg”.


Text Editors: These are UNIX equivalents of the Windows Notepad, but they have more functionality.

pico: this is probably the most primitive of the text editors available on UNIX. It has the basic functions for saving, editing, opening/finding files.


emacs: brings up the emacs editor. It is a mainly text editor though you can add extensions that let it do things like browse the internet. Emacs functions largely with the keyboard to move around, such as commands to move to the front of a sentence, move to the front of a paragraph, move to the end of a sentence, etc. emacs filename will open up emacs file with the specified filename. It's important to note that if you telnet into UNIX via a Windows machine, emacs will usually not show up correctly. However, emacs will show up fine if you Putty/ssh into UNIX.


Common emacs commands:

ctrl+x then ctrl-c: quit

Ctrl+x then ctrl+f: looks for a file.

ctrl+x then ctrl-s: save

ctrl+z: suspend emacs to go into command line. To return to emacs, press fg.


Ctrl+a: move to beginning of line

Ctrl+e: move to end of a line

Ctrl+v: page down

alt+v: page up.


ctrl+y: paste whatever you have in the “kill ring” (emacs clipboard)

ctrl+k: delete a line after the cursor. Actually you are cutting the line out into the kill ring.

Ctrl+spacebar: set marker. Use your arrow keys to move around and see text being highlighted! Ctrl-spacebar again to end the marker.

Ctrl+w: cuts anything in the parts you markered.

Alt+w: copies anything in the parts you markered.


ctrl+number: ctrl+2 opens up 2 windows. Ctrl+3 opens up 3 windows, and so forth. To move your cursor around windows, use ctrl+o.


Usually when I am programming in emacs I will open up at least 2 windows, one for programming, the other for compiling or looking at other files.


Emacs has a lot of helpful programming options, such as “highlight paratheses”. (F10-> o ->p) Explore!


vi: another UNIX text editor, commonly seen as rival of emacs. It is different from emacs in that for some things like Scheme( a programming language) it will not be completely compatible. Vi also has different commands and modes.


Not so Common Commands (but still good to know)

passwd: change your password.

chmod: change the access permissions on a file or folder. You have do things like “this group can only read not excecute this file”. The mods are given in either 3 digit octal base number (777) or letters like “rwx” (stands for read write execute).


Example: chmod 751 filename

chmod u=rwx, g=rx, o=x filename


Chmod is a command that has many flags and options, you should probably look up a manual or site for indepth information.


more: view a file, for use if you don't want to enter a text editor. Press spacebar to view the next screen of text. more filename.


less: Like the command “more” but gives more options. Unix joke is “less is more”, get it ? :-D

q: quit whatever you were doing. You probably will use this to get out of viewing a file with “less” or “more”.

Ctrl+c: another general “quit whatever you were doing” command.

diff: compare two files to see if they are different. diff file1 file2

 

grep: search for certain letters or words in a file. For example “grep new filename” will search for the word “new” in the the given filename.


kill: forcefully close an application. This is useful for applications that have frozen or applications you can't see. You need a Process ID (pid) to kill a process. You can get the pid by typing “ps”.


For more help, check out these sites:


http://wikipedia.org

This is an encyclopedia site but it will have info on a lot of unix commands. Just type in the unix command into the search box and it should bring up in depth info on the command.


http://www.oreillynet.com/linux/cmd/

O'reilly's list of linux commands and detailed information on the flags.


http://google.com

Internet is full of helpful sites.


This short UNIX help file prepared by JZ Lee ===pv(@o@)vq====

Last modified July 13, 2007. All rights reserved.