Home » Questions » Computers [ Ask a new question ]

Linux grep or find usage

Linux grep or find usage

How do I find a file on my harddisk that starts with io_file?

Asked by: Guest | Views: 9
Total answers/comments: 4
Guest [Entry]

"IMO, using find is slow for an entire harddrive search (it will also show you a lot of permission errors when accessing files you do not own). If possible, use locate:

locate -b 'io_file*'

You'll probably have to re-index if the file is newer than 24h (normally it sets a daily cronjob):

sudo updatedb"
Guest [Entry]

"The shell expands the wildcards and passes the result to grep, so you need to either escape the * or use quotes:

find / -name io_file\*
find / -name 'io_file*'
find / -name ""io_file*""

All three of these do the same thing on my Linux box."
Guest [Entry]

"find -name io_file* will search in the current directory and below only. If you want to search the entire harddrive, you need to specify the path: find / -name io_file*. Same thing goes with grep -r; it will only search in the current directory and below.

The find utility is very handy, but it may be a little counterintuitive to use. My recommendation is that you read the find man-page (man find), it is well worth the invested time."
Guest [Entry]

"Because you didn't give grep a file, it is operating on standard input and waiting for you to type something. It's the wrong command anyway. As for find you need a directory to start from and have to put io_file* in quotation marks, otherwise it gets expanded by the shell:

find / -name ""io_file*""

You can also use locate ""io_file*"" which is faster but may be inaccurate."