Unix Tips

Go To:  Home Page 

 

Unix


Identifying and killing the process
which runs on the system with IP ends with 228
************************************
who | grep develop | grep 228
XXXX XXXXX

ps -f | grep 'pts/2349'
XXXX 3423 2344 XXXXX XXXXX

kill 3423 2344



Matching any line which start with echo

egrep '^(( )+|( )?)echo' filename



Tar

tar cvzf foo.tgz *.cc *.h

This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files (v).

tar cvzf foo.tgz cps100 >> will tar the directory cps100
tar tzf foo.tgz >>To see a tar file's table of contents
tar xvzf foo.tgz >> To extract the contents of a tar file This untars/extracts (x) into the directory, prints the files (v).
tar xvzf foo.tgz anagram.cc You can extract only one (or several) files


Vi Scripts



To repalace the last occuring character "/" with Tab
:%s,/\([^/]*$\),\t\1,

Eg:
/home/prasanna/temp/hill.txt
results in
/home/prasanna/temp hill.txt


Finding files in Linux based on time

find . -name "hello" -printf "%a %c %t %f \n"

find . -follow \( -mtime 2 -o -mtime +2 \) -print

%a - access time (reading, coping)
%c - Changed time of file parameters or properties
%t - modify time of file content
%f - filename without dirs

-atime n - accessed n days ago
-mtime n - modified n days ago
-ctime n - changed n days ago