1

This is a common $unix question thats asked in interviews. I know that you have to use find command but what is the exact answer? i searched in google but couldnt find a proper answer. below command i tried but its wrong.

$find / -name "UnixCommandInterviewQuestions”
0

1 Answer 1

1

Make sure you read the question very carefully.

It says that the file contains "UnixCommandInterviewQuestions", not that the file name is "UnixCommandInterviewQuestions".

One correct answer would be a recursive grep command, like:

grep -r UnixCommandInterviewQuestions /

There are other solutions that may be faster.

Sign up to request clarification or add additional context in comments.

4 Comments

how can you solve it using find command?
I don't think the find command deals with file contents, to my knowledge, merely file metadata (filename, timestamp metadata like last modified, etc). However you could use the find command (and it might be faster, I'm not sure). Try: find / -type f -exec grep UnixCommandInterviewQuestions {} \;
@Joe12 You should make an effort to understand these unix tools if this is for an interview for a job or for some kind of school assignment. I encourage you to try to write some bash scripts using these core utilities for a specific purpose. The best way to really learn how they work is to have a specific goal as opposed to needing to get a correct answer. It will make your life a lot easier and you'll be the one answering questions here instead of asking them. ;)
grep -r PATTERN / will read the contents of every "file" on your system. That includes pseudo-files with infinite content, such as /dev/zero, /dev/random, and /dev/urandom. It's also going to produce tons of error messages for files you don't have permission to read. The -xdev option to the find command is likely to be useful. Or start from a directory other than / if you happen to have some idea where the file is going to be.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.