LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2017, 12:48 PM   #1
herpplederppleston
LQ Newbie
 
Registered: Feb 2017
Posts: 8

Rep: Reputation: Disabled
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?
 
Old 02-09-2017, 12:51 PM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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.
 
Old 02-09-2017, 12:58 PM   #3
nodir
Member
 
Registered: May 2016
Posts: 222

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

Last edited by nodir; 02-09-2017 at 01:00 PM.
 
Old 02-09-2017, 12:59 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,470
Blog Entries: 3

Rep: Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232
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.
 
Old 02-09-2017, 01:02 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,633

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
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???

Last edited by BW-userx; 02-09-2017 at 01:08 PM.
 
Old 02-09-2017, 01:06 PM   #6
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
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
 
Old 02-09-2017, 01:09 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,633

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
Quote:
Originally Posted by nodir View Post
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 ....

Last edited by BW-userx; 02-09-2017 at 01:12 PM.
 
1 members found this post helpful.
Old 02-09-2017, 01:28 PM   #8
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
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).
 
Old 02-09-2017, 01:56 PM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware FreeBSD Win10 MX
Posts: 9,633

Rep: Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074Reputation: 2074
Quote:
Originally Posted by nodir View Post
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.
 
Old 02-09-2017, 03:08 PM   #10
herpplederppleston
LQ Newbie
 
Registered: Feb 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by nodir View Post
Code:
find . -type f -exec file {} \;
http://mywiki.wooledge.org/UsingFind#Actions
thankyou very much sir!
 
Old 02-09-2017, 03:10 PM   #11
herpplederppleston
LQ Newbie
 
Registered: Feb 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
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/
 
Old 02-09-2017, 03:21 PM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,338

Rep: Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037
Quote:
Originally Posted by herpplederppleston View Post
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?
 
Old 02-09-2017, 06:16 PM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,294

Rep: Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595
The file command takes multiple (file-)arguments, so you can do
Code:
find . -type f -exec file {} +
that is faster.
 
Old 02-10-2017, 02:26 PM   #14
herpplederppleston
LQ Newbie
 
Registered: Feb 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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
 
Old 02-10-2017, 02:59 PM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,338

Rep: Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037Reputation: 6037
Quote:
Originally Posted by herpplederppleston View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
find command question mokku Linux - Newbie 16 06-09-2009 01:07 PM
Question on Find Command: - Vs + JockVSJock Linux - Newbie 4 04-29-2009 02:44 AM
Question about find command centosfan Linux - Server 2 11-10-2008 08:36 PM
Question on find command rytrom Linux - Newbie 3 08-07-2003 03:14 AM
Find Command - Basic Question tlb04 Linux - General 3 05-06-2003 09:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration