Home > Blockchain >  Linux- finding files with grep
Linux- finding files with grep

Time:03-18

I'm new to Linux and I don't really know what I'm doing wrong. I need to find files in catalog /usr/sbin that have 'fs' in their name and don't start with 'x'. I need to write results in 111.txt file but cannot use find to do this. I tried this command but it doesn't work.

grep -r -v '^x' -w 'fs' /usr/sbin/ > 111.txt 

CodePudding user response:

You could pipe find into two chained grep commands instead:

find /usr/sbin/ | grep 'fs' | grep -v '^/usr/sbin/x' > 111.txt

CodePudding user response:

grep isn't meant for that, you should use find instead:

find /usr/sbin -type f -name '*fs*' -not -name 'x*' > 111.txt
  • Related