Friday, May 27, 2022

[SOLVED] Linux- finding files with grep

Issue

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 

Solution

You could pipe find into two chained grep commands instead:

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


Answered By - Sasha Koshka
Answer Checked By - Pedro (WPSolving Volunteer)