Translate

Monday, August 10, 2015

Apache Derby DataSource configuration in Weblogic Server


Key Points to Note - 
  • You can specify your own connection properties while configuring Derby Data Source as its going to create Database instance at runtime with whatever DB details provide as below -



  • It creates Derby DB instance files under derby/bin below path by default -/opt/thirdparty/middleware/oracle/wls11g/common/derby/bin






  • -rwxr-x---. 1 g800077 g800077 4853 Aug  4 10:16 derby_common.sh

    • -rwxr-x---. 1 g800077 g800077 5740 Aug  4 10:16 dblook
    • -rwxr-x---. 1 g800077 g800077 1079 Aug  4 10:16 setNetworkClientCP
    • -rwxr-x---. 1 g800077 g800077 1073 Aug  4 10:16 setEmbeddedCP
    • -rwxr-x---. 1 g800077 g800077 5801 Aug  4 10:16 NetworkServerControl
    • -rwxr-x---. 1 g800077 g800077 5876 Aug  4 10:16 ij
    • -rwxr-x---. 1 g800077 g800077 5807 Aug  4 10:16 startNetworkServer
    • -rwxr-x---. 1 g800077 g800077 1075 Aug  4 10:16 setNetworkServerCP
    • -rwxr-x---. 1 g800077 g800077 5789 Aug  4 10:16 sysinfo
    • -rwxr-x---. 1 g800077 g800077 5810 Aug  4 10:16 stopNetworkServer
    • -rwxr-x---. 1 g800077 g800077  240 Aug  4 10:16 startNetworkServer.sh
    • -rwxr-x---. 1 g800077 g800077  170 Aug  4 10:16 stopNetworkServer.sh
    • -rw-rw-r--. 1 g800077 g800077 1021 Aug 10 05:00 derby.log
    • drwxrwxr-x. 5 g800077 g800077 4096 Aug 10 05:00 derbyDB

    Start Derby DB services using class -

    • Manually setting up CLASSPATH for certain jar's to test 


    export CLASSPATH=/opt/thirdparty/middleware/oracle/wls11g/common/derby/lib/derbytools.jar:$CLASSPATH
    export CLASSPATH=/opt/thirdparty/middleware/oracle/wls11g/common/derby/lib/derbynet.jar:$CLASSPATH
    java org.apache.derby.drda.NetworkServerControl start -p 1027




    Most of you might already worked on this. Anyone who has not got chance to work on it and a note to myself on the step by step Apache Derby datasource configuration in Weblogic.

    Steps to Configure Apache Derby Datasource in Weblogic

    A. Weblogic v10.3.3 and below
    Pre-requisites:
    --JDK 1.7 with Java DB [Apache Derby distribution] included.
       Java DB is Oracle's supported distribution of the Apache Derby open source database. It supports standard ANSI/ISO SQL through the JDBC and Java EE APIs.

    1a. Java DB startup - 
    Navigate to JDK7 <JAVA_HOME_JDK7>/db/bin directory and execute the startNetworkServer.bat or startNetworkServer.sh per your OS preference.
    By default, the Java DB listens on TCP/IP port 1527. The listen port can always be modified, refer this documentation.
    1b. Download and supplement the Derby JDBC driver jar files to the Weblogic domain classpath in setDomainEnv.cmd or setDomainEnv.sh under <DOMAIN_HOME>/bin. Restart the Weblogic domain for the Derby JDBC driver class to be accessible.
       derbyclient.jar - <JAVA_HOME_JDK7>/db/lib/derbyclient.jar
       derbytools.jar - <JAVA_HOME_JDK7>/db/lib/derbytools.jar

    Example:

         set JAVA_HOME_JDK7=E:\Java\jdk1.7.0_25
         set PRE_CLASSPATH=%JAVA_HOME_JDK7%\db\lib\derbyclient.jar;%JAVA_HOME_JDK7%\db\lib\derbytools.jar



    B. Weblogic v10.3.4 and above
    Starting version Weblogic 10.3.4 the Apache Derby DB is included in the installation along with Weblogic. 

    1a. Java DB startup - Set DERBY_FLAG to true in your setDomainEnv.cmd or setDomainEnv.sh under<DOMAIN_HOME>/bin. This setting would launch Java DB startup during the startup of Weblogic instance. Restart the Weblogic instance to bring up the Java DB along with Weblogic.


    2. If you have not already done so, in the Change Center of the Administration Console, click "Lock & Edit"


    3. In the left pane, navigate to Services > JDBC > Data Sources

    4. On the right pane, click on New to add new Data Source

    5. Specify Name and JNDI name of the Data Source per your preference. Select the Database Type as Derby and appropriate Database Driver. Click Next

    6. I have unchecked the Supports Global Transactions option.Again it is per your preference.

    7. Specify the Connection properties and click Next
         Database Name can be absolute path location of the database files to be saved.
         Example: E:\DerbyDB\ApacheDerbyDB
         Or
         It can be relative path location, you will have to just mention dbName and the database files will be created under <JAVA_HOME_JDK7>\db\bin\ [Option A] or <WEBLOGIC_HOME>\common\derby\bin\ [Option B]
         Example: If the dbName is blogdomain_db, E:\Java\jdk1.7.0_25\db\bin\blogdomain_db or C:\Middleware_10.3.4\wlserver_10.3\common\derby\bin\blogdomain_db would be the location of the database files.
         Host Name where the database runs.
         Port on which the database listens for connections
         Username and Password

    8. Verify Connection properties, click Test Configuration and proceed Next. If you notice under propertiescreate=true is automatically added, the database will be automatically created if not present already.

    9. Select targets for the Data Source. Click Finish

    10. In the Change Center of the Administration Console, click "Activate Changes".


    Here is derby DS configuration xml file - 

    cd /opt/thirdparty/middleware/oracle/user_projects/domains/SyniverseDomain/config/jdbc
    derbyDS-8519-jdbc.xml

    <?xml version='1.0' encoding='UTF-8'?>
    <jdbc-data-source xmlns="http://xmlns.oracle.com/weblogic/jdbc-data-source" xmlns:sec="http://xmlns.oracle.com/weblogic/security" xmlns:wls="http://xmlns.oracle.com/weblogic/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/jdbc-data-source http://xmlns.oracle.com/weblogic/jdbc-data-source/1.2/jdbc-data-source.xsd">
      <name>derbyDS</name>
      <jdbc-driver-params>
        <url>jdbc:derby://localhost:1527/derbyDB;ServerName=localhost;databaseName=derbyDB</url>
        <driver-name>org.apache.derby.jdbc.ClientDataSource</driver-name>
        <properties>
          <property>
            <name>user</name>
            <value>derbyuser</value>
          </property>
          <property>
            <name>portNumber</name>
            <value>1527</value>
          </property>
          <property>
            <name>databaseName</name>
            <value>derbyDB;create=true</value>
          </property>
          <property>
            <name>serverName</name>
            <value>localhost</value>
          </property>
        </properties>
        <password-encrypted>{AES}LI8Wu1l8eRLG38DoayN52MQ8qutL/DB7WVuzfNM3ERQ=</password-encrypted>
      </jdbc-driver-params>
      <jdbc-connection-pool-params>
        <test-table-name>SQL SELECT 1 FROM SYS.SYSTABLES</test-table-name>
      </jdbc-connection-pool-params>
      <jdbc-data-source-params>
        <jndi-name>derbyDS</jndi-name>
        <global-transactions-protocol>TwoPhaseCommit</global-transactions-protocol>
      </jdbc-data-source-params>
    </jdbc-data-source>




    Thanks,
    Srikanth Govada

    Wednesday, July 29, 2015

    Install Weblogic 10.3/11g


    Silent Mode of Installation - 


    Note - Please note you need to have Java installed as pre-requisite in case if you are running 64-Installer.

    32-bit Installer -
    ./wls1036_linux32.bin -mode=silent -silent_xml=silent.xml -log=wls_install.log -log_priority=debug


    silent.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Silent installer option -mode=silent -silent_xml=C:\myfiles\silent.xml -->
    <!-- Specify values for each data-value name as follows:

         BEAHOME            Complete pathname to the Middleware Home directory that
                            will contain this installation.

         WLS_INSTALL_DIR    Complete pathname to the product installation
                            directory in which to install WebLogic Server.

         COMPONENT_PATHS    Components and subcomponents to be installed.
                            To install multiple components, separate the components
                            with a bar (|).
                            To install subcomponents, specify a
                            component/subcomponent combination. For example,
                            to install Core Application Server, use
                            "WebLogic Server/Core Application Server".

         INSTALL_NODE_MANAGER_SERVICE  Install Node Manager as a Windows
                                       service. The default is "no".
                                       Requires Administrator privileges.

         NODEMGR_PORT       Node Manager listen port number. If none specified,
                            installer uses default port 5556.
                            INSTALL_NODE_MANAGER_SERVICE must be set to "yes".

         INSTALL_SHORTCUT_IN_ALL_USERS_FOLDER
                            The Windows Start menu folder in which you want the
                            Start menu shortcuts created.
                            The user performing the installation must have
                            Administrator privileges to install the shortcuts
                            in the All Users folder.
                            Possible values:
    true/yes  The shortcuts are created in
                                      the All Users folder (default)
                            false/no  The shortcuts are created in
                                      the local user's folder

         BEA_BUNDLED_JVMS
                            Option to select BEA bundled JVMS (for e.g. either
                            jrockit_160_05 or jdk160_05 for Windows and Linux
                            platforms). The default value is all BEA bundled JVMs
                            for selected platform.

         LOCAL_JVMS
                            Option to select supported JVM, which is already
                            installed. Note: The presence of either(BEA_BUNDLED_JVMS
                            or LOCAL_JVMS) or both of these tokens negates any
                            default selection and only sets the values assigned for
                            these tokens as user selection. The value of the token
                            can be a pipe ('|') separated JavaHomes.
    -->

    <!-- <?xml version="1.0" encoding="UTF-8"?> -->
       <bea-installer>
         <input-fields>
           <data-value name="BEAHOME" value="/opt/thirdparty/middleware/oracle" />
           <data-value name="WLS_INSTALL_DIR" value="/opt/thirdparty/middleware/oracle/wls11g" />
           <data-value name="COMPONENT_PATHS"
            value="WebLogic Server/Core Application Server|WebLogic Server/Administration Console|WebLogic Server/Configuration Wizard and Upgrade Framework|WebLogic Server/Web 2.0 HTTP Pub-Sub Server|WebLogic Server/WebLogic JDBC Drivers|WebLogic Server/Third Party JDBC Drivers|WebLogic Server/WebLogic Server Clients|WebLogic Server/WebLogic Web Server Plugins|WebLogic Server/UDDI and Xquery Support|WebLogic Server/Server Examples|Oracle Coherence/Coherence Product Files" />
           <data-value name="INSTALL_NODE_MANAGER_SERVICE" value="yes" />
           <data-value name="NODEMGR_PORT" value="5559" />
           <data-value name="INSTALL_SHORTCUT_IN_ALL_USERS_FOLDER" value="yes"/>
    true/yes  The shortcuts are created in
                                      the All Users folder (default)
                            false/no  The shortcuts are created in
                                      the local user's folder

         BEA_BUNDLED_JVMS
                            Option to select BEA bundled JVMS (for e.g. either
                            jrockit_160_05 or jdk160_05 for Windows and Linux
                            platforms). The default value is all BEA bundled JVMs
                            for selected platform.

         LOCAL_JVMS
                            Option to select supported JVM, which is already
                            installed. Note: The presence of either(BEA_BUNDLED_JVMS
                            or LOCAL_JVMS) or both of these tokens negates any
                            default selection and only sets the values assigned for
                            these tokens as user selection. The value of the token
                            can be a pipe ('|') separated JavaHomes.
    -->

    <!-- <?xml version="1.0" encoding="UTF-8"?> -->
       <bea-installer>
         <input-fields>
           <data-value name="BEAHOME" value="/opt/thirdparty/middleware/oracle" />
           <data-value name="WLS_INSTALL_DIR" value="/opt/thirdparty/middleware/oracle/wls11g" />
           <data-value name="COMPONENT_PATHS"
            value="WebLogic Server/Core Application Server|WebLogic Server/Administration Console|WebLogic Server/Configuration Wizard and Upgrade Framework|WebLogic Server/Web 2.0 HTTP Pub-Sub Server|WebLogic Server/WebLogic JDBC Drivers|WebLogic Server/Third Party JDBC Drivers|WebLogic Server/WebLogic Server Clients|WebLogic Server/WebLogic Web Server Plugins|WebLogic Server/UDDI and Xquery Support|WebLogic Server/Server Examples|Oracle Coherence/Coherence Product Files" />
           <data-value name="INSTALL_NODE_MANAGER_SERVICE" value="yes" />
           <data-value name="NODEMGR_PORT" value="5559" />
           <data-value name="INSTALL_SHORTCUT_IN_ALL_USERS_FOLDER" value="yes"/>


    To run the Upgrade installer in silent mode:



    The process for upgrading an installation in silent mode is similar to the process for a full installation in silent mode, except that thesilent.xml file is much simpler. Please note the following issues when performing an upgrade in silent mode:
    • If you created a silent.xml file when you initially installed WebLogic Server, you should store it in a safe location or make a backup copy of it so that you do not accidentally overwrite it with the silent.xml file you are creating for your upgrade installation. Alternatively, you can name your upgrade file using a different file name, for example silent_upgrade.xml.
    • Incorrect entries in silent.xml can cause installation failures. To help you determine the cause of a failure, Oracle recommends that you create a log file when you start the installation. See Generating a Verbose Installation Log.
    • When using an Upgrade installer to upgrade an existing WebLogic Server installation on Linux or UNIX operating systems, you must run the Upgrade installer using the same user ID as was used to perform the initial WebLogic Server installation.
    • If you are upgrading an existing WebLogic Server 10.3.0, 10.3.1, 10.3.2, or 10.3.3 installation that includes Workshop for WebLogic, you must uninstall the Workshop components before upgrading your software. You must use either GUI mode or console mode to remove the Workshop components. See Uninstalling the Software, for more information.
      If you do not remove Workshop prior to running the Upgrade installer, you can remove it after the upgrade only by reverting to the previous installation and running the WebLogic uninstall program to remove the WebLogic components. WebLogic Server 10.3.6 does not support removal of Workshop components.
    Just in case, If we want to install any additional components which were missing in the main/first installation.. here is a way to upgrade.

    NOTE - Please take a back up of registry.xml and registry.dat file also as these files are going to get updated when you run upgrade installer -
    1. Create a silent.xml file (or silent_upgrade.xml file) to specify the Middleware home directory that contains the WebLogic Server installation you want to upgrade. See the sample in Sample silent.xml File for Upgrade Installation.
    2. Save the XML file in the directory in which the Upgrade installer is stored.
    3. Start the Upgrade installer as described in one of the following sections:
    Make sure that the -silent_xml option points to the XML file you created for the upgrade installation.

    1. After the installation completes, if you are using the JRockit SDK, Oracle recommends that you upgrade your domains to use the latest production version. See Configuring Domains to Use the Latest Version of JRockit.
    For Example -

    ./wls1036_linux32.bin -mode=silent -silent_xml=silent_upgrade1.xml -log=wls_upgrade1.log -log_priority=debug

    <!-- <?xml version="1.0" encoding="UTF-8"?> -->
       <bea-installer>
         <input-fields>
           <data-value name="BEAHOME" value="/opt/thirdparty/middleware/oracle" />
           <data-value name="WLS_INSTALL_DIR" value="/opt/thirdparty/middleware/oracle/wls11g" />
           <data-value name="COMPONENT_PATHS"
            value="WebLogic Server/Evaluation Database|Oracle Coherence/Coherence Examples" />
        <!--
        <data-value name="LOCAL_JVMS" value="D:\jrockit_160_05|D:\jdk160_11"/>
        -->
       </input-fields>
    </bea-installer>

    Monday, July 27, 2015

    Validate XML file in LINUX


    xmllint --noout your_test_file.xml
    Example 1 -
    $xmllint --noout silent.xml
    silent.xml:53: parser error : XML declaration allowed only at the start of the document
    <?xml version="1.0" encoding="UTF-8"?>
         ^
    
    Example 2 -
    xmllint --valid --encode utf-8 silent.xml
    silent.xml:53: parser error : XML declaration allowed only at the start of the document
    <?xml version="1.0" encoding="UTF-8"?>
    
    
    - Srikanth Govada

    Friday, July 24, 2015

    Available, used and free memory in Solaris

    Available, used and free memory in Solaris

    To get the amount of memory installed use prtdiag:

    # prtconf | grep Memory
    Memory size: 16384 Megabytes
    ...

    The output shows ~16GB total memory. Then use sar to get the current free memory:

    # sar -r 1 1

    SunOS overmind 5.9 Generic_122300-13 sun4u    10/04/2011

    09:13:23 freemem freeswap
    09:13:24 1007947 31669782

    In this case 1007947KB. At least we need the pagesize:

    # pagesize
    8192

    The pagesize in this example is the default pagesize of 8192 Bytes. Then we begin to calcualte all. First we will divide 8192 through 1024 to get the pagesize in KB. The result will be obviously 8, which will be multiplied with the free memory:

    # echo 1012114*(8192/1024) | bc -l
    8096912.00000000000000000000

    The result is the above value in KB. To get the amount of free memory in GB we need to divide it by 1024 twice:

    # echo 8096912/1024/1024 | bc -l
    7.72181701660156250000

    With ~16GB available memory and ~7.7GB free memory we can see that ~8.3 memory is used. Attached a small script that can do the job:

    # vi /usr/local/sbin/free.sh
    #!/usr/bin/ksh

    # Available memory
    memory=`prtconf | grep Memory | head -1 | awk 'BEGIN {FS=" "} {print $3}'`
    gb_memory=`echo "scale=2; $memory/1024" | bc -l`

    # Free memory
    pagesize=`pagesize`
    kb_pagesize=`echo "scale=2; $pagesize/1024" | bc -l`
    sar_freemem=`sar -r 1 1 | tail -1 | awk 'BEGIN {FS=" "} {print $2}'`
    gb_freemem=`echo "scale=2; $kb_pagesize*$sar_freemem/1024/1024" | bc -l`

    # Used Memory
    gb_usedmem=`echo "scale=2; $gb_memory-$gb_freemem" | bc -l`

    # Conclusion
    echo "Avai Mem: $gb_memory GB"
    echo "Free Mem: $gb_freemem GB"
    echo "Used Mem: $gb_usedmem GB"


    Save it and make it executable:

    # chmod 755 free.sh

    A sample output may be like this:

    /usr/local/sbin/free.sh
    Avai Mem: 32.00 GB
    Free Mem: 7.51 GB
    Used Mem: 24.49 GB

    Thursday, June 25, 2015

    Useful “df” Commands to Check Disk Space in Linux


    On the internet you will find plenty of tools for checking disk space utilization in Linux. However, Linux has a strong built in utility called ‘df‘. The ‘df‘ command stand for “disk filesystem“, it is used to get full summary of available and used disk space usage of file system on Linux system.
    Using ‘-h‘ parameter with (df -h) will shows the file system disk space statistics in “human readable” format, means it gives the details in bytes, mega bytes and gigabyte.

    1. Check File System Disk Space Usage

    The “df” command displays the information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.
    [root@tecmint ~]# df
    
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2     78361192  23185840  51130588  32% /
    /dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
    /dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
    /dev/cciss/c0d0p1       295561     21531    258770   8% /boot
    tmpfs                   257476         0    257476   0% /dev/shm

    2. Display Information of all File System Disk Space Usage

    The same as above, but it also displays information of dummy file systems along with all the file system disk usage and their memory utilization.
    [root@tecmint ~]# df -a
    
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2     78361192  23186116  51130312  32% /
    proc                         0         0         0   -  /proc
    sysfs                        0         0         0   -  /sys
    devpts                       0         0         0   -  /dev/pts
    /dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
    /dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
    /dev/cciss/c0d0p1       295561     21531    258770   8% /boot
    tmpfs                   257476         0    257476   0% /dev/shm
    none                         0         0         0   -  /proc/sys/fs/binfmt_misc
    sunrpc                       0         0         0   -  /var/lib/nfs/rpc_pipefs

    3. Show Disk Space Usage in Human Readable Format

    Have you noticed that above commands displays information in bytes, which is not readable yet all, because we are in a habit of reading the sizes in megabytes, gigabytes etc. as it makes very easy to understand and remember.
    The df command provides an option to display sizes in Human Readable formats by using ‘-h’ (prints the results in human readable format (e.g., 1K 2M 3G)).
    [root@tecmint ~]# df -h
    
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/cciss/c0d0p2      75G   23G   49G  32% /
    /dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
    /dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
    /dev/cciss/c0d0p1     289M   22M  253M   8% /boot
    tmpfs                 252M     0  252M   0% /dev/shm

    4. Display Information of /home File System

    To see the information of only device /home file system in human readable format use the following command.
    [root@tecmint ~]# df -hT /home
    
    Filesystem  Type    Size  Used Avail Use% Mounted on
    /dev/cciss/c0d0p5 ext3     24G   22G  1.2G  95% /home

    5. Display Information of File System in Bytes

    To display all file system information and usage in 1024-byte blocks, use the option ‘-k‘ (e.g. –block-size=1K) as follows.
    [root@tecmint ~]# df -k
    
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2     78361192  23187212  51129216  32% /
    /dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
    /dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
    /dev/cciss/c0d0p1       295561     21531    258770   8% /boot
    tmpfs                   257476         0    257476   0% /dev/shm

    6. Display Information of File System in MB

    To display information of all file system usage in MB (Mega Byte) use the option as ‘-m‘.
    [root@tecmint ~]# df -m
    
    Filesystem           1M-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2        76525     22644     49931  32% /
    /dev/cciss/c0d0p5        24217     21752      1215  95% /home
    /dev/cciss/c0d0p3        29057     24907      2651  91% /data
    /dev/cciss/c0d0p1          289        22       253   8% /boot
    tmpfs                      252         0       252   0% /dev/shm

    7. Display Information of File System in GB

    To display information of all file system statistics in GB (Gigabyte) use the option as ‘df -h‘.
    [root@tecmint ~]# df -h
    
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/cciss/c0d0p2      75G   23G   49G  32% /
    /dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
    /dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
    /dev/cciss/c0d0p1     289M   22M  253M   8% /boot
    tmpfs                 252M     0  252M   0% /dev/shm

    8. Display File System Inodes

    Using ‘-i‘ switch will display the information of number of used inodes and their percentage for the file system.
    [root@tecmint ~]# df -i
    
    Filesystem            Inodes   IUsed   IFree IUse% Mounted on
    /dev/cciss/c0d0p2    20230848  133143 20097705    1% /
    /dev/cciss/c0d0p5    6403712  798613 5605099   13% /home
    /dev/cciss/c0d0p3    7685440 1388241 6297199   19% /data
    /dev/cciss/c0d0p1      76304      40   76264    1% /boot
    tmpfs                  64369       1   64368    1% /dev/shm

    9. Display File System Type

    If you notice all the above commands output, you will see there is no file system type mentioned in the results. To check the file system type of your system use the option ‘T‘. It will display file system type along with other information.
    [root@tecmint ~]# df -T
    
    Filesystem  Type   1K-blocks  Used      Available Use% Mounted on
    /dev/cciss/c0d0p2 ext3    78361192  23188812  51127616  32%   /
    /dev/cciss/c0d0p5 ext3    24797380  22273432  1243972   95%   /home
    /dev/cciss/c0d0p3 ext3    29753588  25503792  2713984   91%   /data
    /dev/cciss/c0d0p1 ext3    295561     21531    258770    8%    /boot
    tmpfs   tmpfs   257476         0    257476    0%   /dev/shm

    10. Include Certain File System Type

    If you want to display certain file system type use the ‘-t‘ option. For example, the following command will only display ext3 file system.
    [root@tecmint ~]# df -t ext3
    
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p2     78361192  23190072  51126356  32% /
    /dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
    /dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
    /dev/cciss/c0d0p1       295561     21531    258770   8% /boot

    11. Exclude Certain File System Type

    If you want to display file system type that doesn’t belongs to ext3 type use the option as ‘-x‘. For example, the following command will only display other file systems types other than ext3.
    [root@tecmint ~]# df -x ext3
    
    Filesystem           1K-blocks      Used Available Use% Mounted on
    tmpfs                   257476         0    257476   0% /dev/shm

    12. Display Information of df Command.

    Using ‘–help‘ switch will display a list of available option that are used with df command.
    [root@tecmint ~]# df --help
    
    Usage: df [OPTION]... [FILE]...
    Show information about the file system on which each FILE resides,
    or all file systems by default.
    
    Mandatory arguments to long options are mandatory for short options too.
      -a, --all             include dummy file systems
      -B, --block-size=SIZE use SIZE-byte blocks
      -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      -H, --si              likewise, but use powers of 1000 not 1024
      -i, --inodes          list inode information instead of block usage
      -k                    like --block-size=1K
      -l, --local           limit listing to local file systems
          --no-sync         do not invoke sync before getting usage info (default)
      -P, --portability     use the POSIX output format
          --sync            invoke sync before getting usage info
      -t, --type=TYPE       limit listing to file systems of type TYPE
      -T, --print-type      print file system type
      -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
      -v                    (ignored)
          --help     display this help and exit
          --version  output version information and exit
    
    SIZE may be (or may be an integer optionally followed by) one of following:
    kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
    
    Report bugs to <bug-coreutils@gnu.org>.

    Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories


    The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner.


    1. To find out the disk usage summary of a /home/tecmint directory tree and each of its sub directories. Enter the command as:
    [root@tecmint]# du  /home/tecmint
    
    40      /home/tecmint/downloads
    4       /home/tecmint/.mozilla/plugins
    4       /home/tecmint/.mozilla/extensions
    12      /home/tecmint/.mozilla
    12      /home/tecmint/.ssh
    689112  /home/tecmint/Ubuntu-12.10
    689360  /home/tecmint
    The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.
    2. Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in BytesKilobytes, MegabytesGigabytes etc.
    [root@tecmint]# du -h /home/tecmint
    
    40K     /home/tecmint/downloads
    4.0K    /home/tecmint/.mozilla/plugins
    4.0K    /home/tecmint/.mozilla/extensions
    12K     /home/tecmint/.mozilla
    12K     /home/tecmint/.ssh
    673M    /home/tecmint/Ubuntu-12.10
    674M    /home/tecmint
    3. To get the summary of a grand total disk usage size of an directory use the option “-s” as follows.
    [root@tecmint]# du -sh /home/tecmint
    
    674M    /home/tecmint
    4. Using “-a” flag with “du” command displays the disk usage of all the files and directories.
    [root@tecmint]# du -a /home/tecmint
    
    4       /home/tecmint/.bash_logout
    12      /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
    24      /home/tecmint/downloads/Phpfiles-org.tar.bz2
    40      /home/tecmint/downloads
    12      /home/tecmint/uploadprogress-1.0.3.1.tgz
    4       /home/tecmint/.mozilla/plugins
    4       /home/tecmint/.mozilla/extensions
    12      /home/tecmint/.mozilla
    4       /home/tecmint/.bashrc
    689108  /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
    689112  /home/tecmint/Ubuntu-12.10
    689360  /home/tecmint
    5. Using “-a” flag along with “-h” displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in KilobytesMegabytes etc.
    [root@tecmint]# du -ah /home/tecmint
    
    4.0K    /home/tecmint/.bash_logout
    12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
    24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
    40K     /home/tecmint/downloads
    12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
    4.0K    /home/tecmint/.mozilla/plugins
    4.0K    /home/tecmint/.mozilla/extensions
    12K     /home/tecmint/.mozilla
    4.0K    /home/tecmint/.bashrc
    673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
    673M    /home/tecmint/Ubuntu-12.10
    674M    /home/tecmint
    6. Find out the disk usage of a directory tree with its subtress in Kilobyte blcoks. Use the “-k” (displays size in 1024 bytes units).
    [root@tecmint]# du -k /home/tecmint
    40      /home/tecmint/downloads
    4       /home/tecmint/.mozilla/plugins
    4       /home/tecmint/.mozilla/extensions
    12      /home/tecmint/.mozilla
    12      /home/tecmint/.ssh
    689112  /home/tecmint/Ubuntu-12.10
    689360  /home/tecmint
    7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human readable format.
    [root@tecmint]# du -mh /home/tecmint
    
    40K     /home/tecmint/downloads
    4.0K    /home/tecmint/.mozilla/plugins
    4.0K    /home/tecmint/.mozilla/extensions
    12K     /home/tecmint/.mozilla
    12K     /home/tecmint/.ssh
    673M    /home/tecmint/Ubuntu-12.10
    674M    /home/tecmint
    8. The “-c” flag provides a grand total usage disk space at the last line. If your directory taken 674MBspace, then the last last two line of the output would be.
    [root@tecmint]# du -ch /home/tecmint
    
    40K     /home/tecmint/downloads
    4.0K    /home/tecmint/.mozilla/plugins
    4.0K    /home/tecmint/.mozilla/extensions
    12K     /home/tecmint/.mozilla
    12K     /home/tecmint/.ssh
    673M    /home/tecmint/Ubuntu-12.10
    674M    /home/tecmint
    674M    total
    
    9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag “-–exclude“. See the output there is no txt files entry.
    [root@tecmint]# du -ah --exclude="*.txt" /home/tecmint
    
    4.0K    /home/tecmint/.bash_logout
    12K     /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
    24K     /home/tecmint/downloads/Phpfiles-org.tar.bz2
    40K     /home/tecmint/downloads
    12K     /home/tecmint/uploadprogress-1.0.3.1.tgz
    4.0K    /home/tecmint/.bash_history
    4.0K    /home/tecmint/.bash_profile
    4.0K    /home/tecmint/.mozilla/plugins
    4.0K    /home/tecmint/.mozilla/extensions
    12K     /home/tecmint/.mozilla
    4.0K    /home/tecmint/.bashrc
    24K     /home/tecmint/Phpfiles-org.tar.bz2
    4.0K    /home/tecmint/geoipupdate.sh
    4.0K    /home/tecmint/.zshrc
    120K    /home/tecmint/goaccess-0.4.2.tar.gz.1
    673M    /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
    673M    /home/tecmint/Ubuntu-12.10
    674M    /home/tecmint
    10. Display the disk usage based on modification of time, use the flag “–time” as shown below.
    [root@tecmint]# du -ha --time /home/tecmint
    
    4.0K    2012-10-12 22:32        /home/tecmint/.bash_logout
    12K     2013-01-19 18:48        /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
    24K     2013-01-19 18:48        /home/tecmint/downloads/Phpfiles-org.tar.bz2
    40K     2013-01-19 18:48        /home/tecmint/downloads
    12K     2013-01-19 18:32        /home/tecmint/uploadprogress-1.0.3.1.tgz
    4.0K    2012-10-13 00:11        /home/tecmint/.bash_history
    4.0K    2012-10-12 22:32        /home/tecmint/.bash_profile
    0       2013-01-19 18:32        /home/tecmint/xyz.txt
    0       2013-01-19 18:32        /home/tecmint/abc.txt
    4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/plugins
    4.0K    2012-10-12 22:32        /home/tecmint/.mozilla/extensions
    12K     2012-10-12 22:32        /home/tecmint/.mozilla
    4.0K    2012-10-12 22:32        /home/tecmint/.bashrc
    24K     2013-01-19 18:32        /home/tecmint/Phpfiles-org.tar.bz2
    4.0K    2013-01-19 18:32        /home/tecmint/geoipupdate.sh
    4.0K    2012-10-12 22:32        /home/tecmint/.zshrc
    120K    2013-01-19 18:32        /home/tecmint/goaccess-0.4.2.tar.gz.1
    673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
    673M    2013-01-19 18:51        /home/tecmint/Ubuntu-12.10
    674M    2013-01-19 18:52        /home/tecmint