View previous topic :: View next topic |
Author |
Message |
Boris27 Guru


Joined: 05 Nov 2003 Posts: 562 Location: Almelo, The Netherlands
|
Posted: Sat Feb 28, 2004 6:30 pm Post subject: |
|
|
steveb wrote: | this one starts manny bash prcesses and you can watch the cpu going crazy:
cheers
SteveB
btw: don't do it if you are not fast enought to do an killall bash! |
Might try it on my laptop and see how it suffers. |
|
Back to top |
|
 |
Andersson Guru


Joined: 12 Jul 2003 Posts: 525 Location: Göteborg, Sweden
|
Posted: Sat Feb 28, 2004 8:32 pm Post subject: Re: Your best bash tricks... |
|
|
allucid wrote: | I was wondering what everyone's favorite (and relatively unknown...) bash tricks were. |
I often forget how to do things, so I started writing down reminders for all sorts of things and kept them in a textfile. When it became too large to cat, I wrote this handy script, it works just like grep except that it prints the entire matching paragraph, not just a line.
edit: I found a more elegant solution than this script, see below.
Code: | #!/bin/bash
# Variables:
file_to_search=/home/user/reminders/reminders
ignore_case=1 # Non-zero value ignores case.
awk -v "RS=\n\n" -v "IGNORECASE=$ignore_case" '/'$1'/{print $0"\n"}' $file_to_search |
together with alias remind_me_about='/home/user/scripts/remind_me_about.sh' I have a quick command line reminder tool. I use it daily
The reminders file looks something like this, with the notes separated by an empty line.
Code: | Format a floppy (NOT mounted, and as root)
fdformat /dev/fd0
To start another x server:
startx -- :1
creating symlinks:
ln -s /path/to/dir /path/to/symlink
Create an iso image (the r is for rockridge, filenames other than 8+3):
mkisofs -r directory/ > image.iso
Burn a cd from an iso (speed will be set to 4 for cdrw):
cdrecord -v speed=8 dev=/dev/hdc image.iso |
edit:
I just learned that I don't need a script for this. A more elegant solution is putting a bash function in ~/.bashrc. Now every user can have their own settings defined in their bashrc (for example, root can have an additional file to search with root related reminders). And everything is there in bashrc with the other settings, there is no script to keep track of.
The function looks like this: remind_me_about(){ awk -v "RS=\n\n" -v "IGNORECASE=1" '/'$1'/{print $0"\n"}' /home/user/reminders.general /home/user/reminders.root; }
Last edited by Andersson on Wed Mar 03, 2004 11:59 pm; edited 1 time in total |
|
Back to top |
|
 |
slarti` Retired Dev


Joined: 20 Sep 2003 Posts: 376 Location: UK
|
Posted: Sat Feb 28, 2004 8:51 pm Post subject: |
|
|
Lost your editor?
cat >file
You can use it like a normal editor, ^C will exit, as you'd expect.
Totally pointless, I know.
Also, a bit mainstream, but backticks (`) are so bloody useful.. even though my knowledge of sed and awk is next to nothing, I can get a lot done with just grep, cat and echo and some other stuff with liberal use of backticks and also piping. _________________ Gentoo/AMD64, shell-tools, net-mail, vim, recruiters
IRC: slarti @ irc.freenode.net
Devspace |
|
Back to top |
|
 |
axxackall l33t


Joined: 06 Nov 2002 Posts: 651 Location: Toronto, Ontario, 3rd Rock From Sun
|
Posted: Sat Feb 28, 2004 8:54 pm Post subject: |
|
|
Andersson, you may want to consider fortune to host all your reminders (or cookies in term of forutne).
BTW, fortune is in portage.
YABTW, you may want to originate bash-related cookies as an ebuild and many of us would be happy to contribute to it. _________________ "Lisp is a programmable programming language." - John Foderaro, CACM, September 1991 |
|
Back to top |
|
 |
nevynxxx Veteran

Joined: 12 Nov 2003 Posts: 1123 Location: Manchester - UK
|
Posted: Sat Feb 28, 2004 9:53 pm Post subject: |
|
|
Code: |
for i in `cat <some file>`;do rm $i;done
|
is a nice one after
Code: |
ls /usr/local/portage/sys-kernel/love-sources >> <some file>
ls /usr/local/portage/sys-kernel/love-sources/files >> <some file>
|
and some editing ...not the best or cheekyest, but one I did today after i've been playing with looping bash scripts to write audio cd's _________________ My Public Key
Wanted: Instructor in the art of Bowyery |
|
Back to top |
|
 |
Andersson Guru


Joined: 12 Jul 2003 Posts: 525 Location: Göteborg, Sweden
|
Posted: Sun Feb 29, 2004 12:07 am Post subject: |
|
|
axxackall wrote: | Andersson, you may want to consider fortune to host all your reminders (or cookies in term of forutne).
BTW, fortune is in portage.
YABTW, you may want to originate bash-related cookies as an ebuild and many of us would be happy to contribute to it. |
Fortune? The thing that displays a funny quote when you log in? Do you mean like a "bash tip of the day", or are there other ways to use it? I've never used fortune so I'm not sure what you're thinking of... |
|
Back to top |
|
 |
axxackall l33t


Joined: 06 Nov 2002 Posts: 651 Location: Toronto, Ontario, 3rd Rock From Sun
|
Posted: Sun Feb 29, 2004 1:05 am Post subject: |
|
|
Andersson wrote: | Fortune? The thing that displays a funny quote when you log in? Do you mean like a "bash tip of the day", or are there other ways to use it? I've never used fortune so I'm not sure what you're thinking of... |
I found fortune (or fortune-like tips) usefull in several places:
- Midnight Commander displays its tips on the message line between pannels and the command prompt. Some of those tips were really usefuls.
- some programs (like GIMP) display their tips when you start the program. When you learn learn the program it's useful. Later you can disable it.
- I have fortune to display its quote when I login. That is mostly to enjoy some Tao wisdom. But you are right it can be used to remind bas tips too.
- I have some web-pages with fortune's quote-of-the day line on the buttom. It can be useful to display some technology specific tips when the page is oriented for that technology.
- Postgresql mail-lists attach postgres-releated tips to the buttom of every message. Never heard complains. Seems like people enjoy and learn it.
- When I learned Emacs I used fortune-like minor-mode to display major-mode specific bindings in the message line.
This list of examples shows that fortune is a tool. It can be used for funny quotes (as it's usually distributed), but also it can be used for something really practical and useful. _________________ "Lisp is a programmable programming language." - John Foderaro, CACM, September 1991 |
|
Back to top |
|
 |
Andersson Guru


Joined: 12 Jul 2003 Posts: 525 Location: Göteborg, Sweden
|
Posted: Mon Mar 01, 2004 9:09 pm Post subject: |
|
|
I've been trying fortune out. It's pretty neat. I think you're right in that if there's interest in threads about bash tips, then there's probably interest in a fortune file of bash tips as well. (This is not the only bash thread in the forums by the way.)
I don't feel like I have time to collect bash tips right now, but perhaps after my tests this semester are over, in two weeks. In case anyone else feels like creating a fortune file, the text file should have a % between the "cookies" and you create the .dat file with the command strfile filename filename.dat. I had to search for a while before I found that  |
|
Back to top |
|
 |
CheshireCat Guru


Joined: 25 Aug 2002 Posts: 572
|
Posted: Mon Mar 01, 2004 10:04 pm Post subject: |
|
|
sonic_ wrote: | Also, a bit mainstream, but backticks (`) are so bloody useful.. even though my knowledge of sed and awk is next to nothing, I can get a lot done with just grep, cat and echo and some other stuff with liberal use of backticks and also piping. |
Backticks are nice, but it's good to get into a habit of using the more nesting-friendly $() construct.
As for other tricks, aliases are always fun. Try adding this one to your .profile: Code: | alias h='history | grep' |
Now you can do things like this: Code: | chshrcat@chshrcat chshrcat $ h cvs
225 cvs diff -u . >../mmxblend2.patch
232 cvs diff -u . >../mmxblend2.patch
237 cvs diff -u . >../mmxblend2.patch
262 cvs diff -u >../adjust.patch
359 cvs diff -u >../adjust.patch
361 cvs diff -u >../adjust.patch
377 cvs diff -u >../adjust.patcscreen -ls
437 vi /usr/portage/distfiles/cvs-src/mythtv/libs/libmythtv/osdtypes.cpp
441 vi /usr/portage/distfiles/cvs-src/mythtv/libs/libmythtv/osdtypes.cpp
459 cvs diff -u >../mmxblend2.patch
504 h cvs |
and use !<number> to recall a command. For example, I'd use !225 to create a new diff vs CVS of the patch that I stupidly failed to realize wasn't right yet, yesterday  |
|
Back to top |
|
 |
charlieg Advocate


Joined: 30 Jul 2002 Posts: 2149 Location: Manchester UK
|
Posted: Mon Mar 01, 2004 10:08 pm Post subject: |
|
|
A really simple one of mine: Code: | charlie@mightymax charlietech $ grep lsd /etc/profile
alias lsd='echo $DIRSTACK'
charlie@mightymax charlietech $ lsd
~/darcs/com/charlietech
|
_________________ Want Free games?
Free Gamer - open source games list & commentary
Open source web-enabled rich UI platform: Vexi |
|
Back to top |
|
 |
Deebster Tux's lil' helper


Joined: 16 Nov 2003 Posts: 126 Location: Reading, England
|
Posted: Wed Mar 03, 2004 5:32 pm Post subject: Re: Udated my aliases, here they are: |
|
|
Kalin wrote: | [code]kalin@sata kalin $ cat /etc/profile.d/10alias
...
alias merge='ACCEPT_KEYWOEDS=~x86 emerge -p'
... |
Shouldn't that be ACCEPT_KEYWORDS? |
|
Back to top |
|
 |
simulacrum Tux's lil' helper

Joined: 30 Nov 2002 Posts: 128 Location: St Paul, MN
|
Posted: Wed Mar 03, 2004 6:44 pm Post subject: |
|
|
charlieg, does "pwd" not produce the same result? |
|
Back to top |
|
 |
meowsqueak Veteran


Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Wed Mar 03, 2004 7:35 pm Post subject: Re: Udated my aliases, here they are: |
|
|
Deebster wrote: | Kalin wrote: | [code]kalin@sata kalin $ cat /etc/profile.d/10alias
...
alias merge='ACCEPT_KEYWOEDS=~x86 emerge -p'
... |
Shouldn't that be ACCEPT_KEYWORDS? |
Of course, good job you pointed that out. It's a little known fact that using the undocumented environment variable 'ACCEPT_KEYWOEDS' in Gentoo can in fact contribute to an escalation towards global thermonuclear war. Please don't use it. God only knows what it would do in Debian... |
|
Back to top |
|
 |
prizna n00b


Joined: 06 Feb 2004 Posts: 19 Location: Iceland (.is)
|
|
Back to top |
|
 |
gurke Apprentice

Joined: 10 Jul 2003 Posts: 260
|
Posted: Wed Mar 03, 2004 9:40 pm Post subject: |
|
|
steveb wrote: | this one starts manny bash prcesses and you can watch the cpu going crazy:
cheers
SteveB
btw: don't do it if you are not fast enought to do an killall bash! |
just tried if i am fast enough. --- i was not.
seems that it didnt hurt my computer. evrythings working fine.
though i ll never do it again. |
|
Back to top |
|
 |
dinkumator n00b

Joined: 07 Nov 2003 Posts: 16 Location: tennessee, usa
|
Posted: Wed Mar 03, 2004 10:52 pm Post subject: |
|
|
i'm kinda surprised no one mentioned this:
loads .profile when su ing to another user |
|
Back to top |
|
 |
charlieg Advocate


Joined: 30 Jul 2002 Posts: 2149 Location: Manchester UK
|
Posted: Wed Mar 03, 2004 11:31 pm Post subject: |
|
|
simulacrum wrote: | charlieg, does "pwd" not produce the same result? | So it does!  _________________ Want Free games?
Free Gamer - open source games list & commentary
Open source web-enabled rich UI platform: Vexi |
|
Back to top |
|
 |
odegard Guru

Joined: 08 Mar 2003 Posts: 324 Location: Trondheim, NO
|
Posted: Wed Mar 03, 2004 11:35 pm Post subject: |
|
|
Some of my aliases
Code: |
alias r='history | grep'
alias l='ls -alh --color'
alias .='cd ..'
alias bt='/home/moi/download/torrents/BitTorrent-experimental-3.2.1b-2/btdownloadgui.py'
alias btmake='/home/moi/download/torrents/BitTorrent-experimental-3.2.1b-2/btmakemetafile.py'
|
using just 'l' for listing and '.' for going up a dir really speeds up navigation! |
|
Back to top |
|
 |
meowsqueak Veteran


Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Wed Mar 03, 2004 11:39 pm Post subject: |
|
|
dinkumator wrote: | i'm kinda surprised no one mentioned this:
loads .profile when su ing to another user |
That's not a bad idea to use '-' but aliasing it isn't always useful. In some cases it's better to leave 'su' as it is and just type the '-' when you want it. It depends how you tend to use su.
Here's another nice shortcut:
No need to know that users password and no need to 'su root' first  |
|
Back to top |
|
 |
carambola5 Apprentice


Joined: 10 Jul 2002 Posts: 214 Location: Madtown, WI
|
Posted: Wed Mar 03, 2004 11:57 pm Post subject: |
|
|
charlieg wrote: | A really simple one of mine: Code: | charlie@mightymax charlietech $ grep lsd /etc/profile
alias lsd='echo $DIRSTACK'
charlie@mightymax charlietech $ lsd
~/darcs/com/charlietech
|
|
I use the alias lsd differently:
Very useful for using ls with a wildcard. For example, try:
and
You get very different results, and I'm usually looking for the first one. _________________ Get Firefox!
Proper Web Development
I'm done at 999. |
|
Back to top |
|
 |
Trejkaz Guru


Joined: 14 Nov 2002 Posts: 479 Location: Sydney, Australia
|
Posted: Thu Mar 04, 2004 3:06 am Post subject: |
|
|
Not groundbreaking, but I get people going "wtf" frequently enough while watching me type that it's obvious they don't know about it.
emerge bash-completion
Your shell life just got 400% more convenient. |
|
Back to top |
|
 |
Andersson Guru


Joined: 12 Jul 2003 Posts: 525 Location: Göteborg, Sweden
|
Posted: Thu Mar 04, 2004 3:57 am Post subject: |
|
|
Trejkaz wrote: | Not groundbreaking, but I get people going "wtf" frequently enough while watching me type that it's obvious they don't know about it.
emerge bash-completion |
I didn't When people mentioned bash completion I always assumed they were talking of the normal path expansion and similar.
Anyway, on the bash completion web page there are several other really good bash tips. http://www.caliban.org/bash/index.shtml |
|
Back to top |
|
 |
Trejkaz Guru


Joined: 14 Nov 2002 Posts: 479 Location: Sydney, Australia
|
Posted: Thu Mar 04, 2004 4:01 am Post subject: |
|
|
I particularly like the way you can type "tar jxf <tab>" and it will only complete files ending in .tar.bz2. Also it seems that if the command is mplayer it will only complete files which are music or video.
And "dcop <tab>" completes all available DCOP targets... and this works all the way down to the names of the functions which can be called. Just brilliant.
Oh wow! Vi editing mode!
Quote: |
If you're a fan of vi as opposed to Emacs, you might prefer to operate bash in vi editing mode. Being a GNU program, bash uses Emacs bindings unless you specify otherwise.
Set the following in your /etc/inputrc or ~/.inputrc:
set editing-mode vi
set keymap vi
and this in your /etc/bashrc or ~/.bashrc:
set -o vi
|
|
|
Back to top |
|
 |
lightvhawk0 Guru


Joined: 07 Nov 2003 Posts: 388
|
Posted: Thu Mar 04, 2004 7:43 am Post subject: |
|
|
I "cat /dev/usbmouse | hexdump" and watch the data flow when I move the mouse _________________ If God has made us in his image, we have returned him the favor. - Voltaire |
|
Back to top |
|
 |
hardcore l33t


Joined: 01 Nov 2003 Posts: 626 Location: MSU, MI
|
Posted: Thu Mar 04, 2004 8:20 am Post subject: |
|
|
steveb wrote: | this one starts manny bash prcesses and you can watch the cpu going crazy:
cheers
SteveB
btw: don't do it if you are not fast enought to do an killall bash! |
HaHaHa you *forking* bastard That's a sure fire way to bring down any system quickly  |
|
Back to top |
|
 |
|