Useful custom commands for Slackware
Here are three commands I use which I find quite useful. They all deal with finding info on the Slackware packages currently installed on the computer and are a great addition to the other package commands in Slackware (such as installpkg, removepkg, upgradepkg, etc.). These are my own homegrown commands, not copied from anywhere, which I give freely to the public domain without restriction. They are script files which can be placed in /usr/local/bin and used like any other command.
Each has a short help message to help with usage, although I will provide a quick rundown on their usage. They require the utils 'less' (less pkg) and 'egrep' (grep pkg), which may or may not be installed by default. PATTERN MATCHING <- This section has been edited. -> All the scripts now emulate the wildcard pattern matching ( * and ? ) used for filename matches. These scripts do not use true globbing, as it is sometimes called, but merely substitutes the wildcards * and ? with a regular expression equivalent, which is only part of the picture (see 'man glob' for details for the rest of the story on wildcard pattern matching). This is sufficient for what is needed for these scripts. Using more complicated searching, such as with the square brackets ( [ ] ), curly braces ( { } ), and others used in globbing, will not work as expected as the rules are different than how they are applied in regular expressions (used by the 'egrep' command). I suppose I could do more substitution to make it closer to globbing, but I really don't see the need to do so at this time. NOTE: If your familiar with the extended regexp syntax, you could probably do more complicated searches with these scripts, if you remember to take into account the substition of * for .*, ? for .?, and . for \. ............ NOTE: Any changes or updates in code will be reflected here and explained in a following post below...........In other words, the code for these three scripts will always have the most recent changes in this post with an explanation in another post below. lspkg This command simply lists the packages currently installed on your machine. UPDATE: See post #53 below for more info. Code:
#!/bin/sh pkginfo This command lists the package's name, size of the package, the package description, and a list of the files installed by the package. UPDATE: See post #53 below for more info. Code:
#!/bin/sh whichpkg Ever wonder which package a file came from? That's the purpose of this command, to find the package a file comes from. UPDATE: See post #53 below for more info. Code:
#!/bin/sh I hope you find these as useful as I have. While you can get the same information using a graphical package manager, they are much quicker to use from the command line. Enjoy :) ---thegeekster |
You rock, sir.
I especially like lspkg. Nice and handy. Thank you very, very much. |
Thanx :)
But I did notice one little item in the code for whichpkg...............I forgot to add the -i switch in the grep command. It's this switch that makes the search case insensitive...............................LOL...which means I've been using it all this time as a case sensitive search...... :eek: I've already made the changes in the code above..............................but for those who may have copied it already, at the bottom of the code for 'whichpkg' change the two grep lines to read "grep -i ..." (simply insert -i after the word grep)........ |
*** lspkg UPDATE ***
NOTE: This update is superseded by the changes posted here..... :)
|
Thanks, been using these scripts since you first posted them. :)
|
I don't think I've ever posted one of my scripts before. I figure mine suck. As far as this, I've just been using this thing I wrote called 'sp' (Slack packages).
Code:
script=`basename $0` But how every Slack user doesn't come up with *something*, I dunno. It's too common an activity and pkgtool is just too slow. ;) Good stuff, thegeekster. Oh, and my less is 'export LESS="-eFMRXj12"' - using the default less the way I do might be kind of annoying. Oh, and alias cdp='cd /var/log/packages' is essential for manual inspection. Due to filenames, typing 'cd /v<tab>log/p<tab>' sucks. |
Hey, digiot, don't sell yourself short..................this is what open source is about, posting what you have for the benefit of others and if someone knows of a better or more efficient way of doing it, or spots a bug, then it gets fixed...........in other words, community involvement...............I'm sure mine can be improved upon, too.........
This is also why I post these scripts, making it useful for others and hoping others will come forward and help contribute their bit to the community.............and this allows users to have more choices, instead of limiting choices........... ;) I see your code is basically what I have, but all in one program, with one added ability..................I thought of making it all one script, but then I decided to follow the Unix programming philosophy of making a program do just one thing, and do it well.... :) I must say, I never thought of using the manifest file for searching if a file is part of the distribution as a whole, whether the pkg is installed or not...................gives me an idea of updating the 'whichpkg' script to first search locally for installed programs, and if not found, then search the manifest to see if it's even part of the Slackware distribution..................otherwise, it must be a third-party app and not officially part of Slackware.......... :) Also, you might be interested in knowing that you can 'cat' a zipped file (reading the file to the screen), whether compressed with gzip or bzip2, since they only compress a single file. The regular zip utility doesn't do this AFAIK, probably due to the fact it is not limited to compressing only a single file...................In other words, instead of unzipping the manifest file, just 'cat' the file in it's compressed form...............this way, you can save some disk space and still be able to read the file and pipe it through grep to filter the output The commands for these formats is zcat filename.gz for gzipped files and bzcat filename.bz2 for bzip2 files.......this will output the contents of the compressed file to the screen........so for your 'all' variable and '-a' switch you can do something like this: Code:
all=/home/j/var/MANIFEST.bz2 And anyone else.................feel free to step in and post someting you may have come up with..............if you know of a useful timesaver, then post it.... :) |
Quote:
/home/j/var/manifest lines 21792-21811/217164 8% instead of lines 1-22 (or whatever) in the status line which I figure might be useful for something. And with disk sizes these days I don't compress much. I second that, though - I look forward to more folks' posts. :) (OT - anyone else feel claustrophobic. ;) ) |
Quote:
Code:
all=/home/j/var/MANIFEST.bz2 And I'm not that familiar with the 'less' command, other than piping something to less.................so I learned something new and gives me something to play around with...... :) |
:o
Yeah. lesspipe.sh. I forgot that. :( Well, if you're not familiar with less, check out the man page - it's a great tool that can be a lot more effective than I think a lot of people realize. I obviously need to go read it again myself ;) (Still like 'em uncompressed, though.) |
*** chngcd ***
Here's a handy little script for changing CDs easily..................This is especially useful for you gamers whom oftentimes have to change a CD during gameplay........
To use, it's quite simple - open a console terminal and enter chngcd..........The CDROM tray will pop out automatically..........Then place a CD in the tray -OR- replace the current CD to continue -OR- remove the CD to quit, and then press Enter................You don't even have to close the CD tray, it will do it automaticallly................Simple and effective... ;) To make it easy to create the script, just copy-n-paste _all_ of the following code at once into a console terminal, and the script will be created automatically, not to mention being executable as well.......... :) If you prefer to do it the harder way, such as using a text editor, then copy-n-paste everything _except_ the first and last lines into the text editor...........Do not copy the lines containing __EOF__ NOTE: If you need to change the path to the CDROM mount point for any reason, after creating the script just open it up and change the CDROM variable to the desired path.......... Code:
cat << "__EOF__" > /usr/local/bin/chngcd && chmod 755 /usr/local/bin/chngcd |
Since a few bash scripters are gathered here, I'll ask here.
How can parse root=/dev/????? out of /proc/cmdline? |
Quote:
Code:
cat /proc/cmdline | grep 'root=' | cut -d' ' -f3 |
It has to be more explicit to handle any cmdline order.
I've been greping the small 't' and then '='. This works as long as there is no other small t, for instance in the kernel name. I thought sed might help but I don't know how to use it. using grep -d '=' also gets confused. can sed use a multi character delimiter like 'root=' ? |
Hmmm...........then see if this is what you want:
Quote:
|
All times are GMT -5. The time now is 02:55 AM. |