Monday, March 18, 2019


Part – 2:
Find Actions: -
Q) What is find action part ?
Ans – To perform operation on result set of find command, we use find action part.
Q) Find all files whose permission is 644 and change it to 755 in current directory ?
Ans - $ find . –type f –perm 644 –exec chmod 755 {} \;<Enter – Key>
Q) How to delete the temporary files in /tmp directory ?
Ans - $ find /tmp –type f –name ‘*.tmp’ –exec rm –f {} \;<Enter – Key>
Q) Find all the files created before 6 months having ‘core’ word in the name of the file and remove it ?
Ans - $ find . –type f –ctime +180 –name ‘*core*’ –delete<Enter – Key>
Or
$ find . –type f –ctime +180 –name ‘*core*’ –exec rm –f {} \;<Enter – Key>
Q) Search all ‘log’ files in /log directory and give me those files having ‘error’ word in it ?
Ans - $ find /log –type f –name ‘*.log’ –exec grep –l error {} \;<Enter – Key>
Q) Print the last line of all text files in current directory and comma followed by file name ?
Ans - $ find . –type f –name ‘*.txt’ -exec echo “$(tail -1 ‘{}’),$(ls ‘{}’)” \;<Enter – Key>
Q) Move all the files which are not modified within 6 months to /usr/archieve directory ?
Ans - $ find . –type f –mtime +180 –exec mv {} /usr/archeve \;<Enter – Key>
Q) What is the difference between exec and xargs ?
Ans –
1.       exec command will execute on the files return from find command one by one, whereas xargs operate on all files at a single time.
2.        exec command is less faster than xargs command.
3.       Pipe is not associated with exec command whereas xargs need it.

No comments:

Post a Comment

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...