How to search files or directories with CentOS terminal/command line

How to search for files or directories from CentOS Terminal / Command Line, There are several commands you can use and one of them is what we discuss here. How to ignore case sensitivities, exclude some directories and so on.


How to use find command to search files or directories



If you want to search files within your account home directory

find ~/ -name 'thefilename.txt'

or some part of the file name using wildcard characters

find ~/ -name '*file*.txt'

this command will search within home directory and all sub directories, if you omit ~/ it will search within current directory and the sub directories.

To search and ignore case-sensitivity you can use -iname flag

find -iname 'TheFileName.txt'

If you want to search directories only or files only, you can use -type flag

this will search files only
find -iname '*FileName*' -type f

this will search directories only
find -iname '*FileNam*' -type d

To exclude directories or a specific directory you can use -prune flag.
for example if we want to search note.txt and want to exclude a directory named myDir within home directory.
find ~/ -type d -iname 'mydir' -prune -o -name 'note.txt'

and if you want to exclude myDir1, myDir2, myDir3, you can use
find ~/ -type d -iname 'mydir*' -prune -o -name 'note.txt'

Hope this helps. Thanks for reading.





More..


Please activate Javascript then press (F5), to open the page properly
Click on the link.
How To Fix, Free APK, Android, iOS.
http://turefix.blogspot.com/