Is it possible to grep for a string that is hidden within multiple directories from the root directory of my server? For instance, if I SSH into my Ubuntu server and then want to grep for a certain string, but I don't know which subfolder it is in, can I just grep from the root directory?


2 Answers 2


Yes, you can, but depending on how your server is set up, this might take a very long time (or never complete). If you're absolutely sure the disks are all local you can execute:

grep --recursive --ignore-case "string" /

for more info:

man grep
  • My output from that is: Sep 24, 2018 at 17:57
  • root@wavbyte:/# grep --recursive --ignore-case "sample" / grep: /proc/sys/fs/binfmt_misc/register: Invalid argument grep: /proc/sys/net/ipv4/route/flush: Permission denied grep: /proc/sys/net/ipv6/conf/all/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/default/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/eth0/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/eth1/stable_secret: Input/output error grep: /proc/sys/net/ipv6/conf/lo/stable_secret: Input/output error grep: /proc/sys/net/ipv6/route/flush: Permission denied Sep 24, 2018 at 17:58
  • It stopped searching after those outputs Sep 24, 2018 at 19:21
  • Like I said: ...depending on how your system is set up... in this case your user does not have access to those directories, but the command will continue searching the rest of the file system. The answer did mention it ...might take a very long time... ;-)
    – Fabby
    Sep 24, 2018 at 19:25
  • 1
    @Shayan that would be a new question. Provide much more detail on the server itself like the fstab and if that contains IP addresses or remote shares, provide a ping -c 5 IP.AD.DR.ES output for each and I can tell you. The answer does say it depends on your server setup...
    – Fabby
    Sep 1, 2019 at 20:54

You can use the -r option to grep recursively:

Read all files under each directory, recursively, following symbolic links only if they are on the command line.

On a typical system, it might not be a good idea, as grep doesn't have an option to not descend into mounted file systems. You would end up going through file systems like /proc.

  • Is it bad to go through system files? And why?
    – Shayan
    Sep 1, 2019 at 19:29
  • 1
    The /proc file systems contains files such as /proc/kcore. It is very large on 32-Bit systems and huge ob 64.Bit systems.
    – RalfFriedl
    Sep 2, 2019 at 18:40
  • Ah.. that's why my sudo grep -rs "" / command never finished, even after 16 hours lol.. Thanks for answering :)
    – Shayan
    Sep 2, 2019 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .