You are on page 1of 3

=================================

To Execute: ./<program name>


=================================
=================================
To Quit
=================================
esc
:q without saving

:wq with saving

:w to save without quit


=================================
to Copy a File
=================================
Command to copy a file:
cp <sourcefilename> <targetfilename>

Command to move a file:


mv <sourcefilename> <targetfilename>

cp reverse_feed_script.sh reverse_feed_script.sh_copy
=================================
To Delete
=================================
rm mail_test.txt
=================================
Counting Words
=================================
$ wc .rhosts
$ wc -l .profile
$ wc -w .rhosts
$ wc -m .profile
$ wc -w -m test_results
$ wc -wm test_results
$ wc -mw test_results
=================================
Copying Files
=================================
$ cp test_results test_results.orig

If the file test_results.orig exists, the command


$ cp -i test_results test_results.orig

If the destination is a directory, the copy has the same name as the source but is
located in the destination directory
$ cp test_results work/

If more than two inputs are given, cp treats the last argument as the destination
and the other files as sources
$ cp res.01 res.02 res.03 work/
=================================
Renaming Files
=================================
Syntax : mv source destination
$ mv test_result test_result.orig
$ mv -i ch07 ch07.bak
=================================
Removing Files
=================================
Syntax :rm files
$ rm res.01 res.02
$ rm -i hw1 hw2 hw3
=================================
To view the content of a file
=================================
Syntax : cat files
$ cat hosts
=================================
Counting Words ( wc)
=================================
Syntax : wc [options] files
$ wc .rhosts
$ wc .rhosts .profile
$ wc -l .profile
$ wc -w .rhosts
$ wc -m .profile
=================================
changing directory
=================================
Syntax : cd directory
$ cd /usr/local/bin
$ ls /home /usr/local
=================================
Creating Directories
=================================
Syntax :mkdir directory

$ mkdir hw1
$ mkdir /tmp/test-dir
=================================
Moving Files and Directories
=================================
Syntax : mv source destination
$ mv /home/ranga/names /tmp
=================================
Removing Directories
=================================
You can use two commands to remove directories:
� rmdir
� rm -r

$ rmdir ch01 ch02 ch03


=================================
Popular Vi Commands
=================================
1. Esc � While in input mode pressing Esc will change the mode into command
mode
2. i � Goes into the input mode. Start insertion from the current cursor
position
3. a - Goes into the input mode. Start insertion from the current cursor
position + 1 (append)
4. dd � Deletes the current line
5. D � Deletes from cursor to end of line
6. x - Deletes current character
7. dw � Delete a word
8. :w � Perform a save operation
9. :wq � Save and Exit
10. :q! � Discard the changes and exit
11. J - Joining lines
12. ~ - Changing case
13. U � Undoing the last editing instruction
14. dG � Deletes till end of file
15. :w<file> - Save into a different file name