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? |
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.
|
Code:
find . -type f -exec file {} \; |
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 PS. The first argument to find needs to be a path. |
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.*" Quote:
Code:
find -type f -iname "*root.*" Quote:
the Code:
-iname Quote:
|
Quote:
./bar: ASCII text ./checker: POSIX shell script, ASCII text executable |
Quote:
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 .... |
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). |
Quote:
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 |
Quote:
|
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/ |
Quote:
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? |
The file command takes multiple (file-)arguments, so you can do
Code:
find . -type f -exec file {} + |
Quote:
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 |
Quote:
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? |
Quote:
I suppose the forward slashes would be useable as a field separator? I know I could use something like the below in order to define what is a valid IP address: (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) |
Not as bad as it looks, and very much worth learning.
As you are actually learning and paying attention, perhaps a working example will encourage you to follow through. Here is a simple awk that does the trick: Code:
echo 'https://192.168.3.4/random/directories/here/' |awk -F\/ '{print $3}' Awk is the go-to tool for most text extractions and manipulations. Regular expressions are the foundation for most of the real power of text manipulations, and sed puts those right at your fingertips. Here is a sed that produces the same result. Code:
echo 'https://192.168.3.4/random/directories/here/' |sed 's/.*\/\/\([^\/]*\).*/\1/' Code:
echo 'https://some.host.com/random/directories/here/' |sed 's/.*\/\/\([^\/]*\).*/\1/' And just to expand on TB0ne's comments - the rules are there to keep things helpful and friendly here at LQ. If you are looking for someone to do your homework for you, this is not the place. On the other hand, if you are learning and growing and want to share in the experience - it is all good! Welcome to LQ and good luck! |
Quote:
Definitely here to learn/grow/share in the experience so seems like I came to the right place! Thanks all for your input |
Quote:
http://www.linuxquestions.org/questi...2/#post4654486 The complexity and flexibility of *nix is truly awesome, compared to other OS'es. |
Quote:
echo 'https://192.168.3.4/random/directories/here/' |awk -F\/ '{print $3}' I completely understand this command up until $3 I know $ signs signify variables (?), but I don't understand why the number 3 is used? |
Quote:
Once you've identified the field, you can then work on the field further. Keep checking the manual page for awk, it's a good reference work for the language and will make sense more and more. Also there are some good books on sed and awk, check your local college technical or engineering library. IFF the library is any good then there will be at least one such book available. Some wiggle room in that task is that what is allowed in a URL is not universally agreed upon. Regarding sed, the characters delimiting the search and replace pattern only need to be three of a kind. So if you are working with a lot of slashes in your patterns then you can use something else like a pound sign # or pipe | or an exclamation mark: Code:
echo $URL | sed -e 's#^.*//##; s#/.*$##;' |
Quote:
|
All times are GMT -5. The time now is 07:33 PM. |