Linux Commands

I am updating this post when I find a useful linux command. And keep this post, just for my reference and for anyone who may find it helpful.

    1. Clear | Truncate the data in a file without opening.
      truncate -s 0 <file name>
    2. Find files which has given text in given location
      grep -nrwl  -e <"text to find">

      n: line number
      r : recursive
      w: match the whole word, if search for a part of the word omit w
      l : show the file only

    3. Create folder tree
      mkdir -p level_1/{level_2_a,level_2_b}
    4. Find and delete file | folder
       find . -name ".project" -exec rm -r "{}" \;
    5. List all the files which are edited in the given date range
       find repository/conf/ -type f -name "*.xml" -newermt 2015-05-11 ! -newermt 2015-06-07
    6. Print the last n number of lines of a file.
      tail -n file_name
    7. Find and replace the text of all the files recursively in given location.
      grep --include={*.java,*.xml} -rnl './' -e "find-text" | xargs -i@ sed -i 's/find-text/replace-text/g' @