Tuesday 27 September 2016

How to find size of a directory in Linux


du is a linux command, is to display the file space allocated to each file and directory contained in the current directory. It Summarize disk usage of each FILE, recursively for directories.



                        # du    - List of directories that exist in the current directory along with their sizes.


                       # du -c   -Gives grand toal as last line of output.

                   
                       # du -s    -Displays summary of directory size.


                         # du -h   -Displays size in human readable format.









Sort Directory size in ascending order.




                         # sudo du -sh * | sort -hr








Thursday 22 September 2016

How to scheduling Crontab for backup files and directories in linux


1. Install crontab

In centos,redhat:

            # yum install cron*

2. Open crontab.

                  # crontab -e


                                field                    allowed values
                                ------------            -------------------
                                   minute                   0-59
                                   hour                       0-23
                                   day of month         1-31
                                   month                    1-12 (or names, see below)
                                   day of week           0-7 (0 or 7 is Sun, or use names)




 15      16      *       *       1       /bin/tar -czvf /Backup-Folder/Project-Folder-MON.tar.gz       /Project-Folder




The 'Project-Folder' will backup every Monday - every month - every day at 04:15 PM to 'Backup-Folder' under '/' with the name 'Project-Folder-MON.tar.gz'.


-c : Create
-z : Gzip
-v : Verbose
-f : File

3. Save the file


4. List crontab


            # crontab -l


5. Remove crontab


            # crontab -r


6. Restart crontab


            # service crond restart


7. Add crontab on startup


            # chkconfig crond on


How to schedule crontab for other users



Open crontab with username and add the scheduler and restart the service.


            # crontab -e -u username


How to deny a user from crontab



Open crontab.deny file and add the user you want to deny. save the file and restart the service.


            # vim /etc/crond.deny