Finding files with find

Remove files by modification date

This example shows how to remove all files with a modification date before 2016:

find -type f -not -newermt 20160101 | xargs rm

Move old files to another directory

This example shows how to move a large number of files to another directory:

find /var/www/userpics -name '*.jpg' -mtime +31 -print0 | xargs --null mv --target-directory=/backup/oldpics/

Find files by permission

Exact permission (read,write,execute for owner only):

find -perm 700

Use sed

If you want to see a couple of lines from a CSV alongside with the header:

sed -n -e '1p' -e '809,820p' my.csv

Sort lines with sort

Sort by a column:

~# sort -k 1 myfile

Sort numeric:

~# sort -n myfile

Sort reverse:

~# sort -r myfile

Using date

Display date a month ago:

~# date -d "-1 month" +%Y-%m-%d

It automatically adjusts the day if the resulting date would be invalid.

Set time:

~# date +%T -s "12:12:00"

Using rsync

Copy files instead of symlinks

rsync -L /etc/letsencrypt/live/*.pem

Sync only files with a certain extension from one directory tree to another

rsync -av --include="*/" --include='*.status' --exclude='*' /samba/. .

Using ip

Show network interfaces with additional information (similar to ifconfig):

~# ip -a

Using lsof

Open files

Show open files in a directory:

~# lsof /mnt/backup

Network connections

~# lsof -i :80
nginx   431729     root    6u  IPv4 7170923      0t0  TCP *:http (LISTEN)
nginx   431729     root    7u  IPv6 7170924      0t0  TCP *:http (LISTEN)
nginx   431730 www-data    6u  IPv4 7170923      0t0  TCP *:http (LISTEN)
nginx   431730 www-data    7u  IPv6 7170924      0t0  TCP *:http (LISTEN)

See also

An lsof Primer

Using lftp


Mirror from remote FTP server to local server

mirror -c source target

Please note that doesn't mirror dot files like .htaccess. To include these, adjust the default listing options:

set ftp:list-options -a


In case you really need to disable SSL (not recommended), use the following command:

set ftp:ssl-allow false

Encryption with GnuPG

Environment variables


Select alternative home directory for GPG configuration and keys:

   export GNUPGHOME=~/.gnupg-old/