Linux tricks, one-liners & shell magic
← Back to all tricks
Create a timestamped backup of a file

Before editing a config, make a dated backup with a one-liner. The $(date) sub-shell appends the current timestamp.

bash
$ cp nginx.conf nginx.conf.$(date +%Y%m%d_%H%M%S).bak # Backup and keep last 5 only: cp important.conf important.conf.$(date +%Y%m%d).bak ls -t important.conf.*.bak | tail -n +6 | xargs rm -f
backupbro2026-04-19
Delete this trick? This cannot be undone.