Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Created December 22, 2022 13:20
Show Gist options
  • Save tcpdump-examples/693ed4352999c3ba13e38c0728c482a4 to your computer and use it in GitHub Desktop.
Save tcpdump-examples/693ed4352999c3ba13e38c0728c482a4 to your computer and use it in GitHub Desktop.

find command:https://www.howtouselinux.com/post/find-file-by-name-in-linux

Use find command, find all *.txt files but ignore foo.txt

find . -type f ( -iname "*.txt" ! -iname "foo.txt" )

To delete file add -delete or -exec your-delete-command-here option.

find . -type f ( -iname "*.txt" ! -iname "foo.txt" ) -delete

To select folder or dirs use -type d, in this example, find all folders and ignore foo and bar folder :

find . -type d ( ! -iname "foo" ! -iname "bar" )

To delete folders except foo and bar

find . -type d ( ! -iname "foo" ! -iname "bar" ) -execdir rm -rfv {} +

Be careful while deleting files and dirs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment