File management

Create temporary file system in RAM (tmp RAM fs)

mount -t ramfs -o size=1M ramfs /tmp/mountpoint

Grep

  • Grep files case insensitively (i.e to match boo, Boo, BOO and all other combinations):
    $ grep -i "boo" /etc/passwd
  • Grep all files under each directory for a string “192.168.1.5”
    $ grep -r "192.168.1.5" /etc/

List files recursively and filter on filetype

  • List all recursively in list-format and filter directories from the result:

    ls -aRl /path/to/dir | grep "^d"

    grep "^d" ensures directories are filtered based on a regular expression (grep being the filter tool and ^ being the RegExp for: 'begin of line').

  • List all recursively in list-format and filter files from the result:

    ls -aRl /path/to/dir | grep "^-"

    grep "^-" ensures files are filtered based on a regular expression (grep being the filter tool and ^- being the RegExp for: 'begin of line').

Bulk permission transformations

  • Change all the directories to 755 (drwxr-xr-x):

    find /path/to/dir -type d -exec chmod 755 {} \;
  • Change all the files to 644 (-rw-r--r--):

    find /path/to/dir -type f -exec chmod 644 {} \;