Find Command and its attribute in Linux .
Finding a File inside a collection of files made tough . sometimes you may forgotten the filename , but you remember that you have accessed or modified by last 7 days . You can also find files that you have edited before or after accessed or modifed file .
1 ) To list the files in current Directory .
find . -print
This will print all the files in the current directory (mentioned by . )1 ) To list the files in current Directory .
find . -print
2 )Find command is a powerful command line tool and its armed with a variety of interesting options -name argument specifies a matching string for the filename .
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
#The find command is a powerfull command line tool and its aimed with a variety of interesting options . | |
find /home/lazyswapper -name "*.txt" -print | |
# To Ignore cases | |
find /home/lazyswapper -iname "*.txt" -print |
3 ) If we want to match either of the multiple criteria , we can use OR option (-o)
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 . \( -name "*.txt" -o -name "*.pdf" \) -print | |
# HERE , the above command will match either the file ends with txt or pdf |
4 ) The -path argument can be used to match the wildcards.
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 /home/users -path "/*lazy*/" -print |
5 )To find all files other than some files .
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 . ! -name "*.txt" -print |
6 ) while finding some files , it will list all of the files that are available in the current directory and all of its sub directory . so we can control it by using maxdepth and mindepth.
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 . -maxdepth 2 -name "*.txt" | |
find . -mindepth 2 -name "*.pdf" |
7) Finding files using their types either directory , files , links
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
# to find all files that are been accessed older than 7 days | |
find . -atime +7 | |
# to find all files that are been accessed lesser that 7 days | |
find . -atime -7 | |
# to find all files that are been accessed exactly 7 days | |
find . -atime 7 | |
8 ) Finding files using their size .
for more details and working see this video
Comments
Post a Comment