Posted by: tonyteaching | August 3, 2008

UNIX Basic Commands

Link to Unix Command dictionary:

http://fosswire.com/wp-content/uploads/2007/08/fwunixre

http://en.wikipedia.org/wiki/List_of_Unix_programs

 

More UNIX tutorial:http://www.ee.surrey.ac.uk/Teaching/Unix/

 

“The Shell” : is the Unix Interpreter

There are many kinds Unix systems –> there are many kinds of Shells

in Infoeng labs: “tcsh” (‘tee-see-shell’)

UNIX Command Form:

command options parameters

 

we can use command without or more than one options and parameters

we can also use more than one commands by using PIPE syntax

Typically, the command: Acronym of full description of the command

REMEMBER THESE UNIX COMMANDS:

CHECKPOINTS

add_ict1 ………………..for Tutor to add check point (this command will be responded by question ‘what checkpoint numbers want to check’ and user+password the Tutor (Tutor needs to ask Topic Coordinator that He has setup access for him, and ask about the username and the password?)

or if the tutor wants to add more than one check points (max 31)

checkpoints -D comp1301

show_ict1 …………………to show how many checkpoints the student (who login using the workstation) has.

To Change Password

passwrd

0. man or whatis or man -f (View the MANUAL)

————————————————————————————————–

man ls “view manual of ls command (completely)”

man -f “view just brief summary of the manual (1 line)”

man -f ls

whatis “summary the manual”

man -f

whatis ls

man -k “view summary manual related to a keyword”

man -k ls

1. ls (List the directory contents)

————————————————————————————————–

ls “list the Directory contents”

(the Unix directories will be hiden – started with ‘.’)

ls -al “list the Directory contents”

(included Unix directories)

ls -l “list the directory contens with Long (-l) format (each file’s permissions, modification date,size, owner)

ls -l aku.txt “list detail of the file ‘aku.txt’ (parameter) with Long format”

ls -l aku “list the contents of the Directory ‘aku’ (parameter) with Long format”

ls -R “list the content of a tree directories (Root Structure)”

2. talk (chatting)

————————————————————————————————–

talk susa0004 “call username (susa0004) in the same server”

talk susa0004@upnyk.ac.id “call susa0004 on different server (upnyk.ac.id)”

^c (control c) “break the connection”

to establish the connection, susa0004 should reply with typing the same

talk marl0024 (if your username ‘marl0024’)

if you want to know what is your Server’s Name: hostname

 

if you want to know who are log in the current Server : who

calender : cal

3.history (view the list of previous commands that we have typed)

—————————————————————————————————

history “view the list of previous commands”

!! “repeat the previous command”

or with ARROW keys

!23 “repeat the command number 23”

4.TEXT EDITING

—————————————————————————————————

To Create/write the file can use NotePad or CDE Editor

more Tony.txt “display the contents (more) of file Tony.txt”

(‘more’ command is just .txt file)

cp Tony.txt otherTony.txt

“copy (cp) file ‘Tony.txt’ in the same directory with name ‘otherTony.txt'”

5. PRIVILEGES of a file

—————————————————————————————————–

when we show all information about a file with “ls -l thefilename”

There are 3 privileges:

read (r)

write (w)

executable (x)

There are 3 seperate groups of file users

-rwx—rwx

The user themselves(u) The specified group of users(g) Any other user(o)

chmod “change mode of the priviledge”

chmod g+rw Tony.txt

“change mode: Add for Group READ WRITE priviledges for file Tony.txt”

the file’s privileges will be

-rwxrw-rwx

chmod o-rwx Tony.txt

“change mode: Erase for Other user READ WRITE EXECUTABLE priviledges for file Tony.txt”

the file will be

-rwxrw—-

6. Files and Directories

—————————————————————————————————

pwd

“print work directory – to show what the current working directory is?”

CHANGE DIRECTORY

—————-

cd ~ “back to home directory”

cd ~/ict1 “back to home directory and move to ict1 directory”

cd /opt/teaching “move to directory ‘opt’ and further move to subdirectory ‘teaching'”

cd . “move to current directory”

cd .. “move to Parent directory/ 1 step closer to the root”

MAKE DIRECTORY (mkdir)

———————-

mkdir unix “make directory ‘unix’ in current directory”

COPY FILE (cp)

———————-

cp /opt/teaching/pracs/prac11/office.txt .

“copy file ‘office.txt’in specific directory to active/current directory with the same name”

cp /opt/teaching/pracs/prac11/office.txt ..

“copy file ‘office.txt’ to parent directory of active directory with the same name”

cp /opt/teaching/pracs/prac11/office.txt ~/data/office_baru.txt

“copy office.txt to directory ‘data’ with new name ‘office_baru.txt'”

MOVE/RENAME FILE (mv)

———————-

mv current_map.ps old_map.ps

“rename ‘current_map.ps’ to be ‘old_map.ps’ in same directory”

mv current_map.ps ../old_map.ps

“rename ‘current_map.ps’ to parent directory with new name ‘old_map.ps’

mv current_map.ps rubbish

move ‘current_map.ps’ to ‘rubbish’ directory

so when using mv command, if the targeted file followed by

another file‘s name –> Rename

directory name –> Move

DELETE/REMOVE (rm) (rmdir)

—————————

rm rubbish/old_map.ps

“remove/delete file ‘old_map.ps’ in directory ‘rubbish'”

rmdir rubbish

“remove/delete directory ‘rubbish'”

7. PRINT (lp)

—————————————————————————————————

lp [-d printername] [options…] filename

-os : single sided

-od : double sided

-o4d : 2 pages per side

example:

lp -d max -os office_map.ps

“print’office_map.ps’ file to ‘max’ printer with simplex output”

lpstat -R “check the status the print job”

8. Wild character

—————————————————————————————————

? one any character

* zero or more characters

mv T* ~/data

“move all file in current directory started ‘T’ to directory ‘data'”

mv a8 a9 10 ~/data

“move three data a8,a9,a10 to ‘data’ directory”

ls ??

ls a*c.*

ls a* *c

ls a? ?c

ls b? ?b b?? ?b? ??b list all files that contain a ‘b’

ls *b*b*

9. FILTERS and PIPES

—————————————————————————————————

sort Tony “sort the lines of ‘Tony’ file into alphabetical order”

sort < Tony > Tony_sorted “sort input from ‘Tony’, output to ‘Tony_sorted'” (automaticaly Unic create the new file ‘Tony_sorted'”

“PIPES” : combination of Filter Commands

—————————————-

sort < Tony | nl ” sort file ‘Tony’ then numbering the lines”

sort -r “sort reverse”

grep c < /usr/dict/words | wc ” search the line which contains ‘c’ character from file ‘words’ then count the number of characters, words, and lines”

wc < /opt/teaching/comp1101/pracs | sort | head -1 “Word Count the files in directory ‘pracs’, Sort the files based on word count, then display the first line (the fewest lines)”

SORT INPUT FROM KEYBOARD:

————————-

sort (then press ‘return’)

(type) alpha (then press ‘return’)

(type) bravo (then press ‘return’)

(type) charlie (then press ‘return’)

(type) delta (then press ‘return’)

(type) echo (then press ‘return’)

10. DISPLAY THE FILE CONTENT

—————————————————————————————————

cat file1 [file2 …] “display the contents of file1” (CAT only is available for text files: mail message, source code, web page,…)

more file1 [file2 …] “display *.txt file”

Note: This file can be download here unixbasiccommands


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: