Here you will find more than 50000 job interview questions

Job Questions Search Engine


Sponsored Links

How to use find command with grep command

September 7, 2010 by bigboss · Leave a Comment
Filed under: Unix Command Interview Questions 

Manages arguments passed to another command. This is often used either to increase efficiency (avoiding calling a command once for each argument) or to overcome shell environment limits (“Argument list too long”). It works by collecting arguments and invoking your command.

xargs is used to pass command arguments to the other process . So if we want to transfer output of the find command to the grep command we can use xargs.

find . -type f -print | xargs grep ‘oldmonk”

This command will search for all file in the current directory recusively (only file not directory) which contain ‘oldmonk’

Explain find command in Unix

find : Is used to find a file in the directory or a file system

Usage:

1. find . -print //List all file in the current directory recursive

2. find .    -name  *.html”  -print // Find all file in the current directory with .html recursive

3. find . -mtime -7 -name  “*.html”  -print // Find all file which has been modified in last 7 days

4. find . -mtime  7 -name  “*.html”  -print // Find all file which has been exactly  7 days back

5. find . -mtime  +7  -name  “*.html”  -print // Find all file which has not been modified in last 7 days

To find files in more than one directory through find command you can specify more than 1 directory at the start

for example:

6. find /usr /bin -name “*\.htm*”  -print

To find file of specific type :

7. find . -type d -print //type d stands for directory

Below are the other type options in find command

d -Directory
f – File
l – Link

FIND COMMAND INTERVIEW QUESTIONS,  FIND COMMAND USAGE, FIND COMMAND OPTIONS, WHY FIND COMMAND IS BEING USED UNIX FIND COMMAND

More find command examples :

find $HOME -mtime 0 // Find all files which has been modified in last 24 hours in your home directory

find $HOME -mtime +365 // Find all files which has not been modifed in  last 365 days

find $HOME -newer ~joeuser/lastbatch.txt // Find all newer file in home directory which is newer than lastbatch.txt

More Linux find command options:

name: Finds files with certain naming conventions in the directory structure
-ctime time interval Locates files that that were created during the specified time interval
-mtime time interval Finds files that have been modified during the specified time interval
-atime time interval Locates files that have been accessed during the specified time interval
-perm permissions Locates files with certain permission settings
-user Locates files that have specified ownership
-group Locates files that are owned by specified group
-size Locates files with specified size
-type Locates a certain type of file

  • Categories

    |
  • Tags

    ADO.NET Questions Algorithm Questions ASP.NET Questions auto_ptr Binary tree questions C++ Constructor Interview Questions C++ Questions CISCO Exams Questions Common Interview Questions Core Java Interview Questions Csharp Questions datastructure questions Delphi 6 find command gdb interview questions grep interview questions IBM certification exams questions Infosys Puzzles Java Struts Linked List Problem Linux Command Questions List Manager Interview Questions Markov Algorithm memory leakage mysql Interview Questions Normalization Oracle Application Developer Certification Exam Interview Questions Oracle Questions Perl Questions PHP Questions Pointers Interview Questions PostgreSQL Database Questions pthread interview questions Smart Pointer Solaris Interview Questions SQL SERVER Interview Questions STL STL Map Symbian OS Tricky Interview Questions Unix Interview Questions unix shell Vector Windows OS Questions