LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find command question (https://www.linuxquestions.org/questions/linux-newbie-8/find-command-question-4175599374/)

herpplederppleston 02-09-2017 11:48 AM

Find command question
 
find -type f -name "root"

Say I was using the above command to find a file, how would I adjust the command to make each result have the file type displayed? I'm guessing it would involve piping the output to the file command somehow, but not sure?

r3sistance 02-09-2017 11:51 AM

What do you mean how would you get it to display the file type? You already limited to type f. Do you mean how do I check if it is executable or something else? I suspect the -ls flag maybe the answer but not entirely certain what it is you are after.

nodir 02-09-2017 11:58 AM

Code:

find . -type f -exec file {} \;
http://mywiki.wooledge.org/UsingFind#Actions

Turbocapitalist 02-09-2017 11:59 AM

You'll want to use the -exec option for find so it can call file for you. See the manual page for details.

Code:

man find
Or you could use the -print0 option and pipe the output to xargs --null which can in turn call file for you.

PS. The first argument to find needs to be a path.

BW-userx 02-09-2017 12:02 PM

the type is file, the extension to tell one what type of file it is is a different matter, it seems that yes that can get confusing.

Code:

find -type f -iname "root.*"
would return everything named root and whatever after the . period.

Quote:

root.sh
root.goba
Code:

find -type f -iname "*root.*"
would return everything with the word root in it and whatever after the period .
Quote:

babbryroot.sh

the
Code:

-iname
eliminates the caps or lower case but looks at both.

Quote:

Root.hoHOho
root.hojer
geEforoOt.here
oops did anyone notice I forgot a path to???:doh:

nodir 02-09-2017 12:06 PM

Quote:

Originally Posted by BW-userx (Post 5667918)
the type is file, the extension to tell one what type of file it is is a different matter, it seems that yes that can get confusing.

user$ find . -type f -exec file {} \;
./bar: ASCII text
./checker: POSIX shell script, ASCII text executable

BW-userx 02-09-2017 12:09 PM

Quote:

Originally Posted by nodir (Post 5667920)
user$ find . -type f -exec file {} \;
./bar: ASCII text
./checker: POSIX shell script, ASCII text executable

I never said your way was wrong or would not work, I just gave a different way of doing things.

file type is an ambiguous word here i think.

if that was just a hey check out what this can do post, then thanks, I cannot run it to see, I'm in windows ....

nodir 02-09-2017 12:28 PM

Nah, not "check what this can do."
I didn't fully understand what you meant with the type is file (obviously, but there are different files) and what you meant with extensions (which are not needed nor recommended, at least as far shell scripts are concerned).
Hence i quoted that part, not the explanations about find usage (which never hurts, imho).

BW-userx 02-09-2017 12:56 PM

Quote:

Originally Posted by nodir (Post 5667935)
Nah, not "check what this can do."
I didn't fully understand what you meant with the type is file (obviously, but there are different files) and what you meant with extensions (which are not needed nor recommended, at least as far shell scripts are concerned).
Hence i quoted that part, not the explanations about find usage (which never hurts, imho).

yeah I thought of that extensions thing after I posted too Because Linux does not put a .exe or anything on it even a shell script to get it to work. myshellscript.sh that was established only for reasons for easy and quick identification. Not so that it's actually "work", execute that is.

left over windows idealism I think is the source of my take on what s/he meant by file type. Though their is the .conf .ini and other such file types within Linux too one needs to take into consideration here. Now that my brain is thinking Linux and not Windows. :D

herpplederppleston 02-09-2017 02:08 PM

Quote:

Originally Posted by nodir (Post 5667915)
Code:

find . -type f -exec file {} \;
http://mywiki.wooledge.org/UsingFind#Actions

thankyou very much sir!

herpplederppleston 02-09-2017 02:10 PM

Whilst I have your attention, how about this one:

What command(s) would I use to extract the IP only from this URL?

https://192.168.3.4/random/directories/here/

TB0ne 02-09-2017 02:21 PM

Quote:

Originally Posted by herpplederppleston (Post 5667989)
Whilst I have your attention, how about this one:

What command(s) would I use to extract the IP only from this URL?

https://192.168.3.4/random/directories/here/

Read the LQ Rules....open new threads for new questions, and also read the "Question Guidelines". We're happy to help you, but these sound a LOT like verbatim homework questions..what effort have you put into this? Reading the man pages on commands would tell you a good bit, as with the find question you initially posted.

And to get the IP, you could use awk, split, grep, sed, or a combination of those things...along with others. What have you done/tried so far?

MadeInGermany 02-09-2017 05:16 PM

The file command takes multiple (file-)arguments, so you can do
Code:

find . -type f -exec file {} +
that is faster.

herpplederppleston 02-10-2017 01:26 PM

Quote:

Originally Posted by TB0ne (Post 5668000)
Read the LQ Rules....open new threads for new questions, and also read the "Question Guidelines". We're happy to help you, but these sound a LOT like verbatim homework questions..what effort have you put into this? Reading the man pages on commands would tell you a good bit, as with the find question you initially posted.

And to get the IP, you could use awk, split, grep, sed, or a combination of those things...along with others. What have you done/tried so far?

Thanks, sorry about that, will read the guidelines

I've tried a few of those commands, and also cut. Genuinely stumped on this. It's not homework, it's a kind of quiz, that permits "research" so I don't think I'm doing anything wrong. Not looking for exact answers, just a nudge in the right direction. I guess I should just read the man pages for all the aforementioned commands a bit more thoroughly

TB0ne 02-10-2017 01:59 PM

Quote:

Originally Posted by herpplederppleston (Post 5668479)
Thanks, sorry about that, will read the guidelines

I've tried a few of those commands, and also cut. Genuinely stumped on this. It's not homework, it's a kind of quiz, that permits "research" so I don't think I'm doing anything wrong. Not looking for exact answers, just a nudge in the right direction. I guess I should just read the man pages for all the aforementioned commands a bit more thoroughly

No worries, and yes, research is always the key to learning better. The options can get confusing, and we're always happy to explain things if you're stuck. The man pages are always a good starting point...unless you try looking at the ones for sed and awk, both of which can be hideously complicated, and are both very powerful commands. I think there's even an entire book written on them:
http://shop.oreilly.com/product/9781565922259.do

As a hint, look at the "-F" flag for awk, then look at your input string. See anything common at the beginning/end of what you're after that you can use as a field-separator?


All times are GMT -5. The time now is 07:56 AM.