2

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.

Aravind
  • 1,599

2 Answers2

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 01 '15 at 12:27
  • 1
    Then (s)he can use your solution ;-) Good explanation BTW. – Milind Dumbare Apr 01 '15 at 12:32