Thursday, May 9, 2013

Unix Tips



Some commands to get started with Unix:


#connect to a server using secure shell
ssh <username>@<server>
 
#find files with name in a folder
find /tmp /var/tmp . $HOME -name foo
 
#find file containing text recursively
grep -r "redeem reward" /home/tom
 
#run emacs editor
emacs runShell.sh &
 
#run vi editor
vi
vi <filename> 
# vi change highlight colors
:hi
:hi pythonString guibg=Black guifg=DarkYellow ctermbg=Black ctermfg=DarkYellow
:syntax on
:set nu
:set smartindent
:set tabstop=4
:set shiftwidth=4
:set expandtab
 
#copy file from a different server
scp <file_source> <file_destination>
scp <file_name> <user_name>@<server>:<destination_path>
scp <user_name>@<server>:<file_source> <file_path>
 
#grep process 
ps -ef | grep <app name>
ps -ef | grep <user>
ps ax | grep <user> | grep <command name> | awk '{print $1}' | wc -w
#and kill 
kill -9 1986
kill $(ps ax | grep <search command> | awk '{print $1}')
 
# vi search and replace
# the slash(/) can be replaced by "#" or "@" or "$"
# First occurrence on current line:      :s/OLD/NEW
# Globally (all) on current line:        :s/OLD/NEW/g
# Between two lines #,#:                 :#,#s/OLD/NEW/g
# Every occurrence in file:              :%s/OLD/NEW/g 
# Characters in the text                 :%s/OLD.DLO/NEW/g
# search/replace with special characters :s#//#/#g
# replace "asd/qwe/zxc" with "fgh/vbn"   :s@asd/qwe/zxc@fgh/vbn@g
# replace "asd/qwe/zxc" with "fgh/vbn"   :s/asd\/qwe\/zxc/fgh\/vbn/g    
# delete blank lines                     :g/^$/d
 



#svn commands
svnadmin create     #create a new repository
svn info            #lists the information for the repository
svn mkdir           #make a directory in the repository
svn checkout        #gets a copy of the repository and puts it under version control
svn export          #get something from repository (will not be under version control)
svn import          #put something into repository
svn commit          #find all changes and put them into the repository
svn status          #shows a list of changes
svn status -u       #shows a list of changes in the repository that don't exist in my copy
svn add             #mark a file to be added to the repository
svn move            #move something in the repository from one spot to another
svn delete          #delete something from the repository
svn rename          #basically a move and a delete done in one step
svn copy            #copy something in the repository
svn log             #shows a list of commit messages
svn list            #display contents of repository directory
svn update          #update my checked out copy to the whatever is in the repository
svn update -r       #update to a specific version of the repository
svn diff            #check difference between files
svn propset svn:keywords "Id" pkg_log_utils.sql
  
# untar to a specific directory
tar xvzf file_name.tar.gz -C <unzip location>
#unzip .gz file
gunzip file.gz
gzip -d file.gz

#rename a bunch of files in a directory
for f in *.csv; do mv $f $(echo $f | sed 's/.csv/.prod.csv/g'); done

#output logs and errors to a log file 
function_call > /tmp/tmp.log 2>&1
 
#continuously monitor above log file
tail -f /tmp/tmp.log

No comments: