pkg search

I am wondering if it is possible to exclude entries in searches? alot of simple searches return unwanted results. For example, pkg search xml is full of p5-, py-, py311- and rubygem- results. Actually, alot of searches are full of p5-, py- and rubygem- results. The search results would be nicer without these entries. xml is too general. Is it possible to use regex?
 
Is it possible to use regex?
What do you think -x does or stands for? pkg-search(8) is your friend here:

Code:
     pkg search [--{comment,description,depends-on,full,origins,prefix}]
                [--{quiet,raw,size,no-repo-update}] [--repository reponame]
                [--{case-sensitive,exact,glob,case-insensitive,regex}]
                [--raw-format format] pattern
....SNIP....
     -x, --regex
                 Treat pattern as a regular expression according to the
                 "modern" or "extended" syntax of re_format(7).  This is the
                 default.  Matches any substring of the search field unless
                 explicit beginning or ending anchor terms are used.
And if you then check re_format(7) (and regex(3)) you'll see that exclusions are possible.

Code:
peter@bsd:/home/peter $ pkg info -x ^xml
xmlcatmgr-2.2_4
xmlcharent-0.3_2
xmlto-0.0.28_3
peter@bsd:/home/peter $ pkg info -x xml | wc -l
       7
 
There are several ways, depending on if you're looking for a certain package, or browse packages.
pkg-search(8) already itself brings some options.
The classic way is to filter the output through grep(1) which can inlcude or exclude certain patterns, example:
pkg search xml | grep Ruby

You also may search for a certain package using a search engine (e.g. duckduckgo.com), or browse what all is available in
FreeBSD Ports Search
 
one can also pipe the output of pkg search into any other grep/egrep/whatever regex tool you want, yes basically the same thing Maturin says.
My personal opinion is I hate trying to remember regex options for every different tool I use. I concentrate on learning and remembering what I need for grep and then take advantage of Unix "every tool should push to stdout" and pipe things together.
 
Maturin , mer Thanks for the info :) please note that i am a Windows user for 26 years. I have no experience with grep outside of the basics mentioned in the handbook. I will learn how to use grep and piping (which was mentioned to me by SDKchan some time ago). For now, i just wanted a quick regex method of filtering out all of that p5- perl, py- python and rubygem- mess. I am a php programmer and even the php entries are annoying. I promise to learn the Unix way but i have so much to learn yet. Mastering everything costs time and what little brain cells that i have left :)

Meantime, i like to just search for wildcards because FreeBSD is new to me and, coming from Windows, i have never heard of alot of tools, for example tmux, until i started using FreeBSD. Anyway, i used my quick and dirty regex and found an interesting program:

Code:
pkg search ^window.*\-

window-1.0_2.pkg so i installed it and fired it up. I found a way to help data and also learned how to change windows. I think that it is a neat little tool but a little research reveals that it used to be in the base system. Fascinating! I never heard of it or used it before. I like it somehow. I kept an offline package because it it piques my interest. I'm not sure why noone uses it these days but i like it.

Thanks for the tips about grep. Much appreciated! I hope that you have a nice day.
 

Attachments

  • window.jpg
    window.jpg
    20.7 KB · Views: 203
I have no experience with grep outside of the basics mentioned in the handbook. I will learn how to use grep and piping (which was mentioned to me by SDKchan some time ago).
All good.
One of the biggest things to remember about *nix systems is almost all tools are designed to do one thing, take stdin, transform it and push to stdout. That is where the pipe comes in (" | "). You wind up doing things like
"ls | grep | sed | awk | xargs" to rename/move files.

What that means is you don't have to remember "what the heck is the pkg search option to exclude a pattern" you instinctively know "pkg search name | grep -v ^name"

Of course things like systemd pervert/pollute this paradigm, but most shell things honor the stdin/stdout.
 
please note that i am a Windows user for 26 years. I have no experience with grep outside of the basics mentioned in the handbook.
That's why my answers are often more general. Not to just give a specific answer to a specific question, but to give general ideas, to be useful for others things, too.

Unix[like] shells bring a lot of little tools, you already can do a lot with, if you simply know them, know some of their options, and how to combine them.
It's really worth the time to just explore, what basic commands there are (e.g. basic unix commands (personally I like to add cut and paste to the file manipulation section of that list [there are more])

It makes no sense to read all manual pages at once - impossible, way too much information. It's a learning progress needs time and experience. But my recommendation is:
Scan - don't read it all, just overfly - that list (it was just a quick and dirty search; others may provide better lists, or you find one yourself) just to get an impression of what basic commands there are.
Everytime you stumble over a new command, always roughly scan its man page: read the description in the header, scroll quickly down, stop where you find something interesting, or if you're looking for something specific, but else just scroll completely once to get an impression about what options there are. And always take a closer peek at any man page's bottom: examples, files, and "see also" are very valuable. Especially the latter one can provide solutions if the command the man page you're looking at does not provide what you're looking for.

As mer also indicated between the lines:
It's more efficient to learn general ways you can use for most situations,
and look up a specific solution if the general ways are at their limits - if you need something more specific.
 
Alternatively, you could use grep -v ... or grep -Ev "unwanted1|unwanted2" to exclude some ports that contain unwanted strings.
Thank you very much. I've read the man page and this is a fantastic suggestion. Hopefully other newbies find this thread when searching for this subject matter. I will have to spend some time mastering the grep and piping methods of computing.

Maturin Your posts are always informative and i appreciate you taking time out of your day to help a newbie. I try to learn something new everyday on FreeBSD. I really love this system. I feel like Unix-like environment is true computing and the freedom of a bare-bones system is so refreshing. I am satisfied with this system but it will cost time to catch up to regular users/experts.

I know that i can browse ports but i usually only install pre-compiled packages from the repository. I have compiled a port to gain experience but i have other FreeBSD topics to focus on at this time. I want to install FreeBSD on my laptop soon, so i want to focus on some subjects that are important to me, such as pf rules and security. I also have yet to explore proxies and ssl interception (man-in-the-middle attacks to filter traffic). On Windows, i use Fiddler. Linux is Charles (commercial software). I have to figure out what i need to do on FreeBSD. Jails are also an important subject to me in this learning process.

Anyone notice how web-browsers are disappearing? data centralization tactics? we are really down to Firefox on FreeBSD? I'm struggling to find alternatives. I guess that we will end up using curl in the future.
 
Your posts are always informative and i appreciate you taking time out of your day to help a newbie. I try to learn something new everyday on FreeBSD. I really love this system. I feel like Unix-like environment is true computing and the freedom of a bare-bones system is so refreshing.
Thank you. That's what I'm trying to do: I cannot give the help the hackers, gurus, developers, and pros I see here a lot provide. But since I am a FreeBSD exclusive user (okay, not 100.0% exclusive. I play some old ancient 90s games on XP under VB) I want to share my good experiences I have with FreeBSD, and I try to convince newbies to give FreeBSD a shot. And maybe (of course with others [thanks to all for any adding, or correcting annotations at this point! 🙏]) to give some advice, how to get into this system as quickly and comfortable as possible (so maybe to relieve the gurus.) Which, if we both look back we had with our (and also including others again) first posts under FreeBSD or Linux from Windows, seemed to work. :cool:
But I will, 'cause I only can, give you general advices, only, 'cause since when I read your posts between the lines right, in some points you already overtook me 😁
You may a newbie to unix-world, but you're for sure no computers noob!
(high time to get you on the right horse 😁 [...Windows...😖])
Which brings me to
I am satisfied with this system but it will cost time to catch up to regular users/experts.
You don't have to catch up. This ain't a competition.
You cannot learn everything. To even get close takes (many) years.
But that's not the target. Using it is. That's what it's for.
Know what you want to do with the machine (which for many already is a hard task), knowing what can be done, pick from that what is of use or interest to you, and just do it. Learn how to accomplish certain tasks you pick is what the game is all about. (Okay, maybe if you want or need to earn money with it you may need to learn some things more.)
Anyway you will learn pretty much if you just use it, and be open to another not-Windows-world.
What you proved you are. 👍

I didn't told you the best part yet:
What you learn on BSDs/unix[like] is, as you also already figured out yourself, real computering. Only certain things change step by step by progress on computer science, by evolution, by sense, not because of a commercial big-tech company's marketing departement decided willfully to do so.
Many general core basics, as some mentioned in this thread, are over fifty years old. And stay. Because they are proven good, and by now no other way was found to do it better. New things are added, only, but not willfully replaced. Only things nobody really need and use anymore for quite a time are thrown overboard (and still there are ways to have or get them back anyway.) especially not unannounced, nor willfully to force to use the new ways, only.
So:
Learning is really worth the effort.
Gained knowledge is not endangered to be dropped into the garbage everytime a new version is released. Anything you learn in unix[like]-world is an useful investement.

Eventually one day you will realize:"Damned, I became pretty good" - when you already are long by than.

Short:
Becoming good ain't the target. This will happen automatically just by using, and loving it. What you already do.

I know that i can browse ports but i usually only install pre-compiled packages from the repository.
That's good. But in general what is in ports you get as packages, too. So what I ment was: Browse the ports tree for to see what's all available (it's a lot), for maybe something interests you.
Then install the according package.

we are really down to Firefox on FreeBSD? I'm struggling to find alternatives.
Search the forums! There already are some threads discussing that exact topic, suggesting several browsers. (you sometimes get quicker and better results using duckduckgo.com for search on FreeBSD forums, than using the forum's internal search.)

Besides several documentations besides The Handbook, like The Wiki, your local file:///usr/local/share/doc/, The Mailing Lists (pick and subscribe to some e.g. security to get informed in time about security issues, and how to solve them) and several personal blogs on FreeBSD, and other documentation,
The Man Pages, and this forums are a gold diamond mine, you just need to dig.
(since this is an open, public forum any one can read without being logged in, I also always try to give general answers anybody may have a use for, not the OP, only - so I may give information you already knew 🤓)

Enjoy! (your weekend, FreeBSD, your life with your wife, and your kids!)
 
Back
Top