Useful Unix Commands

Remove archive log files older than 2 days:

-- list them first to confirm
find .*.arc -mtime +2 -type f -maxdepth 1 -exec ls -ltr {} \;
-- then delete    
find .*.arc -mtime +2 -type f -maxdepth 1 -exec rm {} \;

Remove trace files – same as above:

-- list them first to confirm
find . -name "*.trc" -mtime +90 -type f                        
-- then delete
find . -name "*.trc" -mtime +90 -type f -exec rm -f '{}' \; 

Different way of doing the above:

-- to find files. Value is number of days
find . -maxdepth 1 -name "*.xml"  -mtime +10 -type f

-- to delete files. value is number of days
find . -maxdepth 1 -name "*.xml" -mtime +10 -type f -exec rm -f '{}' \;

Loop a command:

while true; do crs_stat -t; sleep 5; done

Copy Files from one server to another:

scp <file> <user>@<target>:<path>
eg: scp test.txt oracle@SERVERA:/export/home/oracle

Messages on linux:

var/log/messages

Changing Permissions and Owners:

-- Change owner
chown <owner> <file>
chown oracle CSSfile
-- Change group
chgrp <group> <file>
chgrp dba CSSfile
-- Change permissions
r = 4    w = 2   x = 1
owner|group|all
  421   |  421   |421
  rwx       rwx     rwx
--for read, write, all for all would be:
chmod 777
--for drwxr-xr-x
chmod 755

Tar files:

-- taring a folder
tar -cvfp <tar filename/location> <top level of dir you want to tar>
-- Notes
-- c = create file v = verbose f = files p = preserve permissions
-- Untaring a folder
tar -xvf <name of tar>
-- untaring a folder to location
tar -xvf <name of tar> -C <dir to untar to>

Search and replace:

:%s/<SEARCH_STRING>/<REPLACE_STRING>/g    - /g means global

Advertisements

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

%d bloggers like this: