-
-
Save thanhtam92/d2316f3bcdfd8520edf080d86e03282f to your computer and use it in GitHub Desktop.
linux find command
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
find command:http://www.oreillynet.com/linux/cmd/cmd.csp?path=f/find | |
find . -maxdepth 1/2/..../n | |
%to just find them and printout: | |
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n' | |
%delete them, may be modified to use | |
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n' | xargs rm | |
http://content.hccfl.edu/pollock/unix/findcmd.htm | |
# deleting command may be this ,too | |
find . -maxdepth 1 -size 0 -ok rm { } \; | |
#Remove all empty files on the system (prompting first): | |
find / -size 0 -ok rm { } \; | |
# 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