Wednesday, 25 June 2014

Linux Commands



Grep: Startpoint and Endpoints together in the timing file.
grep Startpoint reg2reg.rpt  -A3 | grep Endpoin | sort -u | less
grep Startpoint reg2reg.rpt  -c --> count the number of startpoints without sorting

Show list of files in current directory
ls
à long, a à hidden, r à alphabetical order, t à timestamp

Changing the permissions of files/directories
chmod +x 
chmod +w 
chmod +r 
chmod 744 
chmod 777 
Ex. 777 = 111 111 111 = {owner, group, others}
111 = {r, w, x} = {read, write, execute}

Copy the files/directory to destination
cp source destination à copies destination to source (file)
cp –r source destination à copies recursively (directory)
head  à displays first 10 lines of the file
head –n  à displays first n lines of the file
tail  à last 10 lines
tail –n  à last n lines

Global Regular Expression Parser (GREP)
grep "word"  à searches for the word in the file
grep "^module"  à searches for the lines start with "module"
grep "^module$"  à searches for the lines end with "module"
grep "word" | wc –l à searches for word in file and gives the number of occurrences
à Unix pipe, output of one command is given as input to the next command

sort  à sorts the file in alphabetical order
sort > sorted_file à sorts and output will be redirected to sorted_file
>> à append mode
> à overwrite mode

wc (word count)
wc  à displays line, word, character count of the file
wc –l à
 only line countwc –w  à only word count
wc –c  à only character count

diff  à diffs two files
diff –r –w  à diffs two directories
sdiff  à diffs and results will be placed side by side

cat  à displays file contents
cat | more à displays one page(one screen on console) at a time, goes to second screen on pressing space bar (more command – can be piped with any other command)

mv  à renaming the file, can also be used to move the files in different directories


SYSTEM LEVEL COMMANDS

ps –l à own process details
ps –la à all processes
ps –u  à process details of particular user
ps –u | grep  à searches for particular process of a particular user, process defined by keyword
kill -9  à kill process having ID, PID (sure kill)
env à lists environment variables and their values
env | grep  à environment variables of particular user
setenv CVSROOT /proj/asics in .cshrc file à setting up environment variable
setenv CVSROOT = /proj/asics/ in bash à setting up environment variable
echo $ENV_VARIABLE à displaying the value of environment variable ENV_VARIABLE
who à list of users logged in
who am i à current user
which perl à perl source directory
alias dir ‘ls –l | grep ^d’ à alias for listing directories
alias ll ‘ls –l | more’


VI EDITOR COMMANDS






  • :q à close file
  • vi à create/open new file
  • /
  • :w à save file
  • :wq à save and quit from file
  • :q! à quit from a read only file
  • :wq! à save and quit from a read only file
  • :0 à go to first line
  • :1 à go to first line
  • à go to the last line
  • ctrl+g à prints total number of lines and current line in %
  • :%s??g à global search and replace
  • à go to previous line
  • à go to next line
  • à go to next character and insert mode
  • à insert mode
  • escape à come out of insert mode
  • à go to the next line and insert mode
  • à Page up
  • à Page down
  • à go to previous character
  • à go to next character
  • à delete character
  • dd à delete single line
  • n dd à delete n lines
  • m a à mark current line with ‘a’
  • ` a à go to the line marked ‘a’
  • :’a,’by à copy the lines marked between ‘a’ and ‘b’
  • :e  à opens second file
  • yy, p à copy & paste
  • dd, p à cut & paste
  • n yy à copy n lines
  • :r  à inserts the file contents specified in to current file after current line (cursor)
  • r  à replaces current character with ‘c’
  • ctrl + d à half screen down
  • ctrl + u à half screen up
  • à go to start of line
  • à go to end of line
  • à go to the next word
  • à go to the next character
  • à go to the end of current word
  • dw à delete current word
  • cw à replace current word
  • cc à replace current line
  • à execute previous command
  • :sp  à opens other file specified in the same screen, ctrl+ww can be used to shift between files
  • à join the next line to current line
  • Shift+5 à matching begin end


GVIM settings in your home Dir:

create a file .gvimrc in your home dir and add the following lines


set mouse=a
set hlsearch
set hls

set incsearch
set backspace=2
set nocompatible
" use tab for auto-expansion in menus
set wc=
" show a list of all matches when tabbing a command
set wmnu
" how command line completion works
set wildmode=list:longest,list:full
" remember last 2000 typed commands
set hi=2000
" focus follows mouse
set mousef
:color zellner
set nu


 


No comments:

Post a Comment