Saturday, January 22, 2011

Miscellaneous - Useful UNIX



  • Find/Zip/Move/Delete files older than x days


  • Delete the 500 oldest files


  • Find and grep


  • list all files opened by a process


  • ls -l sorted by size


  • cpio unzip syntax


  • man commands


  • pipes


  • Turn off auto indent and bracket matching in vi


  • Capture a control charater


  • Configure ksh environment


  • Show routing tables


  • Check all logs for ORA- errors

  • Find/Zip/Move/Delete files older than x days

    find ./ -name "*.ARC" -mtime +1 -exec ls -l {} \;
    
    find ./ -name "*.ARC" -mtime +1 -exec rm {} \;
    find ./ -name "*.ARC" -mtime +1 -exec gzip {} \;
    find ./ -name "*.arch" -mtime +1 -exec mv {} /u01/andy/;
    

    Delete the 500 oldest files

    rm -f `ls -tr|head -500`
    

    Find and grep

    find ./ -grep <what> {} \; -print 2>/dev/null
    
    Or...
    find ./ -exec grep -l "string" {} \;


    list all files opened by a process

    lsof -p <pid>

    ls -l sorted by size

    ls -l |sort -k 5
    

    du -sk *|sort -n

    cpio unzip syntax

    cpio -idmv < <filename>
    

    man commands

    man -k <what> -displays the chapters containing the specified
    man <chapter> <what> -shows the page
    

    pipes

    mknod <name> p
    


    Turn off auto indent and bracket matching in vi

    :set noai nosm
    


    Capture a control charater
    ctl-v then press the control key (eg. backspace)

    Configure ksh environment
    To display the current settings
    set -o
    


    To set HP/UX stylee...
    set -o vi
    set -o vi-esccomplete
    

    Show routing tables

    netstat -r


    Check all logs for ORA- errors

    grep ^ORA- *log |cut -f2 -d"-"|cut -f1 -d:|awk '{print "ORA-" $1}'|sort -u
    

    No comments:

    Post a Comment