Skip to content

Instantly share code, notes, and snippets.

@tizee
Last active August 20, 2020 02:22
Show Gist options
  • Save tizee/f0ceef47954ad8c4a9359fd4ed3296c8 to your computer and use it in GitHub Desktop.
Save tizee/f0ceef47954ad8c4a9359fd4ed3296c8 to your computer and use it in GitHub Desktop.
Linux/Unix find command examples
# Usage: combined with rm / cp / xargs / ... using pipe
# Find files with specific name e.g. foo and print them
find . -name "foo" -print
# Find files with specific types e.g. directories
find . -type d -print
# Find files under specific path e.g ~/foo/
find . -path "~/foo/*" -print
# Examples
# Copy a npm package repository
# Do not copy:
# 1. .cache/
# 2. node_modules/ - local packages
# 3. public/ (build output)
find . -maxdepth 1 ! -name ".cache" ! -path "./node_modules" ! -path "./public" ! -path "." -print0 | xargs -0 -I {} cp -rvf {} ~/dest/
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -false -o -name '*.txt'
@tizee
Copy link
Author

tizee commented Feb 17, 2020

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