Linux find command for files or folders older than …..

Find files and folders in current working directory older than 60 days

find ./* -maxdepth 0 -mtime +60

Find only folders in /mnt/media -> child folder -> grandchild exclude these folder notme, dtran, xXXx older than 3 years

find /mnt/media -maxdepth 2 -mtime +1095 -type d -not ( -path “./notme*” -o -path “./dtran*” -o -path “./xXXx*” ) > ~/Folder2Backup.txt

Remove all files that have xxx in names and older than 2 years

find ./ -type f -name “*xxx*.*” -mtime +730 -exec rm “{}” ;

Windows not a big deal, install Cygwin and Finding Nemoooo

find /cygdrive/f -maxdepth 2 -type d -mtime +730 > ~/dir_older_than_2years.txt

Find directory older than 2 years and list its size

find /cygdrive/f -maxdepth 1 -type d -mtime +730 -exec du -sh “{}” ; 

Apple flush DNS cache

Open Terminal and run this command

dscacheutil -flushcache

TTL and DNS cache

Time to Live (TTL) is used to renew the DNS records on all the DNS servers around the world to the set TTL value. 
The units used are seconds. The older common TTL value for DNS was 86400 seconds, which is 24 hours. A TTL value of 86400 would mean that, if a DNS record was changed on the authoritative name server, the DNS servers around the world could still be showing the old value from their cache for up to 24 hours after the change.

Why change the TTL value

If you want to make quick DNS changes, it is a good practice to place a low TTL value. The TTL values can be changed by logging in to the the Self Service Center.
If you change the TTL, you have to wait for the current TTL to pass before the new TTL will be active. This means that if you change the TTL to 1 hour instead of 24 hours, you have to wait the 24 hours first before the 1 hour TTL wil be active.
Setting a TTL value lower than 12 hours is not recommended, and should only be used during a short period for special cases. By default, the TTL value is 24 hours.

Listing directory in Graphical format in Bash

ls -R | grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^/]*//–/g’ -e ‘s/^/   /’ -e ‘s/-/|/’

Script from centerkey.com: http://www.centerkey.com/tree/tree.sh

#!/bin/sh
#######################################################
#  UNIX TREE                                          #
#  Version: 2.3                                       #
#  File: ~/apps/tree/tree.sh                          #
#                                                     #
#  Displays Structure of Directory Hierarchy          #
#  ————————————————-  #
#  This tiny script uses “ls”, “grep”, and “sed”      #
#  in a single command to show the nesting of         #
#  sub-directories.  The setup command for PATH       #
#  works with the Bash shell (the Mac OS X default).  #
#                                                     #
#  Setup:                                             #
#     $ cd ~/apps/tree                                #
#     $ chmod u+x tree.sh                             #
#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
#     $ echo “PATH=~/bin:${PATH}” >> ~/.profile      #
#                                                     #
#  Usage:                                             #
#     $ tree [directory]                              #
#                                                     #
#  Examples:                                          #
#     $ tree                                          #
#     $ tree /etc/opt                                 #
#     $ tree ..                                       #
#                                                     #
#  Public Domain Software — Free to Use as You Like  #
#  http://www.centerkey.com/tree  –  By Dem Pilafian  #
#######################################################
echo
if [ “$1” != “” ]  #if parameter exists, use as base folder
   then cd “$1”
   fi
pwd
ls -R | grep “:$” |  
   sed -e ‘s/:$//’ -e ‘s/[^-][^/]*//–/g’ -e ‘s/^/   /’ -e ‘s/-/|/’
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep “/” | wc -l` = 0 ]   # check if no folders
   then echo ”   -> no sub-directories”
   fi
echo
exit

Add it to your system. Please watch out the code before running it!

curl http://www.centerkey.com/tree/tree.sh > /usr/bin/tree
chmod +x /usr/bin/tree 

 http://stackoverflow.com/questions/3455625/linux-command-to-print-directory-structure-in-the-form-of-a-tree

Compare 2 directory in Linux

Let’s make an example. Create 2 folder and put files in it

mkdir dir{1,2}
touch dir1/{1,2,3,4,5,6}.txt
touch dir2/{2,4,5,7,9}.txt

ls -R dir1
dir1:
1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

ls -R dir2
dir2:
2.txt  4.txt  5.txt  7.txt  9.txt

diff -r dir1 dir2
Only in dir1: 1.txt
Only in dir1: 3.txt
Only in dir1: 6.txt
Only in dir2: 7.txt
Only in dir2: 9.txt

http://stackoverflow.com/questions/16787916/difference-between-2-directories-in-linux

Ubuntu Change Date from IST to ICT

If you try to change your clock, NTP setting and sync to hardware clock but the date still wrong so here’s how

#date
Thu Nov 27 08:16:23 IST 2014  #wrong date time

#dpkg-reconfigure tzdata
Current default time zone: ‘Asia/Ho_Chi_Minh’
Local time is now: Thu Nov 27 09:48:02 ICT 2014.
Universal Time is now: Thu Nov 27 02:48:02 UTC 2014.

#date
Thu Nov 27 09:48:09 ICT 2014  #correct now

Setup Backuppc Client

On Remote Server

Add backuppc user

adduser backuppc
passwd backuppc
su - backuppc
From root run visudo to update sudoer
backuppc ALL=(ALL:ALL) NOPASSWD: /usr/bin/rsync, /bin/tar
Optional:
chmod 755 /home/backuppc/.ssh
chmod 600 /home/backuppc/.ssh/authorized_keys

On BackupPC server

Copy Public key from BackupPC server to remote host for passwordless login
ssh-copy-id backuppc@Remote_Host
ssh -c blowfish -q -x -l backuppc Remote_Host hostname
if it successfully return the remote hostname, we ready to add remote host to Backuppc Web Dashboard
http://mydomain.vn/backuppc -> Edit Config -> Host -> Add Host: Hostname, User: backuppc

Configure transfer method

Select the remote hostname from the list of Host

http://mydomain.vn/backuppc/index.cgi?host=Remote_Host -> Edit Config -> Xfer

XferMethod: Rsync
RsyncShareName: /var/www

Replace root user (after -q -x -l) with backuppc in RsyncClientCmdRsyncClientRestoreCmd

Leave Schedule as default