Professional Documents
Culture Documents
Basic Command Unix PDF
Basic Command Unix PDF
Practice. Login your user and change password to new one. Do not
practice this command with root user.
# passwd
Practice. Login your user, and check current being user. su to be root,
and check that your user is changing to root. Logout user root, and check
your user again.
# whoami
# su
# whoami
# exit
# whoami
3. Directory Command
ls : List the contents of a directory
ls option dirname lists content of dirname directory. If dirname is omitted, it lists
current directory. Option l gives a more information showing file type, size, owner
and modification date of each file, option -la lists all files including those filenames
begin with a dot such as . , .. (. represents current directory, .. represents parent
directory).
cd : Change to a directory.
cd dirname move working directory to dirname directory. If dirname is omitted, it
will move back to home directory.
pwd : Show current working directory
It prints out current working directory.
Practice. Change directories and check where you are. Notice where is
your home directory.
# cd
# pwd
# cd ..
# pwd
# cd /etc
# pwd
# cd
# pwd
Following are commands you can use to manipulate your text file, make sure you use
them in command mode only. (Press ESC to get to command mode)
Saving and exiting vi
Save file and exit vi
Exit vi
Exit vi without saving file
Save file to name filename
:wq!
:q
:q!
:w filename
Entering text
To type text into file, you must enter insert mode. Choose the command that is best suited
to the present position of the cursor and the editing task you want to do. After you type
any of these letters, you will be in Insert mode and everything you type will be inserted
into text file. Once finish inserting text or want to use any vi commands, press the ESC
key to back to command mode.
Insert text after cursor
Insert text before cursor
Append text at the end of current line
Insert text at the start of current line
Open a new line below current line
Open a new line below current line
a
i
A
I
O
o
Deleting text
Delete current character
Delete current word
Delete current line
Delete next N line
Undelete a word or a line
x
dw
dd
Ndd
p
0
$
1G
G
NG
yy
Nyy
p
Search text
Search pattern
Repeat previous search
/pattern
n
Replace text
Replace pattern1 with pattern2 on
the same line
Replace every pattern1 with
pattern2 on the same line
Replace every pattern1 with
pattern2 in whole file
:s/pattern1/pattern2
:s/pattern1/pattern2/g
:g/pattern1/s//pattern2/g
VI Exercise
Ex 1. At your home directory, create a new file test1 which contains following 2 lines,
save and exit.
Hello, This is my vi test file
SOI Asia project stands for School of Internet Asia project
Ex 2. Edit file test1 to contain following content. Change content on first line by using
command x to delete unwanted characters and then inserting desired texts. Then use
G to go to last line and press o to insert text at the last line..
Hello, This is my second practice
SOI Asia project stands for School of Internet Asia project
And I am one of operator team member of SOI Asia project
Ex 3. Search all occurrences of word project in file test1 using command / and n.
Ex 4. Replace all occurrences of word project with word activity, save to new file
name test2. Check that content of file test1 and test2 are different.
Ex 5. Edit file test2 and delete the last line using command dd. Then copy remaining
2 lines and paste it 5 times. Now test2 will contain following content, save but dont
exit vi.
Hello, This is my second practice
SOI Asia activity stands for School of Internet Asia activity
Hello, This is my second practice
SOI Asia activity stands for School of Internet Asia activity
Hello, This is my second practice
SOI Asia activity stands for School of Internet Asia activity
Hello, This is my second practice
SOI Asia activity stands for School of Internet Asia activity
Hello, This is my second practice
SOI Asia activity stands for School of Internet Asia activity
Ex 6. Moving to Line 7 of file test2 using command 7G and delete last 4 lines of file
by command 4dd and then undelete using p.
Ex 7. Copy and paste first line 3 times, save and exit. Final content of file test2 is
Hello, This is my second practice
Hello, This is my second practice
Hello, This is my second practice