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”
Joe12
  • 69
  • 1
  • 12

1 Answers1

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.

Kevin
  • 1,489
  • 2
  • 20
  • 30
  • how can you solve it using find command? – Joe12 Aug 27 '17 at 20:08
  • 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 {} \;` – Kevin Aug 27 '17 at 20:11
  • @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. ;) – Kevin Aug 27 '17 at 20:17
  • 2
    `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. – Keith Thompson Aug 27 '17 at 20:18