Thursday 27 April 2017

Unix Basic Commands - Part 2

1)      Identifying the files by modified or accessed or changed time in a particular duration
                Find -mtime 0 –type f     (Files which are modified today)
                Find -ctime 3 –type f      (Files which are Created in last 3 days)
    Find  -atime +3 –type f    (Files which are accessed in last 3 days)

2)      Identifying the files on which you have privileges (Read -4, Write -2 and Execute -1)
Following command Displays all files which has read, write and Execute privileges (4+2+1)(4+2+1)(4+2+1)
Find –perm  777

3)      Command to read files from sub folders
Cat  /subfolder/filename
4)      Read the header and footer of a file
Header:
                                 Sed –n –e ‘1p’ header_footer>header
Footer
                                Sed –n –e ‘$p’ header_footer>footer
5)      Checking the completeness of a file
       Check the file contain EOF file or not,
       Ex: if [ $(sed –n ‘$p’ $j | grep "EOF" | wc -l) -ne 0 ]

6)      Moving a file form one folder to another
Syntax:
mv from_file_folder to_file_folder

Example:
mv   /home/raghu/task1/file1   /home/Raghu

7)      Finding a string in a file
grep “string” filename
8)      Counting number of words in a file
wc –w filename
9)      Create a file with output of command
Command > filename

No comments:

Post a Comment