Sample Header Ad - 728x90

Does a command exist that lists all the directories where a word appears in a file or directory name?

0 votes
3 answers
68 views
When I don't remember where a file or a folder is, I sometime use the locate command (that finds more occurrences, allow more candidates than a find, in my mind. But maybe I'm mistaking). But then there's a lot of responses, of course:
locate clang
/data/sauvegardes/dev/Java/Experimentations/Angular4/bikes/node_modules/blocking-proxy/.clang-format
/data/sauvegardes/dev/Java/Experimentations/Angular4/bikes/node_modules/node-gyp/gyp/tools/Xcode/Specifications/gyp.xclangspec
/data/sauvegardes/dev/Java/Experimentations/Angular6/ng6-proj/node_modules/blocking-proxy/.clang-format
/data/sauvegardes/dev/Java/Experimentations/Angular6/ng6-proj/node_modules/node-gyp/gyp/tools/Xcode/Specifications/gyp.xclangspec
/data/sauvegardes/dev/Java/Experimentations/blog-demo/node/node_modules/npm/node_modules/node-gyp/gyp/tools/Xcode/Specifications/gyp.xclangspec
/data/sauvegardes/dev/Java/Experimentations/blog-demo/node_modules/blocking-proxy/.clang-format
/data/sauvegardes/dev/Java/Experimentations/blog-demo/node_modules/node-gyp/gyp/tools/Xcode/Specifications/gyp.xclangspec
/data/sauvegardes/dev/Java/Experimentations/ol-ext-angular/.metadata/.plugins/ts.eclipse.ide.server.nodejs.embed.win32.win32.x86_64/node-v6.9.4-win-x64/node_modules/npm/node_modules/node-gyp/gyp/tools/Xcode/Specifications/gyp.xclangspec

(201 responses)
I piped this command, with dirname, sort and uniq to list only directories having such word in their name or carrying one or more file having it.
locate clang | xargs -L1 dirname | sort | uniq
it works...
/home/lebihan/dev/Java/comptes-france/metier-et-gestion/AdapterInboundWebEtude/etude/node_modules/node-gyp/gyp/tools/Xcode/Specifications
/home/lebihan/dev/Java/comptes-france/metier-et-gestion/AdapterInboundWebEtude/etude/node/node_modules/npm/node_modules/node-gyp/gyp/tools/Xcode/Specifications
/usr/include/boost/align/detail
/usr/include/boost/config/compiler
/usr/include/boost/predef/compiler
/usr/lib/linux-kbuild-6.1/scripts
/usr/lib/llvm-14/lib
/usr/lib/postgresql/14/lib/bitcode/postgres/commands
/usr/lib/x86_64-linux-gnu
/usr/local/go/misc/ios
/usr/local/go/src/debug/dwarf/testdata
/usr/local/go/src/debug/elf/testdata
/usr/local/go/src/debug/macho/testdata
/usr/share/doc
/usr/share/doc/libclang1-14
/usr/share/doc/libclang-cpp14

(108 responses)
But does _Linux_ have a command doing the same, more easily?
Asked by Marc Le Bihan (2353 rep)
Oct 31, 2023, 07:34 AM
Last activity: Oct 31, 2023, 10:20 AM