UNIX Commands

VI Commands

General Startup
To use vi: vi filename
To exit vi and save changes: ZZ   or  :wq
To exit vi without saving changes: :q!
To enter vi command mode: [esc]

Counts
A number preceding any vi command tells vi to repeat
that command that many times.

Cursor Movement

h       move left (backspace)
j       move down
k       move up
l       move right (spacebar)
[return]   move to the beginning of the next line
$       last column on the current line
0       move cursor to the first column on the current line
^       move cursor to first nonblank column on the current line
w       move to the beginning of the next word or punctuation mark
W       move past the next space
b       move to the beginning of the previous word or punctuation mark
B       move to the beginning of the previous word, ignores punctuation
e       end of next word or punctuation mark
E       end of next word, ignoring punctuation
H       move cursor to the top of the screen
M       move cursor to the middle of the screen
L       move cursor to the bottom of the screen

Screen Movement

G        move to the last line in the file
xG       move to line x
z+       move current line to top of screen
z        move current line to the middle of screen
z-       move current line to the bottom of screen
^F       move forward one screen
^B       move backward one line
^D       move forward one half screen
^U       move backward one half screen
^R       redraw screen ( does not work with VT100 type terminals )
^L       redraw screen ( does not work with Televideo terminals )

Inserting

r        replace character under cursor with next character typed
R        keep replacing character until [esc] is hit
i        insert before cursor
a        append after cursor
A        append at end of line
O        open line above cursor and enter append mode

Deleting

x       delete character under cursor
dd      delete line under cursor
dw      delete word under cursor
db      delete word before cursor

Copying Code

yy      (yank)’copies’ line which may then be put by
the p(put) command. Precede with a count for
multiple lines.

Put Command
brings back previous deletion or yank of lines,
words, or characters

P       bring back before cursor
p       bring back after cursor

 Find Commands

?       finds a word going backwards
/       finds a word going forwards
f       finds a character on the line under the cursor going forward
F       finds a character on the line under the cursor going backwards
t       find a character on the current line going forward and stop one character before it
T       find a character on the current line going backward and stop one character before it
;    repeat last f, F, t, T

Miscellaneous Commands

.    repeat last command
u    undoes last command issued
U    undoes all commands on one line
xp    deletes first character and inserts after second (swap)
J    join current line with the next line
^G    display current line number
%    if at one parenthesis, will jump to its mate
mx    mark current line with character x
‘x    find line marked with character x

NOTE: Marks are internal and not written to the file.

Line Editor Mode
Any commands form the line editor ex can be issued
upon entering line mode.

To enter: type ‘:’
To exit: press[return] or [esc]

ex Commands
For a complete list consult the
UNIX Programmer’s Manual

READING FILES
copies (reads) filename after cursor in file
currently editing

:r filename

WRITE FILE

:w     saves the current file without quitting

MOVING

:#    move to line #
:$    move to last line of file

SHELL ESCAPE
executes ‘cmd’ as a shell command.
:!’cmd’

For change the color in console in home directory

vi .bashrc

add the following line

unset LS_COLORS

enter the following command for the current session

[ugunasekaran@phxbeacon02 logs]$ cd

[ugunasekaran@phxbeacon02 ~]$ . .bashrc

[ugunasekaran@phxbeacon02 ~]$ cd –

For executing the last command /

Kill the process: ^Z and kill %1and enter one more time

To start the app server:

cd /v3app/intl/bin

./wrapper.sh start

To Find unique records in file

cat signin-ato-2013-04-12.txt | cut -d , -f2 | sort | uniq | wc -l

 For Sudo Access

sudo su – was

For Deployment:

perl /var/tmp/v3deploy/deploy.pl -deliverable beacon –servetraffic –nocreatedatasource –force –nodiskcheck –odbName=ibeacon-app –calPoolName=v3beaconintl E765_INTL_BUNDLED_14590170_R1.zip

export PATH=/path/to/dir:$PATH

To set vi mode

set –v vi

Writing into file

tee a_`date ‘+%m%d%y_%H_%M_%S’`

fbuild | tee “/c/Users/ugunasekaran/Desktop/mvnlog`date ‘+%d_%m_%H_%M_%S’`.log”

File Transfer to Ubundu/Linux/Unix – PSCP is in downloads folder – Go to download and run this command

pscp source_file_name userid@server_name:/path/destination_file_name.

Inline editing of file contents

perl -i.bkp -npe ‘s/hive -e/hive -S -e/;’ *.sh

Searching pattern in file

find . -name “*” -exec grep -i “top dispute” {} \; -print

Replacing pattern in file

find . -name “*sas” -exec perl -pi -e ‘s/guzhu\@ebay.com/DL-eBay-PD-TNS-PD\@corp.ebay.com/g’ {} \; -print

Replacing pattern in file from list of files

for f in $(cat test.txt); do echo “Processing $f…” ; perl -pi.uv-back -e ‘s/guzhu\@ebay.com/DL-eBay-PD-TNS-PD\@corp.ebay.com/g’ $f; done

Remote File Copy

Copy the file “foobar.txt” from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file “foobar.txt” from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory “foo” from the local host to a remote host’s directory “bar”

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Copy the file “foobar.txt” from remote host “rh1.edu” to remote host “rh2.edu”

$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/

Copying the files “foo.txt” and “bar.txt” from the local host to your home directory on the remote host

$ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy the file “foobar.txt” from the local host to a remote host using port 2264

$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy multiple files from the remote host to your current directory on the local host

$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
$ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .

Terminal Multiplexers

TMUX

Advertisements

One thought on “UNIX Commands

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