Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Last active November 21, 2024 04:37
Show Gist options
  • Save Shaun289/fb66e104bd0ea2f79a30a81a5422e508 to your computer and use it in GitHub Desktop.
Save Shaun289/fb66e104bd0ea2f79a30a81a5422e508 to your computer and use it in GitHub Desktop.
test find in bash

Environment

$ cat /etc/issue
Ubuntu 22.04.5 LTS \n \l
$ echo $SHELL
/usr/bin/bash

find names including "gdb" only directory

  • I want to find names including "gdb" only directory.

Create directories and files to test

$ touch aa
$ mkdir gdb
$ mkdir 3gdb2
$ touch 2gdb2
$ ls  -al
$ touch 3gdb2/gdb.txt
$ touch gdb/gdb.txt
$ tree
.
├── 2gdb2
├── 3gdb2
│   └── gdb.txt
├── aa
└── gdb
    └── gdb.txt

2 directories, 4 files

Test find

  • find names including "gdb" only directory.
$ find . -type d -name "*gdb*"
./3gdb2
./gdb
  • find names "gdb" only directory.
$ find . -type d -name gdb
./gdb
  • find names including "gdb" only file.
$ find . -type f -name "*gdb*"
./3gdb2/gdb.txt
./2gdb2
./gdb/gdb.txt
  • find names "config.log" only file in "github/"
$ echo github/ | xargs -i find {} -type f -name config.log
github/vim/src/auto/config.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment