Saturday, August 27, 2016

How to check file format for linux system

File system can be checked though one of below commands in linux system. these can be exeucted to check file system of given or all devices provided you have permission to do so.

1. using "df" disk filesystem command
   
-bash-3.2$ df -T | awk '{print $1,$2,$NF}' | grep "^/dev"
2. Using "/etc/fstab"

-bash-3.2$ cat /etc/fstab

3. Using "mount" command

-bash-3.2$ mount | grep "^/dev"
4. Using "file" command

file -sL /dev/sda1
5.  Using fsck command

fsck -N /dev/sda1



Tuesday, August 16, 2016

Directory permission in Linux

The permission on directory behaves differently than the normal files in Linux. below are meaning of permission bit on directory.
  1. Write bit (w): allows the affected user to create, rename, or delete files within the directory, and modify the directory's attributes.
  2. Read bit (r): allows the affected user to list the files within the directory.
  3. Execute bit (x): allows the affected user to enter the directory, and access files and directories inside.

Monday, August 8, 2016

How to compare two files in Linux

There are various tools provided in various linux flavors to compare two text files, but there are few common ways of doing this i as below.

1. Using "diff" command.
    It compare two files line by line and list out the differences.

    Syntax: diff [options] file1 file 2
 
     Options: options can be used to change behavior of command scope
                    -b Instruct the system to ignore extra spaces and tabs.
                    -w Ignore all white spaces
                    -i Ignore any case differences
                    -E Ignore changes due to tab expansion.
                    -c useful in comparing tow code files and points ! to indicate difference,- for less and +                             for  more
                    <for more options refer manual>
 
     Example:
   
                 file1:
                         1
                         2
                         3
                         4
                         5
                         6
                         7
                         8
                         9

                 file2:
                        1
                        2
                        3
                        7
                        8
                        9
                       10
                       11
                       16
     
            $ diff file1 file2


                4,6d3
                < 4
                < 5
                < 6
               9a7,9
                > 10
                > 11
                > 16

The output is produced in ED line editor format, which suggest what changes to file will make it same as other file being compared. in above example 4,6d3 means delete 3 lines from 4-6 in first file and 9a7,9 means append at 9th position line 7-9 from second file.

Note: diff can be used to compare files in two different directory.

2. Using "vimdiff" or "vim -d" text editor functionality
    this tool will display the difference in file in vertical column and highlighting the difference.

    Syntax: vimdiff file1 file2

    Example: vimdiff 1 2 or vim -d 1 2


   
3. Using "comm" command
     This command will compare the files and will display the difference in  3 column.

    Syntax: comm [-123i] file1 file2
                  -1 to display difference in 1st file compared to 2nd file
                  -2 to display difference in 2nd file compared to 1st file.
                  -3 to display matching lines.
                  -i to do case sensitive comparison.

     Example: comm 1 2
                                           1
                                           2
                                           3
4
5
6
                                           7
                                           8
                                           9
                  10
                  11

                  16