Last active
August 20, 2020 02:22
-
-
Save tizee/f0ceef47954ad8c4a9359fd4ed3296c8 to your computer and use it in GitHub Desktop.
Linux/Unix find command examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More use cases: http://www.theunixschool.com/2012/07/find-command-15-examples-to-exclude.html