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 . )

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 .
#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
view raw find-name.sh hosted with ❤ by GitHub

3 ) If we want to match either of the multiple criteria , we can use OR option (-o)
find . \( -name "*.txt" -o -name "*.pdf" \) -print
# HERE , the above command will match either the file ends with txt or pdf
view raw find-or.sh hosted with ❤ by GitHub

4 )  The -path argument can be used to match the wildcards.
find /home/users -path "/*lazy*/" -print
view raw find-path.sh hosted with ❤ by GitHub


5 )To find all files other than some files .
find . ! -name "*.txt" -print
view raw find-neg.sh hosted with ❤ by GitHub


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.
find . -maxdepth 2 -name "*.txt"
find . -mindepth 2 -name "*.pdf"
view raw find-minmax.sh hosted with ❤ by GitHub


7) Finding files using their types either directory  , files , links 
# 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
view raw find-tiime.sh hosted with ❤ by GitHub


8 ) Finding files using their size .
for more details and working see this video

Comments

Popular posts from this blog

Python : Is Just a Hype ?

What is the best way to learn Programming ?

Dangerous commands in linux that you should never try .