Linux: disk usage command – du

du is a standard unix command to calculate disk space from Unix/Linux system.

To get the sum space of the directory,

du

To get sum space with human-readable,

du -sh

To get sub directories space

du -sh *

To get sub directories space with all hidden folder,

du -sk .[!.]* * | sort -n

Scheduled MySQL database backup

Assume that you are using crontab to schedule your task which you are using Unix system.

To schedule a database backup, it will be very easy as step below.

1. Log into your SSH.
2. Type “crontab -e” without quote.
3. Enter the command below.

0 0 * * * date=`date -I` ; mysqldump -a -u[user] -p[password]  [dbname] | gzip > /path/folder/[dbname]_$date.sql.gz

where you shall replace the user, password and dbname to your database information.

With the command as above it will actually backup your database by 12.00AM daily and place to the desired path and name with date.

How to use Linux Screen

Screen is one of the powerful command in Linux(Unix System) that allow user to run command in remote mode and this is to avoid connection timed out or etc issue causing the previous launched command stopped.

You may install screen by running yum or apt-get depending on your box, then you can start screen by typing screen at the command prompt.

screen

Once screen session has started, you can use the following commands to mess around:

– Ctrl + A + ‘c’ = To open a New Windows
– Ctrl + A + ‘n’ = next window (if you have multiple windows running)
– Ctrl + A + ‘0…9’ = go to window number x where it should come with 0 to 9.
– Ctrl + A + ‘d’ = detach from a window. Say, if you want to close your session and return later.
– Ctrl + ‘d’ = detach and clear the screen session,

To re-attach to a screen, you may need to check the number of screen is running.

screen -ls


This will display the screens currently running, you could run the command as below to resume the screen session.
[code]$ screen -x pid.tty.user[/code]