Skip to content

Instantly share code, notes, and snippets.

@mistical2008
Forked from remarkablemark/find.md
Created March 21, 2018 06:47
Show Gist options
  • Select an option

  • Save mistical2008/86cde70d1ebcbef65fda59b7e0cec295 to your computer and use it in GitHub Desktop.

Select an option

Save mistical2008/86cde70d1ebcbef65fda59b7e0cec295 to your computer and use it in GitHub Desktop.

find

List all files and directories in directory:

find <directory>

List all files in directory:

find <directory> -type f

List all directories in directory:

find <directory> -type d

List all files matching pattern:

find <directory> -type f -name <pattern>

Delete all matching files:

find <directory> -type f -name <pattern> -delete

Execute command on all matching files:

find <directory> -type f -name <pattern> -exec <command>

Examples

Delete all swap files:

find . -type f -name "*.swp" -delete

Alternative approach using xargs:

find . -type f -name "*.swp" | xargs rm

Delete all swap files with confirmation:

find . -type f -name "*.swp" -exec rm -i {} ";"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment