View previous topic :: View next topic |
Author |
Message |
meowsqueak Veteran


Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Sun Oct 12, 2003 7:16 am Post subject: |
|
|
My avatar doesn't depict our nearby flaming ball of fusing hydrogen for nothing  |
|
Back to top |
|
 |
haceye Apprentice


Joined: 22 May 2003 Posts: 187 Location: Stuttgart, Germany
|
Posted: Mon Oct 13, 2003 12:41 pm Post subject: |
|
|
Hi,
I hate typing /etc/init.d/... over and over, so I added this to my /root/.bashrc:
Code: | for service in `cd /etc/init.d/; ls`
do
alias "rc${service}"="/etc/init.d/${service}"
done
|
David _________________ faster 'emerge -s'? emerge esearch |
|
Back to top |
|
 |
fimblo Guru

Joined: 19 Feb 2003 Posts: 306 Location: European Union, Stockholm
|
Posted: Wed Oct 15, 2003 8:32 pm Post subject: |
|
|
man this thread has covered alot... but one thing I love is bash, and the fact that its actually a complete programming language (turing complete). I've never really bothered to learn it completely, but using loops from the bash prompt is useful if you want to move MANY files, so many, in fact, that the wildcard doesnt work.
Code: | mkdir manyfilesdir ; cd manyfilesdir
perl -e 'while ($n++ < 30000) { `touch $n`; }' # makes damn many files
for file in `find .` ; do test -f $file && rm $file && echo $file; done |
er, just a warning- this is an example, I dont know how many inodes you have left on your system... and I dont know what would happen if they run out... I tested it anyway making 100000 and it worked fine.
The point was anyway that you can automate things a bit more... I use this alot when I want to make thumbnails of many jpg files, or doing latex and dvips on many tex files
Code: |
for x in *.jpg; do convert -geometry 400x400+0+0 $x ${x/img/small_img}; done
for x in *tex; do latex $n && dvips -o ${x/.tex/.ps} $x ; done
|
/fimblo _________________ http://blahonga.yanson.org - little geekblog
http://blahona.yanson.org/howtos/livecd - yet another livecd howto |
|
Back to top |
|
 |
gwydion Apprentice


Joined: 26 Nov 2002 Posts: 151 Location: Michigan, USA
|
Posted: Tue Oct 21, 2003 1:43 am Post subject: |
|
|
haceye wrote: | Hi,
I hate typing /etc/init.d/... over and over, so I added this to my /root/.bashrc:
Code: | for service in `cd /etc/init.d/; ls`
do
alias "rc${service}"="/etc/init.d/${service}"
done
|
David |
A few months ago I noticed a friend starting a service on his mandrake box with the 'service' command, and I thought it was pretty nifty... better than '/etc/init.d/blah' ...
so I wrote this script, and stuck it in /usr/sbin Code: | #!/bin/bash
service=$1 ; shift
/etc/init.d/$service "$@" |
Slightly different approach, but 'service blah start|stop|restart|zap' strikes me as ... logical. _________________ Linux User #223670 |
|
Back to top |
|
 |
neenee Veteran


Joined: 20 Jul 2003 Posts: 1786
|
Posted: Tue Oct 21, 2003 7:54 am Post subject: |
|
|
thanks. i love this one. it saves me quite a bit of time
when i disable/enable wshaper. |
|
Back to top |
|
 |
dub.wav Tux's lil' helper

Joined: 09 Apr 2003 Posts: 149 Location: Norway
|
Posted: Tue Oct 21, 2003 5:51 pm Post subject: |
|
|
Here's a script to get stuff from cvs.
Code: |
#!/bin/bash
sites="SourceForge Gnome Xiph"
function read_project() {
echo -n "Project: "
read p
}
function read_module() {
echo -n "Module: "
read m
}
function read_revision() {
echo -n "Revision (if any): "
read r
}
function ext() {
CVSROOT="$site" $*
}
function cvsget() {
ext cvs login || exit
read_module
read_revision
if [ -z "$r" ];then
ext cvs -z3 checkout $m
else
ext cvs -z3 checkout -r $r $m
fi
}
function sf() {
read_project
local site=":pserver:anonymous@cvs.sourceforge.net:/cvsroot/$p"
cvsget
}
function gnome() {
local site=":pserver:anonymous@anoncvs.gnome.org:/cvs/gnome"
cvsget
}
function xiph() {
local site=":pserver:anoncvs@xiph.org:/usr/local/cvsroot"
cvsget
}
function menu() {
n=1
while [ "$site" != "4" ]
do
echo "Choose site, or press 4 to exit."
for i in $sites
do
echo "$n) $i"
(( n++ ))
done
echo -n "> "
read site
case "$site" in
"1" ) sf;;
"2" ) gnome;;
"3" ) xiph;;
"4" ) ;;
* ) echo "Wrong arg";;
esac
n=1
done
}
menu
|
Adding more cvs sites is pretty straightforward:
- Add the name of the cvs site to $sites
- Add a function
- Add it to case
- Increase the "exit" number:
Code: |
while [ "$site" != "4" ]
..
"4" ) ;;
|
Saves me some time anyway  |
|
Back to top |
|
 |
Hydralisk Tux's lil' helper

Joined: 19 Mar 2003 Posts: 83
|
Posted: Wed Oct 22, 2003 7:46 pm Post subject: |
|
|
(If you liked bash, wait till you try zsh. ) |
|
Back to top |
|
 |
meowsqueak Veteran


Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Wed Oct 22, 2003 7:59 pm Post subject: |
|
|
I always felt like bash + bash-completion script was superior to zsh - just my opinion. Can you tell us what makes zsh better than bash for you? |
|
Back to top |
|
 |
arkane l33t


Joined: 30 Apr 2002 Posts: 918 Location: Phoenix, AZ
|
Posted: Thu Oct 23, 2003 10:06 pm Post subject: |
|
|
softchill wrote: | I've seen lots of nice tips and I got a few for you.
Special character and string interpreted by the terminal
Someone made an alias to clean the screen when you logout... I got better:
then add what ever else you want getty to show before the login prompt.
|
If you use Bash, you can edit your .bash_logout and put "clear" in there... and anything else you want to show after the screen clear. |
|
Back to top |
|
 |
jesterspet Apprentice


Joined: 05 Feb 2003 Posts: 215 Location: Atlanta
|
Posted: Fri Oct 24, 2003 2:37 am Post subject: |
|
|
The best tip I recieved after migrating over to a *nix based work enviroment, was:
Dude, have you checked out this mailing list
As far as handy tweaks go, since I am a Vim fan, I took a tip from the aforementioned mailing list and made an enviroment enhancement for my self, by adding the following to my ~/.bashrc:
Code: | export MANPAGER='col -b | view -c 'set ft=man nomod nolist' -"
|
It gives you colored syntax highlighting & if you know a bit about vim, you can customize the color scheme to your personal tastes.
That tip is right up there with:
Have you tried Gentoo _________________ (X) Yes! I am a brain damaged lemur on crack, and would like to buy your software package for $499.95 |
|
Back to top |
|
 |
pr0phet n00b

Joined: 18 Oct 2003 Posts: 8 Location: U.S., SE Charlotte
|
Posted: Fri Oct 24, 2003 6:21 am Post subject: bash logout stuff |
|
|
Seen some posts where peeps used some aliases for clearing the screen on logout. How about this...
Code: | touch ~/.bash_logout
echo 'clear' > ~/.bash_logout
echo 'find ~/ -name "core" -exec rm -f {} \;' >> ~/.bash_logout
|
gnome 2.4 has a nasty habit of placing core files in your home directory, using the find command in .bash_logout to search and destroy is a good way to cleanup your home directory. You can do all kinds of stuff with ~/.bash_logout  _________________ "..this world is not your home, so don't make yourselves cozy in it. Don't indulge your ego at the expense of your soul." -1 Peter 2:11
"All that is not eternal is eternaly useless." -C.S. Lewis
V.Parsons aka pr0phet
Last edited by pr0phet on Fri Oct 31, 2003 1:24 am; edited 1 time in total |
|
Back to top |
|
 |
fimblo Guru

Joined: 19 Feb 2003 Posts: 306 Location: European Union, Stockholm
|
Posted: Fri Oct 24, 2003 6:22 am Post subject: |
|
|
Quote: | The best tip I recieved after migrating over to a *nix based work enviroment, was:
:idea Dude, have you checked out this mailing list |
your link doesnt work
EDIT: now it seems to work
/fimblo _________________ http://blahonga.yanson.org - little geekblog
http://blahona.yanson.org/howtos/livecd - yet another livecd howto |
|
Back to top |
|
 |
iplayfast l33t


Joined: 08 Jul 2002 Posts: 642 Location: Cambridge On,CA
|
Posted: Sat Oct 25, 2003 5:46 am Post subject: My tips |
|
|
when in konqueror use man:topic to find something Code: | for example:
man:ls
|
You can use your mouse for cross referencing.
And ever wonder how far through an emerge you are?
well most packages are either c or cpp files. So Code: |
you must be root to do this
find /var/tmp/portage/PackageName/ -iname "*.c*" | wc -l
|
This will tell you how many c/c++ files there are.
Code: |
find /var/tmp/portage/PackageName/ -iname "*.o*" | wc -l
|
This will tell you how many files have been built.
Subtract the two and you know approximatly how far you have to go. |
|
Back to top |
|
 |
pr0phet n00b

Joined: 18 Oct 2003 Posts: 8 Location: U.S., SE Charlotte
|
Posted: Sat Oct 25, 2003 8:56 am Post subject: nifty service script |
|
|
* UPDATE *
go here https://forums.gentoo.org/viewtopic.php?t=101984 and check and update for this. I started a new thread specifically for this.
I saw a couple posts concerning the nifty service function RedHat provides as opposed to having to type out /etc/init.d/foo {start|stop|status}
I happen to be running a rh server and tried the service script on my gentoo box. And it worked without any modifications. That's not to say it doesn't need any modification, but it works nonetheless.
For those interrested, here is the script...
Code: | #!/bin/sh
# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH
VERSION="`basename $0` ver. 0.91"
USAGE="Usage: `basename $0` < option > | --status-all | \
[ service_name [ command | --full-restart ] ]"
SERVICE=
SERVICEDIR="/etc/init.d"
OPTIONS=
if [ $# -eq 0 ]; then
echo $"${USAGE}" >&2
exit 1
fi
cd /
while [ $# -gt 0 ]; do
case "${1}" in
--help | -h | --h* )
echo $"${USAGE}" >&2
exit 0
;;
--version | -V )
echo $"${VERSION}" >&2
exit 0
;;
*)
if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ];
then
cd ${SERVICEDIR}
for SERVICE in * ; do
case "${SERVICE}" in
functions | halt | killall | single| linuxconf| kudzu | \
*rpmorig | *rpmnew | *rpmsave | *~ | *.orig)
;;
*)
if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
env -i LANG=$LANG PATH=$PATH TERM=$TERM
"${SERVICEDIR}/${SERVICE}" status
fi
;;
esac
done
exit 0
elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
SERVICE="${1}"
if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
env -i LANG=$LANG PATH=$PATH TERM=$TERM
"${SERVICEDIR}/${SERVICE}" stop
env -i LANG=$LANG PATH=$PATH TERM=$TERM
"${SERVICEDIR}/${SERVICE}" start
exit $?
fi
elif [ -z "${SERVICE}" ]; then
SERVICE="${1}"
else
OPTIONS="${OPTIONS} ${1}"
fi
shift
;;
esac
done
if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}"
${OPTIONS}
else
echo $"${SERVICE}: unrecognized service" >&2
exit 1
fi |
I'll play around with this script to make it more suited to Gentoo, if anyone is interrested, i'll repost the modified script.
enjoy [/url] _________________ "..this world is not your home, so don't make yourselves cozy in it. Don't indulge your ego at the expense of your soul." -1 Peter 2:11
"All that is not eternal is eternaly useless." -C.S. Lewis
V.Parsons aka pr0phet
Last edited by pr0phet on Sun Nov 02, 2003 4:06 am; edited 1 time in total |
|
Back to top |
|
 |
pr0phet n00b

Joined: 18 Oct 2003 Posts: 8 Location: U.S., SE Charlotte
|
Posted: Sat Oct 25, 2003 9:04 am Post subject: nifty service script |
|
|
Just as a warning.
Don't issue "service --status-all" especially if you've ssh'd into your box from a remote location.
When it reaches halt.sh it brings down the house! So be aware of this. _________________ "..this world is not your home, so don't make yourselves cozy in it. Don't indulge your ego at the expense of your soul." -1 Peter 2:11
"All that is not eternal is eternaly useless." -C.S. Lewis
V.Parsons aka pr0phet |
|
Back to top |
|
 |
VisualPhoenix Tux's lil' helper

Joined: 26 Sep 2002 Posts: 135 Location: (CT v NJ)
|
Posted: Sat Oct 25, 2003 7:22 pm Post subject: |
|
|
I have a couple machines that I like to ssh over vnc with so I wrote the following script to make my connection to them easier:
sshvnc
Code: |
#!/bin/sh
screen ssh -C -X -L 5901:localhost:5901 ${1}
vncviewer -depth 16 -compresslevel 8 -quality 0 -encodings Tight ${2}
screen -r
screen -wipe
|
sshvnc my.server.com localhost:1
i'm sure it can be improved - but i find it quite handy.
also - if you want to bypass the entire screen process (if using tightvnc) try:
sshtvnc
Code: |
vncviewer -depth 16 -compresslevel 8 -quality 0 -encodings Tight -via ${1} ${2}
|
|
|
Back to top |
|
 |
sman n00b

Joined: 21 Aug 2003 Posts: 23
|
Posted: Sun Oct 26, 2003 12:34 pm Post subject: Make your startup MUCH faster... |
|
|
changing RC_PARALLEL_STARTUP="no" to "yes" in
/etc/conf.d/rc
took ~20 seconds off my boot time |
|
Back to top |
|
 |
Vhata n00b

Joined: 17 Oct 2002 Posts: 4 Location: Rhodes University, South Africa
|
Posted: Mon Oct 27, 2003 7:52 pm Post subject: |
|
|
This is a script I wrote to do the equivalent of 'emerge -s' (or 'emerge search'). I find the time emerge takes to search through the portage tree rather irritating, so I used bash to shortcut it. It's not perfect (the 'latest version available' thing doesn't always work, for example, but that is the fault of 'gnuls -v', not mine , but I find it very useful.
I've put it in /usr/local/bin/describe:
#!/bin/bash
search=$1
. /etc/make.conf
(for z in /usr/portage/*/*$search*/*.ebuild ${PORTDIR_OVERLAY}/*/*$search*/*.ebuild
do
if [ -e $z ]
then
categpkg=`echo $z | cut -d'e' -f2- | cut -d'/' -f2,3`
descr=`cat $z | egrep '^\s*DESCRIPTION\s*=' | cut -d'=' -f2-`
homepage=`cat $z | egrep '^\s*HOMEPAGE\s*=' | cut -d'=' -f2- | cut -d'"' -f2`
ver=`ls -d /var/db/pkg/$categpkg* 2> /dev/null || echo none`
ver=`echo $ver | rev | cut -d'/' -f1,2 | rev`
ver=${ver/$categpkg-/}
latest=`echo $z | rev | cut -d'/' -f2- | rev`
latest=`ls -rv $latest/*.ebuild | head -1 | rev | cut -d'/' -f1,2 | cut -d. -f2- | rev`
pname=`echo $latest | cut -d'/' -f1`
latest=`echo $latest | cut -d'/' -f2`
latest=${latest/$pname-/}
printf "\033[01;31m$categpkg\033[00m: "
printf "\033[32m$descr\033[00m "
printf "( \033[01;34m$homepage\033[00m ) "
printf "[ installed: \033[01;32m$ver\033[00m; "
printf "latest: \033[01;32m$latest\033[00m ]\n"
fi
done) | sort | uniq
And, as an example:
$ describe editor
app-editors/hteditor: "HT Editor - editor for executable files" ( http://hte.sf.net/ ) [ installed: none; latest: 0.7.3 ]
app-editors/kxmleditor: "KDE XML Editor" ( http://kxmleditor.sourceforge.net ) [ installed: 0.8.1; latest: 0.8 ]
dev-util/gst-editor: "GStreamer graphical pipeline editor" ( ) [ installed: none; latest: 0.5.0 ]
gnome-extra/gconf-editor: "An editor to the GNOME 2 config system" ( http://www.gnome.org/ ) [ installed: 2.4.0; latest: 2.4.0 ]
gnome-extra/gconf-editor: "an editor to the GConf2 system" ( http://www.gnome.org/ ) [ installed: 2.4.0; latest: 2.4.0 ]
media-gfx/kimagemapeditor: "An imagemap editor for KDE" ( http://kimagemapeditor.sourceforge.net/ ) [ installed: none; latest: 0.9.5.1 ]
net-zope/externaleditor: "Allows you to use your favorite editor(s) from ZMI." ( http://www.zope.org/Members/Caseman/${MY_PN}/ ) [ installed: none; latest: 0.7 ]
net-zope/externaleditor: "Allows you to use your favorite editor(s) from ZMI." ( http://www.zope.org/Members/Caseman/ExternalEditor/ ) [ installed: none; latest: 0.7 ] _________________ No trumpets, no drums.
Jonathan Hitchcock |
|
Back to top |
|
 |
tactless l33t


Joined: 14 Jul 2002 Posts: 642 Location: Mitzpe Adi, Israel
|
Posted: Mon Oct 27, 2003 8:32 pm Post subject: |
|
|
This one was in the GWN, but is worth mentioning:
Ever forgot to turn on your ADSL/Cable modem when turning your machine on, thus having a lot of services not start up? Ever needed to bring a service down, but then needed to bring all of its dependencies back up with it? I used to do this:
Code: | for i in `find /etc/runlevels/default`; $i start; done |
But this is shorter:
Yep. Works. _________________ Tactless
"If it wasn't for fog, the world would run at a really crappy framerate."
Jabber: tactless@amessage.info |
|
Back to top |
|
 |
meowsqueak Veteran


Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Mon Oct 27, 2003 8:34 pm Post subject: |
|
|
Vhata wrote: | I find the time emerge takes to search through the portage tree rather irritating |
Check out 'esearch' - you'll probably have to unmask it. It generates a static index (eupdatedb) which takes around 20 minutes the first time on my Athlon TBird 1.2GHz but the search speed is incredible. Try it and see
Although it helps to update it every time the portage tree changes, subsequent eupdatedb invocations seem much faster. A cronjob would work well here. |
|
Back to top |
|
 |
reeder n00b


Joined: 02 Apr 2003 Posts: 45 Location: Plano, TX
|
Posted: Mon Oct 27, 2003 8:43 pm Post subject: |
|
|
A few years ago I would have recommended hanging onto your keypunch machine because every now and then the only input device working is the card reader. :-)
Now one of my favorite tips is to learn ed(1). Sometimes your fool screen editors just won't work, but ed(1) will! It's bailed me out more than once.
-- William |
|
Back to top |
|
 |
tomk Bodhisattva


Joined: 23 Sep 2003 Posts: 7221 Location: Sat in front of my computer
|
Posted: Tue Oct 28, 2003 12:46 am Post subject: |
|
|
OK, I think bashis great so I'll give you my favourite bash tips (sorry if you know them already)
Say I want to edit two files (File1.java and File2.java) in the same directory use the curly braces to say you some typing:
Code: | joe /foo/bar/File{1,2}.java |
Just make sure you get the order right, especially when using it with mv.
Ctrl-R will let you search your bash history to find that really long command you used a while ago, just type the first few letters after hitting Ctrl-R and the whole commmand will be ready for you just to press enter.
Ctrl-T will swap the last two characters around, handy for when you tpye lkie thsi.
One more which I only found out about a few days ago is that you can move the cursor to begining and end of words holding down Ctrl and pressing the left and right cursor keys.
Tom |
|
Back to top |
|
 |
redog n00b

Joined: 06 Nov 2002 Posts: 35
|
Posted: Tue Oct 28, 2003 3:02 pm Post subject: |
|
|
amne wrote: | things that may be useful for you:
hint #1:
having a backup is always a good idea (ok, i have already had 3 ibm drives that died )
|
TrueDat!!!
amne wrote: |
hint #2:
don't delete something to restore it from your backup if you didn't back it up.
|
I would hope that this is common sence
amne wrote: |
hint #3:
most services (sshd, squid) can be configured to listen only at your lan device, which makes it unnecessary to set up iptables to block the open port at your world device (i did that in my early linux times). |
Unnecessary mabe but I still suggest doing so. With iptables you dont have to imply each and every port you want blocked, a catchall rule is a must IMO. Why give a malicious daemon any chance, or ports to which it might bind. It could easly act like squid or apache or any other gnu service , close those ports man...You oughta checkout firehol damn nice iptables tool. |
|
Back to top |
|
 |
jesterspet Apprentice


Joined: 05 Feb 2003 Posts: 215 Location: Atlanta
|
Posted: Tue Oct 28, 2003 4:08 pm Post subject: |
|
|
When I first saw this thread, It was for favorite tips. To me that means the ofter overlooked & simple ways of improving your computing experience.
Following that line of thought, here is another good tip:
One way to speed up the interaction time of a shell (that does not hash its commands) that you may overlook is to modify your path. The order of the directories in your path should rely on the number of commands you use most. So /usr/bin or /bin would probably be first. Very large directories that are mounted over the network should be later in the list. If there are some directories in your path you only use for one or two commands consider making an alias or shell script (if your shell doesn't support aliases) which calls the program with its full path name.
shamlessly stolen from the UGU tips list _________________ (X) Yes! I am a brain damaged lemur on crack, and would like to buy your software package for $499.95 |
|
Back to top |
|
 |
redog n00b

Joined: 06 Nov 2002 Posts: 35
|
Posted: Tue Oct 28, 2003 4:38 pm Post subject: Some tips I didnt see |
|
|
I like both bash and vi. so I enable vi mode in bash with
So, to access bash history I can use "k" and "j" insted of the arrows(which are sooo far away )
go to the end of a line and begin typeing with "A"
get into insert mode with the regular vi commands "i" "a" "A"
and out with <esc>
you get undo, "u" I haven't figured out redo since ^r is bashes history search.
We can get to the begining of the line with 0 aka:zero
As well as alot of other useful vi commands. dG, d$ , d^ , b , e .....
And the look of concern on your co-workers face as to why they cannot type in your term (when its in command mode) is the best!
Also a neet command I havent seen mentioned is fc.
fc "Fix Command" is a builtin bash command for editing or recalling the history
I alias it to this so that all I need to type is r v and the last command I issued starting with the letter v is re-executed. -Thanks Sam!
fc -l is just like history | tail -17
And I helped a guy once who wanted this behavior, I forget why , but mabe someonelse will find it useful...
For an aditional script to run when you logout of bash you can set this trap in ~/.profile Code: | trap '[[ -r $HOME/.bash_logout ]] && . $HOME/.someother_logout' 0 1 3 15 |
|
|
Back to top |
|
 |
|