2

This question already has an answer here:

I have an account number 1234-5678, I am trying to find it in all files of directories. I used the below command but no result found.

grep "1234-5678" */

Please can someone help me how to find it in all files of directories.

marked as duplicate by terdon Apr 1 '15 at 12:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Use the -r, --recursive switch of grep. – FloHimself Apr 1 '15 at 12:22
  • grep "1234-5678" * -r or grep "1234-5678" * -R – Milind Dumbare Apr 1 '15 at 12:23
  • Did you not ask that same question just 3 weeks ago? What's wrong with the answers you got there? What version of AIX are you using? – Stéphane Chazelas Apr 1 '15 at 12:44
  • @Stéphane Chazelas sorry i have forgot about that, so i posted this. – Aravind Apr 1 '15 at 12:48
  • For your penance, can you please go and double-check if AIX's grep -R searches in fifos, devices or the target of symlinks? mkdir X; ln -s /etc/issue X/a; mkfifo X/b; grep -R . X and see if it hangs or matches on /etc/issue. – Stéphane Chazelas Apr 1 '15 at 13:02
3

Portably/standardly:

find . -type f -exec grep 1234-5678 /dev/null {} +

Some grep implementations have -r or -R options to search in files recursively. The behaviour varies from implementation to implementation though.

With the grep found in AIX 6.1 for instance, you'll probably want to use the -R option1.

Beware though that contrary to the find approach above, it may look in non-regular files like fifos or device files (or may not, I don't have access to an AIX system just now).

1 Support for those -r/-R options was added in AIX 5.3 according to IBM's online documentation. And it should be noted that the meaning of -r/-R is the reverse from that of GNU grep (-r follows symlinks to directories, and -R doesn't while it's the contrary with GNU grep)

2

grep "1234-5678" * -r or grep "1234-5678" * -R if you want to follow the symbolic links.

  • 3
    Having options after arguments is a GNUism and will typically not fork in non-GNU systems like the OP's AIX. Also note that the meaning of -r/-R is reversed between GNU and AIX greps. You command may not work if there are file names that start with -. It will also exclude hidden files and dirs in the current directory, but not in sub-directories. – Stéphane Chazelas Apr 1 '15 at 12:27
  • 1
    Then (s)he can use your solution ;-) Good explanation BTW. – Milind Dumbare Apr 1 '15 at 12:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.