Saturday, 15 October 2011

Vi - Linux Editor Commands

Common vi Commands
Have a look at this list of common vi commands (there are many more, but these will at least allow you to get some basic work done). Then we'll do one more exercise before moving on.
Note: As with all of Linux, vi commands are case sensitive.
Positioning the Cursor
Move cursor one space right.
Move cursor one space left.
Move cursor up one line.
Move cursor down one line.
ctrl-F Move forward one screen.
ctrl-B Move backward one screen.
$ Move cursor to end of line.
^ Move cursor to beginning of line.
:1 Move to first line of file
:$ Move to last line of file
/ Search for a character string.
? Reverse search for a character string.
x Delete the character at the cursor position.
dd Delete the current line.
p Paste data that was cut with x or dd commands.
u Undo.

Basic UNIX Commands

Show current directory
Show content of directory
ls -al
Changing directory
cd <newdir>
Creating directory
mkdir <dir>
Deleting directory if empty
rmdir <dir>
Deleting directory if full
rm -r <dir>
Moving directory
mv <olddir> <newdir>
Copy directory
cp -r <olddir> <newdir>
Show file entry
ls -al <file>
Delete file
rm -i <file>
Move file
mv <file> <path>
Copy file
cp <file> <newfile>
Rename file
mv <oldfile> <newfile>
Show file content at once
cat <file>
Show file content page wise
more <file>
Show file with long lines
cat <file> | fold
Show first 20 lines of file
head -20 <file>
Show last 20 lines of file
tail -20 <file>
Edit file
<editorname> <file>
Edit file with vi
vi <file>
Give all file permissions to yourself
chmod 700 <file>
The above even into subdirectories
chmod -R 700 <dir>
Open file for reading and executing for all
chmod 644 <file>
Starting file as program
<filneame> <arguments>
Find word in file
grep <word> <file>
Find all files which contain a word
grep -l <word> *
Find abstract pattern: ab 2 digits cd
grep 'ab[0-9][0-9]cd' <file>
Comparing two files
diff <file1> <file2>
Updating the date of a file
touch <file>
Giving a specific date to a file
touch 0101010199 <file>
Getting help about a command
man <command>
Find command related to a term
man -k <term>
Where is a particular program if it is in the path
which <commandname>
Is a <name> a unix command or an alias in ksh
whence <commandname>
Making an alias in csh/tcsh
alias <aliasname> '<long_command>'
Making an alias where the arguments go in the middle
alias <aliasneme> '<command> \!* <other>'
Making an alias in sh/bash/ksh
alias <aliasname>='<long_command>'
Using an alias
<aliasname> <arguments>
Use command instead of it's alias
Showing all aliases
Remove an alias
unalias <aliasname>
See environment variables
Setting the term variable if vi doesn't work
setenv term vt100
Opening the X-server for X-clients
xhost +
Setting the display for X-clients
setenv display <computer>:0.0
Telnet to another computer
telnet <computername>
Rlogin to another computer
rlogin -l <username_there> <computername>
Browsing the net with netscape
Check whether someone is logged in somwhere
finger user@host.domain
Check for all people on another computer
finger @host.domain
Talk to another person on another computer
talk user@host.domain
Ftp building up connection
ftp <computername>
Ftp adjusting for binary transfer
Ftp showing directory
Ftp changing directory
>cd /<path>/<path>
Ftp getting a file
>get <file>
Ftp getting multiple files
>mget <filenamecommon>*
Ftp searching for a file
>quote site find <filename>
Get the ip number of a computer
nslookup <computername>
Check whether another computer is up
ping <computername>
Check the pathway to another computer
traceroute <computername>
Info about Unix System
See who is logged on
who ... w ... what
Get the date
See who logged in lately
last -20
See what operating system is there
uname -a
See who you are
Get the name of your computer
See the disk space used
df -k
See you quota usage
quota -v
See how much space all your files need
du -k
Check for mail
Read mail
Compose mail
Mail -s <subject> <mailaddress>
Mail a whole file ( one "<" is real )
Mail -s <subject> <mailaddr> < <file>
Compressing Files
Compress 50%
compress <file>
Uncomress the above file.Z
uncompress <file>.Z
Compress 70%
gzip <file>
Uncompress the above file.gz
gzip -d <file>.gz

Which one is right ?