Linux file operations

Useful file operation commands

Linux Search Files

Find all files modified at date:
find ./ -type f —name “*.php” newermt “2017-10-14”
Find all files modified at date and time:
find ./ -type f —name “*.php” -newermt “2017-10-14 10:21:00”
Find all modified files between dates:
find ./ -type f —name “*.php” -newermt “2017-10-14 10:21:00” \! -newermt “2017-10-14 10:40:00”
Delete all files modified between dates:
find ./ -type f -newermt “2017-10-14 10:21:00” \! -newermt “2017-10-14 10:40:00” -exec rm {} +
Backup root directory excluding home, tmp, etc:
sudo tar --exclude='/proc' --exclude='/home' --exclude='/tmp' --exclude='/var/web-cache' --exclude='/boot' -zcvf yyyy-mm-dd_root.tgz /
Archive by 7z excluding directories
sudo 7z a -r 2017_11_14-root.7z /* '-xr!/boot' '-xr!/proc' '-xr!/tmp' '-xr!/var/web-cache' '-xr!/home' -spf

rsync – a fast, versatile, remote (and local) file-copying tool

Copy files by rsync over SSH from server to local machine:

rsync -avz -e “ssh -o StrictHostKeyChecking=no -o UserKnownHostFile=/dev/null” —progress [email protected]:/var/cache/apt/archives/*.deb /home/username/Downloads

2 thoughts on “Linux file operations”

  1. In absence of the preview button, let me add one: *list all setuid files*

    $ sudo find /opt -perm -4000 2> /dev/null

  2. I find the ‘-print0’ option combined with ‘xargs -0 ‘ very useful. For example: you have a latex file (.tex) in which the label: ‘fig:example’ is used. Then you can run:
    find . -type f -name '*.tex' -print0 | xargs -0 grep 'fig:example'

Comments are closed.