Re: Show us your /etc/profile
PS1='[\[`if test $? -eq 0; then echo "\e[1;32m"; else echo "\e[1;31m"; fi`\]$?\[\e[0m\]]-[\[\e[0;34m\]\h\[\e[0m\]]-[\[\e[0;34m\]\w\[\e[0m\]]\[\n\]\$ ' Where is that awesome post about the CRC24 to get a nice color for each hostname ? There: https://www.mail-archive.com/misc@openbsd.org/msg136871.html On Fri, Aug 28, 2015 at 11:54 AM, Patrick Dohmanwrote: > My back to SCO additions⦠> > > #-# > # Print the current directory, hostname & user# > #-# > > HOST=`hostname` > PS1='$(print -n "[${USER}@${HOST%%.*} ";[[ "$HOME" == "$PWD" ]] && print > -n "~" ||([[ "${PWD##*/}" == "" ]] && print -n "/" || print -n > "${PWD##*/}");print "]$")' > > #*** > HISTFILE=~/.ksh_history > export HISTFILE > HISTSIZE=500; export HISTSIZE > # > > > #-# > # a few Korn/Bash shell aliases # > #-# > > alias l="ls -la" > alias vi=âvim" > > Regards > Patrick > > > > On Aug 27, 2015, at 7:36 PM, T B wrote: > > > > Resurrecting this not-too-old thread. You might find this one useful if > > you run CARP firewalls which gives you a dynamic prompt telling you the > > master/backup/other status. > > > > function fwStatus { > >IFCONFIG=`ifconfig -a | grep carp:` > >NUMCARPS=`echo "$IFCONFIG" | wc -l` > >BACKUPCARPS=`echo "$IFCONFIG" | grep 'carp: BACKUP' | wc -l` > >MASTERCARPS=`echo "$IFCONFIG" | grep 'carp: MASTER' | wc -l` > > > >if [[ "$MASTERCARPS" == "$NUMCARPS" ]]; then > >printf master > >elif [[ "$BACKUPCARPS" == "$NUMCARPS" ]]; then > >printf backup > >else > >printf other > >fi > > } > > > > HOSTNAME=`hostname -s` > > PS1='${USER}@${HOSTNAME}:${PWD} ($(fwStatus)) $ ' > > > > > > On Wed, Aug 5, 2015 at 1:43 AM, Sean Kamath > > wrote: > > > >> On Aug 2, 2015, at 8:49 AM, li...@wrant.com wrote: > >> > never > thought of using a shell function in .profile till I read this thread. > >>> > >>> ... > >>> > >>> Functions has always been impressive once you move past the alias > >>> shortcomings (can't handle arguments etc), so also worth a read the > >>> "Functions" section. > >> > >> > >> Functions have been amazingly useful and impressive for a very long > time. > >> They are also not limited to ksh. In fact, my introduction to this very > >> useful aspect of shell programming was from Sun's rcS script, which has > >> this: > >> > >> # Simulates cat in sh so it doesn't need to be on the root filesystem. > >> # > >> shcat() { > >>while [ $# -ge 1 ]; do > >>while read i; do > >>echo "$i" > >>done < $1 > >>shift > >>done > >> } > >> > >> > >> There have been times when I've been on systems in single user mode > >> without filesystems, and knowing how to do some things we typically use > >> external programs for in the shell can be a lifesaver, like "echo *" as > a > >> poor man's "ls". > >> > >> If your directory isn't *that* large, 'for i in *; do echo $i; done | > wc > >> -l' works well. Well, for some definition of 'well'. > >> > >> My point is that shell functions allow you to do some fairly complex > >> stuff, and if you're careful, you can avoid execs. There are places the > >> shell forks, however. It can be a fun exercise to find them with > profiling > >> tools. :-) > >> > >> Sean > > -- () ascii ribbon campaign - against html e-mail /\
Re: Show us your /etc/profile
On Fri, Aug 28, 2015 at 11:01:45AM +0200, Martijn van Duren wrote: Here's some potential useful feature from my .profile. It might not be perfect, but at least it's better then some of the generators I've seen in production. # $RANDOM is not portable and in ksh it's limited to 32767. rand() { local number local rdevice for rdevice in /dev/{u,}random fail; do test -c $rdevice -a -r $rdevice break done test $rdevice = fail return 1 number=$(dd if=$rdevice bs=4 count=1 2/dev/null | hexdump -e '/4 %u\n') if [ -z $1 ]; then echo $number else echo $(($number % $(($1 + 1 fi } One can use 'openssl rand' here for results of the same quality in less lines. -- Matthieu Herrb [demime 1.01d removed an attachment of type application/pgp-signature]
Re: Show us your /etc/profile
On Sat, Aug 29, 2015 at 12:26:37PM +0200, Matthieu Herrb wrote: | On Fri, Aug 28, 2015 at 11:01:45AM +0200, Martijn van Duren wrote: | Here's some potential useful feature from my .profile. It might not be | perfect, but at least it's better then some of the generators I've seen in | production. | | # $RANDOM is not portable and in ksh it's limited to 32767. | rand() { | local number | local rdevice | | for rdevice in /dev/{u,}random fail; do | test -c $rdevice -a -r $rdevice break | done | test $rdevice = fail return 1 | | number=$(dd if=$rdevice bs=4 count=1 2/dev/null | hexdump -e '/4 %u\n') | if [ -z $1 ]; then | echo $number | else | echo $(($number % $(($1 + 1 | fi | } | | One can use 'openssl rand' here for results of the same quality in | less lines. For better quality (no modulo bias) random values, pkg_add ranval. Uses OpenBSD's arc4random family of functions. Because of this, it doesn't open devices (easy to build into a static binary and use in chroots). Cheers, Paul 'WEiRD' de Weerd -- [++-]+++.+++[---].+++[+ +++-].++[-]+.--.[-] http://www.weirdnet.nl/
Re: Show us your /etc/profile
Here's some potential useful feature from my .profile. It might not be perfect, but at least it's better then some of the generators I've seen in production. # $RANDOM is not portable and in ksh it's limited to 32767. rand() { local number local rdevice for rdevice in /dev/{u,}random fail; do test -c $rdevice -a -r $rdevice break done test $rdevice = fail return 1 number=$(dd if=$rdevice bs=4 count=1 2/dev/null | hexdump -e '/4 %u\n') if [ -z $1 ]; then echo $number else echo $(($number % $(($1 + 1 fi } # http://xkcd.com/936/ generatepw_file() { local file=${1:-/usr/share/dict/words} local lineno=`wc -l $file` || return 1 local i=0 local passphrase local random if [ $lineno -lt 75000 ]; then echo Not enough words in $file 2 return 1 fi while [ $i -lt 4 ]; do random=$(rand $lineno) || return 1 passphrase=${passphrase}$(sed -n $random p $file) i=$((i+1)); done echo $passphrase } generatepw_random() { local characters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^*()-_=+[]{}:,./?\|' local charactercount=$(echo -n $characters | wc -c) local password='' # Password should be somewhere between 10 and 20 characters local passwordlength=$((`rand 10` + 10)) local i=0 local random while [ $i -lt $passwordlength ]; do random=$(rand ${charactercount}) || return 1 password=${password}$(echo $characters | sed -n s/^.\{${random}\}\(.\).*/\1/p) i=$((i+1)) done echo $password } generatepw() { if [ `rand 1` = 1 ]; then generatepw_file || generatepw_random || return 1 else generatepw_random || return 1 fi } On 08/28/15 02:36, T B wrote: Resurrecting this not-too-old thread. You might find this one useful if you run CARP firewalls which gives you a dynamic prompt telling you the master/backup/other status. function fwStatus { IFCONFIG=`ifconfig -a | grep carp:` NUMCARPS=`echo $IFCONFIG | wc -l` BACKUPCARPS=`echo $IFCONFIG | grep 'carp: BACKUP' | wc -l` MASTERCARPS=`echo $IFCONFIG | grep 'carp: MASTER' | wc -l` if [[ $MASTERCARPS == $NUMCARPS ]]; then printf master elif [[ $BACKUPCARPS == $NUMCARPS ]]; then printf backup else printf other fi } HOSTNAME=`hostname -s` PS1='${USER}@${HOSTNAME}:${PWD} ($(fwStatus)) $ '
Re: Show us your /etc/profile
On Fri, Aug 28, 2015 at 1:20 AM, Alexander Hall alexan...@beard.se wrote: I'm pretty sure this messes up $? at the prompt. Try: false echo $? You could circumvent this by saving $? at the beginning of the function and returning it at the end. Happy to report that this is not the case. That would be pretty annoying, though.
Re: Show us your /etc/profile
My back to SCO additions… #-# # Print the current directory, hostname user# #-# HOST=`hostname` PS1='$(print -n [${USER}@${HOST%%.*} ;[[ $HOME == $PWD ]] print -n ~ ||([[ ${PWD##*/} == ]] print -n / || print -n ${PWD##*/});print ]$)' #*** HISTFILE=~/.ksh_history export HISTFILE HISTSIZE=500; export HISTSIZE # #-# # a few Korn/Bash shell aliases # #-# alias l=ls -la alias vi=“vim Regards Patrick On Aug 27, 2015, at 7:36 PM, T B phreakoci...@gmail.com wrote: Resurrecting this not-too-old thread. You might find this one useful if you run CARP firewalls which gives you a dynamic prompt telling you the master/backup/other status. function fwStatus { IFCONFIG=`ifconfig -a | grep carp:` NUMCARPS=`echo $IFCONFIG | wc -l` BACKUPCARPS=`echo $IFCONFIG | grep 'carp: BACKUP' | wc -l` MASTERCARPS=`echo $IFCONFIG | grep 'carp: MASTER' | wc -l` if [[ $MASTERCARPS == $NUMCARPS ]]; then printf master elif [[ $BACKUPCARPS == $NUMCARPS ]]; then printf backup else printf other fi } HOSTNAME=`hostname -s` PS1='${USER}@${HOSTNAME}:${PWD} ($(fwStatus)) $ ' On Wed, Aug 5, 2015 at 1:43 AM, Sean Kamath kam...@moltingpenguin.com wrote: On Aug 2, 2015, at 8:49 AM, li...@wrant.com wrote: never thought of using a shell function in .profile till I read this thread. ... Functions has always been impressive once you move past the alias shortcomings (can't handle arguments etc), so also worth a read the Functions section. Functions have been amazingly useful and impressive for a very long time. They are also not limited to ksh. In fact, my introduction to this very useful aspect of shell programming was from Sun's rcS script, which has this: # Simulates cat in sh so it doesn't need to be on the root filesystem. # shcat() { while [ $# -ge 1 ]; do while read i; do echo $i done $1 shift done } There have been times when I've been on systems in single user mode without filesystems, and knowing how to do some things we typically use external programs for in the shell can be a lifesaver, like echo * as a poor man's ls. If your directory isn't *that* large, 'for i in *; do echo $i; done | wc -l' works well. Well, for some definition of 'well'. My point is that shell functions allow you to do some fairly complex stuff, and if you're careful, you can avoid execs. There are places the shell forks, however. It can be a fun exercise to find them with profiling tools. :-) Sean
Re: Show us your /etc/profile
Alexander Hall alexan...@beard.se writes: [...] I'm pretty sure this messes up $? at the prompt. Try: false echo $? You could circumvent this by saving $? at the beginning of the function and returning it at the end. Here's an excerpt of my .kshrc. The '$' is printed in red if the last command failed, $? is preserved in case I want to know the exact value. --- _nc=$(tput sgr0) _red=$(tput setaf 1) --- _ps1_err () { local _rc=$? [ $_rc -ne 0 ] printf %s $_red return $_rc } PS1='\h \w\[$(_ps1_err)\]\$\[$_nc\] ' --- -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Re: Show us your /etc/profile
On August 28, 2015 2:36:38 AM GMT+02:00, T B phreakoci...@gmail.com wrote: Resurrecting this not-too-old thread. You might find this one useful if you run CARP firewalls which gives you a dynamic prompt telling you the master/backup/other status. function fwStatus { IFCONFIG=`ifconfig -a | grep carp:` NUMCARPS=`echo $IFCONFIG | wc -l` BACKUPCARPS=`echo $IFCONFIG | grep 'carp: BACKUP' | wc -l` MASTERCARPS=`echo $IFCONFIG | grep 'carp: MASTER' | wc -l` if [[ $MASTERCARPS == $NUMCARPS ]]; then printf master elif [[ $BACKUPCARPS == $NUMCARPS ]]; then printf backup else printf other fi } I'm pretty sure this messes up $? at the prompt. Try: false echo $? You could circumvent this by saving $? at the beginning of the function and returning it at the end. /Alexander HOSTNAME=`hostname -s` PS1='${USER}@${HOSTNAME}:${PWD} ($(fwStatus)) $ ' On Wed, Aug 5, 2015 at 1:43 AM, Sean Kamath kam...@moltingpenguin.com wrote: On Aug 2, 2015, at 8:49 AM, li...@wrant.com wrote: never thought of using a shell function in .profile till I read this thread. ... Functions has always been impressive once you move past the alias shortcomings (can't handle arguments etc), so also worth a read the Functions section. Functions have been amazingly useful and impressive for a very long time. They are also not limited to ksh. In fact, my introduction to this very useful aspect of shell programming was from Sun's rcS script, which has this: # Simulates cat in sh so it doesn't need to be on the root filesystem. # shcat() { while [ $# -ge 1 ]; do while read i; do echo $i done $1 shift done } There have been times when I've been on systems in single user mode without filesystems, and knowing how to do some things we typically use external programs for in the shell can be a lifesaver, like echo * as a poor man's ls. If your directory isn't *that* large, 'for i in *; do echo $i; done | wc -l' works well. Well, for some definition of 'well'. My point is that shell functions allow you to do some fairly complex stuff, and if you're careful, you can avoid execs. There are places the shell forks, however. It can be a fun exercise to find them with profiling tools. :-) Sean
Re: Show us your /etc/profile
Resurrecting this not-too-old thread. You might find this one useful if you run CARP firewalls which gives you a dynamic prompt telling you the master/backup/other status. function fwStatus { IFCONFIG=`ifconfig -a | grep carp:` NUMCARPS=`echo $IFCONFIG | wc -l` BACKUPCARPS=`echo $IFCONFIG | grep 'carp: BACKUP' | wc -l` MASTERCARPS=`echo $IFCONFIG | grep 'carp: MASTER' | wc -l` if [[ $MASTERCARPS == $NUMCARPS ]]; then printf master elif [[ $BACKUPCARPS == $NUMCARPS ]]; then printf backup else printf other fi } HOSTNAME=`hostname -s` PS1='${USER}@${HOSTNAME}:${PWD} ($(fwStatus)) $ ' On Wed, Aug 5, 2015 at 1:43 AM, Sean Kamath kam...@moltingpenguin.com wrote: On Aug 2, 2015, at 8:49 AM, li...@wrant.com wrote: never thought of using a shell function in .profile till I read this thread. ... Functions has always been impressive once you move past the alias shortcomings (can't handle arguments etc), so also worth a read the Functions section. Functions have been amazingly useful and impressive for a very long time. They are also not limited to ksh. In fact, my introduction to this very useful aspect of shell programming was from Sun's rcS script, which has this: # Simulates cat in sh so it doesn't need to be on the root filesystem. # shcat() { while [ $# -ge 1 ]; do while read i; do echo $i done $1 shift done } There have been times when I've been on systems in single user mode without filesystems, and knowing how to do some things we typically use external programs for in the shell can be a lifesaver, like echo * as a poor man's ls. If your directory isn't *that* large, 'for i in *; do echo $i; done | wc -l' works well. Well, for some definition of 'well'. My point is that shell functions allow you to do some fairly complex stuff, and if you're careful, you can avoid execs. There are places the shell forks, however. It can be a fun exercise to find them with profiling tools. :-) Sean
Re: Show us your /etc/profile
On Aug 2, 2015, at 8:49 AM, li...@wrant.com wrote: never thought of using a shell function in .profile till I read this thread. ... Functions has always been impressive once you move past the alias shortcomings (can't handle arguments etc), so also worth a read the Functions section. Functions have been amazingly useful and impressive for a very long time. They are also not limited to ksh. In fact, my introduction to this very useful aspect of shell programming was from Sun's rcS script, which has this: # Simulates cat in sh so it doesn't need to be on the root filesystem. # shcat() { while [ $# -ge 1 ]; do while read i; do echo $i done $1 shift done } There have been times when I've been on systems in single user mode without filesystems, and knowing how to do some things we typically use external programs for in the shell can be a lifesaver, like echo * as a poor man's ls. If your directory isn't *that* large, 'for i in *; do echo $i; done | wc -l' works well. Well, for some definition of 'well'. My point is that shell functions allow you to do some fairly complex stuff, and if you're careful, you can avoid execs. There are places the shell forks, however. It can be a fun exercise to find them with profiling tools. :-) Sean
Re: Show us your /etc/profile
Hello Vijay, On Sat 01/08/2015 14:09, Vijay Sankar wrote: [...] To quickly see how many files I have in a directory, I use alias nof='ls -l . | egrep -c '^-'' I have always wondered if there is a better way of doing this. In general, I would avoid using a pipe when a native command exists (and particularly in this case, where grep string comparison is a slow operation); this could probably be more appropriate: alias nof='find ./ -type f -maxdepth 1 | wc -l' See the difference in runtime in case of a huge file listing (not so uncommon...): just22@poseidon:[tmp] time find ./ -type f -maxdepth 1 | wc -l 113069 real0m1.732s user0m0.100s sys 0m1.560s just22@poseidon:[tmp] time ls -l ./ | egrep -c ^- 113069 real0m2.238s user0m0.630s sys 0m1.550s All the best -- Alessandro DE LAURENZIS [mailto:just22@gmail.com] LinkedIn: http://it.linkedin.com/in/delaurenzis
Re: Show us your /etc/profile
On Sun, Aug 2, 2015 at 6:35 AM, Alessandro DE LAURENZIS just22@gmail.com wrote: On Sun 02/08/2015 08:23, Alessandro DE LAURENZIS wrote: operation); this could probably be more appropriate: alias nof='find ./ -type f -maxdepth 1 | wc -l' Ok, that's clearly inefficient because the search is performed in all subtrees, instead of cwd only; maybe this: find . ! -name . -prune -type f -print | wc -l This approach also counts hidden files while the original did not include those in the count. That said, to avoid the inefficiency of searching the subtrees, all you had to do was reverse -type and -maxdepth: find . -maxdepth 1 -type f | wc -l And this should be more efficient than descending into each subtree and then pruning it as your first action. Thanks, -- Raul
Re: Show us your /etc/profile
On Sun 02/08/2015 08:23, Alessandro DE LAURENZIS wrote: [...] operation); this could probably be more appropriate: alias nof='find ./ -type f -maxdepth 1 | wc -l' Ok, that's clearly inefficient because the search is performed in all subtrees, instead of cwd only; maybe this: find . ! -name . -prune -type f -print | wc -l - Alessandro DE LAURENZIS [mailto:just22@gmail.com] LinkedIn: http://it.linkedin.com/in/delaurenzis
Re: Show us your /etc/profile
On 2015-08-02 08:23, Alessandro DE LAURENZIS wrote: On Sat 01/08/2015 14:09, Vijay Sankar wrote: alias nof='ls -l . | egrep -c '^-'' I have always wondered if there is a better way of doing this. In general, I would avoid using a pipe when a native command exists (and particularly in this case, where grep string comparison is a slow operation); this could probably be more appropriate: There IS no native command doing what Vijay wants... you introduced a pipe in your own example, too. Don't be afraid of pipes! There isn't necessarily a disadvantage in splitting jobs through a pipe. For example, it enables the system to better utilize multiple processors/cores, which may or may not make a difference. In this case, your example is undoubtedly faster. *But*, what you did was to speed optimize a process, involving a human operator, to work half a second faster in a rather constructed scenario with over a hundred thousand files in one directory. In practice, the difference is completely imperceptible for the operator: 88888 (cut) bl@paddan:~$ cd /usr/share/man/man3 # [1] bl@paddan:/usr/share/man/man3$ time ls -l . | egrep -c '^-' 4045 0m0.05s real 0m0.02s user 0m0.03s system bl@paddan:/usr/share/man/man3$ time find . -maxdepth 1 -type f | wc -l 4045 0m0.04s real 0m0.01s user 0m0.02s system bl@paddan:/usr/share/man/man3$ _ 88888 (cut) This kind of optimization is really not that productive. There is for sure a good lesson in showing how to do things in different ways, to broaden ones horizon when it comes to thinking outside the box (or pipe). But, starting to talk about shaving fractions of a second off of an interactive command in an edge case is just a red herring in my opinion. It teaches the wrong message. A much better optimization for this question, in my mind, is this: Don't use an alias at all! Instead use a shell function, like this: 88888 (cut) nof() { ls -l $1 | egrep -c '^-' } 88888 (cut) (In this case, substituting find is *not* immediately applicable.) The advantage of this approach is that in the regular case nof works just like in Vijay's original alias, but this has the added functionality of being able to nof any directory with a command line argument, like this: 88888 (cut) bl@paddan:/usr/share/man/man3$ nof 4045 bl@paddan:/usr/share/man/man3$ nof /bin 42 -- (Who knew Douglas Adams was an OpenBSD contributor!) bl@paddan:/usr/share/man/man3$ 88888 (cut) You can't do the above (as easily) with the find approach, since it doesn't work without a directory argument. (Yes, of course we can add code to fix that, but that's not the point here.) This isn't a SPEED optimization, it is a FUNCTIONALITY optimization. It is a better way to do the same thing, just what Vijay asked for. :-) Moral of my story: KISS. Keep It Simple, Stupid. Put your efforts in the right place. Regards, /Benny [1] I first did this to quickly find out which directory in my machine was the biggest, to have somewhere to play: bl@paddan:~$ sudo find / -type d -ls | cut -c48- | grep -v ^ The cut and grep business sorts out all smaller directories with three or four digit sizes, giving me a quick overview over the biggest directories. This whole operation took me less than a minute, including a couple of trial-and-error runs to find out the best position for the cut. I am sure there are much better and more accurate ways of doing this, still with simple shell commands and pipe chaining, but this is what I thought of off the top of my head, and it did this one-shot job much more quickly than if I had sat down to come up with a more accurate or general solution. Optimizing your *work* doesn't have to include measuring cpu cycles! alias nof='find ./ -type f -maxdepth 1 | wc -l' See the difference in runtime in case of a huge file listing (not so uncommon...): just22@poseidon:[tmp] time find ./ -type f -maxdepth 1 | wc -l 113069 real0m1.732s user0m0.100s sys 0m1.560s just22@poseidon:[tmp] time ls -l ./ | egrep -c ^- 113069 real0m2.238s user0m0.630s sys 0m1.550s All the best
Re: Show us your /etc/profile
Quoting Benny Lofgren bl-li...@lofgren.biz: On 2015-08-02 08:23, Alessandro DE LAURENZIS wrote: On Sat 01/08/2015 14:09, Vijay Sankar wrote: alias nof='ls -l . | egrep -c '^-'' I have always wondered if there is a better way of doing this. In general, I would avoid using a pipe when a native command exists (and particularly in this case, where grep string comparison is a slow operation); this could probably be more appropriate: There IS no native command doing what Vijay wants... you introduced a pipe in your own example, too. Don't be afraid of pipes! There isn't necessarily a disadvantage in splitting jobs through a pipe. For example, it enables the system to better utilize multiple processors/cores, which may or may not make a difference. In this case, your example is undoubtedly faster. *But*, what you did was to speed optimize a process, involving a human operator, to work half a second faster in a rather constructed scenario with over a hundred thousand files in one directory. In practice, the difference is completely imperceptible for the operator: 88888 (cut) bl@paddan:~$ cd /usr/share/man/man3 # [1] bl@paddan:/usr/share/man/man3$ time ls -l . | egrep -c '^-' 4045 0m0.05s real 0m0.02s user 0m0.03s system bl@paddan:/usr/share/man/man3$ time find . -maxdepth 1 -type f | wc -l 4045 0m0.04s real 0m0.01s user 0m0.02s system bl@paddan:/usr/share/man/man3$ _ 88888 (cut) This kind of optimization is really not that productive. There is for sure a good lesson in showing how to do things in different ways, to broaden ones horizon when it comes to thinking outside the box (or pipe). But, starting to talk about shaving fractions of a second off of an interactive command in an edge case is just a red herring in my opinion. It teaches the wrong message. A much better optimization for this question, in my mind, is this: Don't use an alias at all! Instead use a shell function, like this: 88888 (cut) nof() { ls -l $1 | egrep -c '^-' } 88888 (cut) (In this case, substituting find is *not* immediately applicable.) The advantage of this approach is that in the regular case nof works just like in Vijay's original alias, but this has the added functionality of being able to nof any directory with a command line argument, like this: 88888 (cut) bl@paddan:/usr/share/man/man3$ nof 4045 bl@paddan:/usr/share/man/man3$ nof /bin 42 -- (Who knew Douglas Adams was an OpenBSD contributor!) bl@paddan:/usr/share/man/man3$ 88888 (cut) You can't do the above (as easily) with the find approach, since it doesn't work without a directory argument. (Yes, of course we can add code to fix that, but that's not the point here.) This isn't a SPEED optimization, it is a FUNCTIONALITY optimization. It is a better way to do the same thing, just what Vijay asked for. :-) Moral of my story: KISS. Keep It Simple, Stupid. Put your efforts in the right place. Regards, /Benny [1] I first did this to quickly find out which directory in my machine was the biggest, to have somewhere to play: bl@paddan:~$ sudo find / -type d -ls | cut -c48- | grep -v ^ The cut and grep business sorts out all smaller directories with three or four digit sizes, giving me a quick overview over the biggest directories. This whole operation took me less than a minute, including a couple of trial-and-error runs to find out the best position for the cut. I am sure there are much better and more accurate ways of doing this, still with simple shell commands and pipe chaining, but this is what I thought of off the top of my head, and it did this one-shot job much more quickly than if I had sat down to come up with a more accurate or general solution. Optimizing your *work* doesn't have to include measuring cpu cycles! alias nof='find ./ -type f -maxdepth 1 | wc -l' See the difference in runtime in case of a huge file listing (not so uncommon...): just22@poseidon:[tmp] time find ./ -type f -maxdepth 1 | wc -l 113069 real0m1.732s user0m0.100s sys 0m1.560s just22@poseidon:[tmp] time ls -l ./ | egrep -c ^- 113069 real0m2.238s user0m0.630s sys 0m1.550s All the best Thanks very much Alessandro, Raul, and Benny. Really appreciate all your thoughtful comments. They were very educational for me. Benny's shell function is more appropriate for what I am doing with nof. I am very embarrassed to admit this but unfortunately I never thought of using a shell function in .profile till I read this thread. Thanks again Benny Lofgren. Just in case it is of any relevance this is what I use nof for. I have a few ports building systems running and they run different versions of OpenBSD. As a result they
Re: Show us your /etc/profile
never thought of using a shell function in .profile till I read this thread. Maybe redundant but worth checking ksh(1), and search for kshrc, right after the description and arguments. The section (ENV parameter) describes strategy to keep your .profile cleaner for login shells and interactive shells related setup in .kshrc. So, you may want to put majority of your aliases and functions etc in $HOME/.kshrc and this in $HOME/.profile export ENV=$HOME/.kshrc It is again repetitive of previous posts but there is no need to pollute /etc/profile, rather recommended to put these in $HOME dot files for various reasons, the principle of least applied change at the lowest possible level. Functions has always been impressive once you move past the alias shortcomings (can't handle arguments etc), so also worth a read the Functions section. Check also the FILES section for places you can put appropriate respective customisation. I've found this man page ksh(1) more helpful than books on shells programming. This applies to many other man pages in OpenBSD, which is not only impressive, but really helpful and saves time.
Re: Show us your /etc/profile
On 2015-07-31, listas...@dna.uba.ar listas...@dna.uba.ar wrote: What aliases or custom functions do you use? Nothing exciting. Here's a useful one not everybody might know about: alias doas='doas ' Also, just for kicks I keep these around, although they aren't terribly useful in a windowing environment where you can just resize your xterm: alias c132='printf \033[?3h; stty columns 132; kill -WINCH $$' # set DECCOLM alias c80='printf \033[?3l; stty columns 80; kill -WINCH $$' # reset DECCOLM -- Christian naddy Weisgerber na...@mips.inka.de
Re: Show us your /etc/profile
On 31/07/15 21:25, listas...@dna.uba.ar wrote: How do you customize your environment? What aliases or custom functions do you use? Here's my /etc/profile I think you can find one or two interesting things in it. Ouch - this hits a nerve. @work, we have a Unix environment where the powers that be have put every little customization into /etc/profile, parsing huge scripts to setup everything in their gusto. It takes ages to parse, just for me to 'unalias' and 'unset' every little crap they put into and setup a sane prompt. Remember, users cannot easily avoid having /etc/profile parsed during login. Thus they cannot avoid getting all the variables and aliases that you are putting into it. Please do not recommend putting too much stuff into /etc/profile, the content of that file should be limited to bare minimum that should be enforced onto users. Everything else should go into $HOME/.profile (or /etc/skel/.profile). Bernd
Re: Show us your /etc/profile
Quoting listas...@dna.uba.ar: Hello everybody How do you customize your environment? What aliases or custom functions do you use? Here's my /etc/profile I think you can find one or two interesting things in it. Show us yours! (in case wordwrapping breaks long lines: http://pastie.org/10322761) # hname=`hostname` hname=${hname%%.*} # You are here test ! -f ~/.hushlogin test -t 0 banner $hname # complete path PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/u/system/bin: export PATH # system defaults PAGER=less export PAGER EDITOR=vi test -x /usr/local/bin/vim EDITOR=vim export EDITOR # confort alias more=less alias ls='ls -Fca' alias l='ls -l' alias wget='wget -c' alias _tf='tail -20 -f ' alias tf='_tf /var/log/messages' alias tfm='_tf /var/log/maillog' alias tfd='_tf /var/log/daemon' alias ducks='du -cks * |sort -rn |head -11' alias pid='ps awx | grep -v grep | egrep -- ' test -x `which pgrep 2 /dev/null` alias pid='pgrep -lf ' pidof() { pgrep $1 } pkey() { cat ~/.ssh/id_dsa.pub | \ ssh $1 (mkdir ~/.ssh /dev/null 21; cat - ~/.ssh/authorized_keys) } # windozise #alias rm='rm -i' #alias mv='mv -i' #alias cp='cp -i' # www alias gohtdocs='cd /var/www/htdocs' alias gosite='cd /var/www/htdocs/site/' alias httpd_restart='/etc/rc.d/httpd restart' # OpenBSD CVS CVSROOT=anon...@anoncvs.openbsd.org:/cvs export CVSROOT CVS_RSH=/usr/bin/ssh export CVS_RSH # OpenBSD packages export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/ export PKG_PATH # ui if [ ${SHELL} = /bin/ksh ] then PS1=$hname':$PWD{!}' if [ $USER == root ] then export PS1=$PS1# alias p='export PS1=# ' else export PS1=$PS1 alias p='export PS1=$ ' fi set -o emacs# heh set -o vi-tabcomplete # bashishhh bind ^B=backward-word bind ^N=forward-word fi unset hname # ui if [ -t 0 ] then stty erase ^? stty status ^T # for dd(1) fi # alias fw_log='tcpdump -ttt -nle -i pflog0' alias openports='fstat | grep internet| grep -v 127.0.0 | sort -u | awk { print \$9 } | sort -u' xtitle() { printf \\033]0;$1\\007 } alias unspam='sa-learn --ham --dbpath /var/amavisd/.spamassassin -u _vscan' alias idspam='sudo -u _vscan /bin/sh -l' function spamtrap { test -z $1 echo 'usage: spamtrap regex to block' return 1 spamdb | grep $1 | cut -d\| -f 2 | while read x ; do spamdb -t -a $x; done } export http_proxy=http://157.92.192.253:8080/; export https_proxy=$http_proxy export ftp_proxy=$http_proxy test -f /etc/profile.local . /etc/profile.local Thanks very much, very interesting. My .profile is a very small subset of yours except for the following. To quickly see how many files I have in a directory, I use alias nof='ls -l . | egrep -c '^-'' I have always wondered if there is a better way of doing this. -- Vijay Sankar, M.Eng., P.Eng. ForeTell Technologies Limited vsan...@foretell.ca
Re: Show us your /etc/profile
On Fri, Jul 31, 2015 at 05:25:49PM -0300, listas...@dna.uba.ar wrote: [...] How do you customize your environment? [...] Colorful prompt with power line glyphs and SCM branch and routing table id display [0]. What aliases or custom functions do you use? [...] My favorites are alias cp='rsync -Phr' alias ..='cd ..' [0]: http://unobtanium.de/static/rice.png [1]: https://github.com/farhaven/dotfiles/blob/master/kshrc -- Gregor Best -- Horse sense is the thing a horse has which keeps it from betting on people. -- W. C. Fields
Re: Show us your /etc/profile
On Fri, Jul 31, 2015 at 4:25 PM, listas...@dna.uba.ar wrote: How do you customize your environment? What aliases or custom functions do you use? Here's what I use: PATH=$HOME/bin:$PATH EDITOR=vi export EDITOR Pretty exciting, no? Customizations go in $HOME/bin ... and looking at the sort of stuff I have there, I doubt anyone should ever want to use any of it. Most of what I have there has host names in it, and for an example of something which does not: $ cat ~/bin/quotecsvn #!/bin/sh #0 :0 exec /Users/rauldmiller/bin/jconsole $0 $@ ) require'csv' data=: readcsv ;{:ARGV mask=: *./(*./@e.'-0123456789') data data=: mask x:@.@]^:[.1 data data writecsv;{:ARGV exit 0 Anyways, it's mostly just junk... -- Raul
Re: Show us your /etc/profile
Nice! I am stealing idea! Thanks! Will share what i will be able to. On Fri, 31 Jul 2015 23:27 listas...@dna.uba.ar wrote: Hello everybody How do you customize your environment? What aliases or custom functions do you use? Here's my /etc/profile I think you can find one or two interesting things in it. Show us yours! (in case wordwrapping breaks long lines: http://pastie.org/10322761) # hname=`hostname` hname=${hname%%.*} # You are here test ! -f ~/.hushlogin test -t 0 banner $hname # complete path PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/u/system/bin: export PATH # system defaults PAGER=less export PAGER EDITOR=vi test -x /usr/local/bin/vim EDITOR=vim export EDITOR # confort alias more=less alias ls='ls -Fca' alias l='ls -l' alias wget='wget -c' alias _tf='tail -20 -f ' alias tf='_tf /var/log/messages' alias tfm='_tf /var/log/maillog' alias tfd='_tf /var/log/daemon' alias ducks='du -cks * |sort -rn |head -11' alias pid='ps awx | grep -v grep | egrep -- ' test -x `which pgrep 2 /dev/null` alias pid='pgrep -lf ' pidof() { pgrep $1 } pkey() { cat ~/.ssh/id_dsa.pub | \ ssh $1 (mkdir ~/.ssh /dev/null 21; cat - ~/.ssh/authorized_keys) } # windozise #alias rm='rm -i' #alias mv='mv -i' #alias cp='cp -i' # www alias gohtdocs='cd /var/www/htdocs' alias gosite='cd /var/www/htdocs/site/' alias httpd_restart='/etc/rc.d/httpd restart' # OpenBSD CVS CVSROOT=anon...@anoncvs.openbsd.org:/cvs export CVSROOT CVS_RSH=/usr/bin/ssh export CVS_RSH # OpenBSD packages export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/`uname http://ftp.openbsd.org/pub/OpenBSD/uname -r`/packages/`uname -m`/ export PKG_PATH # ui if [ ${SHELL} = /bin/ksh ] then PS1=$hname':$PWD{!}' if [ $USER == root ] then export PS1=$PS1# alias p='export PS1=# ' else export PS1=$PS1 alias p='export PS1=$ ' fi set -o emacs# heh set -o vi-tabcomplete # bashishhh bind ^B=backward-word bind ^N=forward-word fi unset hname # ui if [ -t 0 ] then stty erase ^? stty status ^T # for dd(1) fi # alias fw_log='tcpdump -ttt -nle -i pflog0' alias openports='fstat | grep internet| grep -v 127.0.0 | sort -u | awk { print \$9 } | sort -u' xtitle() { printf \\033]0;$1\\007 } alias unspam='sa-learn --ham --dbpath /var/amavisd/.spamassassin -u _vscan' alias idspam='sudo -u _vscan /bin/sh -l' function spamtrap { test -z $1 echo 'usage: spamtrap regex to block' return 1 spamdb | grep $1 | cut -d\| -f 2 | while read x ; do spamdb -t -a $x; done } export http_proxy=http://157.92.192.253:8080/; export https_proxy=$http_proxy export ftp_proxy=$http_proxy test -f /etc/profile.local . /etc/profile.local
Re: Show us your /etc/profile
On Fri, Jul 31, 2015 at 05:25:49PM -0300, listas...@dna.uba.ar wrote: Hello everybody Hello, alias ducks='du -cks * |sort -rn |head -11' I'm stealing this one ;-) -- Gilles Chehade https://www.poolp.org @poolpOrg
Show us your /etc/profile
Hello everybody How do you customize your environment? What aliases or custom functions do you use? Here's my /etc/profile I think you can find one or two interesting things in it. Show us yours! (in case wordwrapping breaks long lines: http://pastie.org/10322761) # hname=`hostname` hname=${hname%%.*} # You are here test ! -f ~/.hushlogin test -t 0 banner $hname # complete path PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/u/system/bin: export PATH # system defaults PAGER=less export PAGER EDITOR=vi test -x /usr/local/bin/vim EDITOR=vim export EDITOR # confort alias more=less alias ls='ls -Fca' alias l='ls -l' alias wget='wget -c' alias _tf='tail -20 -f ' alias tf='_tf /var/log/messages' alias tfm='_tf /var/log/maillog' alias tfd='_tf /var/log/daemon' alias ducks='du -cks * |sort -rn |head -11' alias pid='ps awx | grep -v grep | egrep -- ' test -x `which pgrep 2 /dev/null` alias pid='pgrep -lf ' pidof() { pgrep $1 } pkey() { cat ~/.ssh/id_dsa.pub | \ ssh $1 (mkdir ~/.ssh /dev/null 21; cat - ~/.ssh/authorized_keys) } # windozise #alias rm='rm -i' #alias mv='mv -i' #alias cp='cp -i' # www alias gohtdocs='cd /var/www/htdocs' alias gosite='cd /var/www/htdocs/site/' alias httpd_restart='/etc/rc.d/httpd restart' # OpenBSD CVS CVSROOT=anon...@anoncvs.openbsd.org:/cvs export CVSROOT CVS_RSH=/usr/bin/ssh export CVS_RSH # OpenBSD packages export PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/`uname -r`/packages/`uname -m`/ export PKG_PATH # ui if [ ${SHELL} = /bin/ksh ] then PS1=$hname':$PWD{!}' if [ $USER == root ] then export PS1=$PS1# alias p='export PS1=# ' else export PS1=$PS1 alias p='export PS1=$ ' fi set -o emacs# heh set -o vi-tabcomplete # bashishhh bind ^B=backward-word bind ^N=forward-word fi unset hname # ui if [ -t 0 ] then stty erase ^? stty status ^T # for dd(1) fi # alias fw_log='tcpdump -ttt -nle -i pflog0' alias openports='fstat | grep internet| grep -v 127.0.0 | sort -u | awk { print \$9 } | sort -u' xtitle() { printf \\033]0;$1\\007 } alias unspam='sa-learn --ham --dbpath /var/amavisd/.spamassassin -u _vscan' alias idspam='sudo -u _vscan /bin/sh -l' function spamtrap { test -z $1 echo 'usage: spamtrap regex to block' return 1 spamdb | grep $1 | cut -d\| -f 2 | while read x ; do spamdb -t -a $x; done } export http_proxy=http://157.92.192.253:8080/; export https_proxy=$http_proxy export ftp_proxy=$http_proxy test -f /etc/profile.local . /etc/profile.local
Re: Show us your /etc/profile
Hello everybody Hello, anonymous. How do you customize your environment? Reading man pages mostly, and teraforming using (brain) farts. What aliases or custom functions do you use? On the blog over 15 pages across several years, just kidding. Here's my /etc/profile I think you can find one or two interesting things in it. Yours? really. Amazing. Thank you. Minus the red linuxisms. You think! Show us yours! I am showing it to you at the moment, you no see? I'll flash you again. (in case wordwrapping breaks long lines Wrap using \ in the file in the first place instead of advertising a link rot. Learn mg. What's in the .local file? Have you heard the mercury chloride story lately? Stomach pain relief instantly. On the go. go. go. Actually this is a good idea, showing configuration files and customisation bringing comfort to novices, but you have to be a teacher to do it properly, and I doubt that's your motive. Thanks anyway, and looking forward to credibility, comments, ideas, and not mindless copying common in cargo cult programmer environments.