Linux/Unix Shortcuts

  1. To execute a unix command on an stdout from another command:
    e.g.: To delete all files that start with 'core' in their name:
    find ./ -name core'*' -exec rm -i {} \;
    Another example on web:
    find . -name '*.py[co]' -exec rm -f {} ';'
  2. To rename the file to a different name:
    find ./ -inum 208946 -exec mv {} new.filename \;
  3. To remove file extension in a shell script:
    If file_name = $1
    file_title=`echo $1|sed 's/..{3}$//'`
  4. To remove trailing spaces from all lines:
    sed 's/[ \t]*$//'
  5. To change recursively permissions such that only directories and executables get the +x permission and others don't:
    chmod -R go+rX whatever
  6. To get an average value of a data column for specific line numbers:
    gawk 'NR >20' data.dat | gawk '{sum=sum+$2} END {print sum/NR}'
  7. To show the hidden characters in vim:
    :set invlist
    :set list
  8. To delete all running jobs on hive:
    qdel `qu | grep abrol | cut -c 1-6`
  9. To copy a whole directory structure without copying any files:
    cd /new/dir
    (cd /old/dir; find -type d ! -name .) | xargs mkdir
  10. Avoiding Tar's (or Any Other Commandline's) Argument List Too Long Error:
    # generate the file list:
    find -iname '*.ext' > fileList.txt
    #run tar passing it the file list:
    tar czvf archive.tar.gz --files-from fileList.txt
    # a shorthand of this would be:
    find . -name '*.ext' -print | tar -cvzf archive.tar.gz --files-from -