Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Console / shell tips & tricks

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
376 posts
  • Page 6 of 16
    • Jump to page:
  • Previous
  • 1
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • …
  • 16
  • Next
Author
Message
Boris27
Guru
Guru
User avatar
Posts: 562
Joined: Wed Nov 05, 2003 10:14 pm
Location: Almelo, The Netherlands
Contact:
Contact Boris27
Website

  • Quote

Post by Boris27 » Sat Feb 28, 2004 6:30 pm

steveb wrote:this one starts manny bash prcesses and you can watch the cpu going crazy:

Code: Select all

:(){ :|:&};:
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.
Top
Andersson
Guru
Guru
User avatar
Posts: 525
Joined: Sat Jul 12, 2003 10:00 pm
Location: Göteborg, Sweden

Re: Your best bash tricks...

  • Quote

Post by Andersson » Sat Feb 28, 2004 8:32 pm

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: Select all

#!/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: Select all

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.
Top
slarti`
Retired Dev
Retired Dev
User avatar
Posts: 376
Joined: Sat Sep 20, 2003 3:04 pm
Location: UK
Contact:
Contact slarti`
Website

  • Quote

Post by slarti` » Sat Feb 28, 2004 8:51 pm

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
Top
axxackall
l33t
l33t
User avatar
Posts: 651
Joined: Wed Nov 06, 2002 4:04 pm
Location: Toronto, Ontario, 3rd Rock From Sun

  • Quote

Post by axxackall » Sat Feb 28, 2004 8:54 pm

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
Top
nevynxxx
Veteran
Veteran
Posts: 1123
Joined: Wed Nov 12, 2003 1:34 pm
Location: Manchester - UK

  • Quote

Post by nevynxxx » Sat Feb 28, 2004 9:53 pm

Code: Select all

for i in `cat <some file>`;do rm $i;done
is a nice one after

Code: Select all

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
Top
Andersson
Guru
Guru
User avatar
Posts: 525
Joined: Sat Jul 12, 2003 10:00 pm
Location: Göteborg, Sweden

  • Quote

Post by Andersson » Sun Feb 29, 2004 12:07 am

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...
Top
axxackall
l33t
l33t
User avatar
Posts: 651
Joined: Wed Nov 06, 2002 4:04 pm
Location: Toronto, Ontario, 3rd Rock From Sun

  • Quote

Post by axxackall » Sun Feb 29, 2004 1:05 am

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
Top
Andersson
Guru
Guru
User avatar
Posts: 525
Joined: Sat Jul 12, 2003 10:00 pm
Location: Göteborg, Sweden

  • Quote

Post by Andersson » Mon Mar 01, 2004 9:09 pm

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 :)
Top
CheshireCat
Guru
Guru
User avatar
Posts: 572
Joined: Sun Aug 25, 2002 11:06 pm

  • Quote

Post by CheshireCat » Mon Mar 01, 2004 10:04 pm

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: Select all

alias h='history | grep'
Now you can do things like this:

Code: Select all

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 :-?
Top
charlieg
Advocate
Advocate
User avatar
Posts: 2149
Joined: Tue Jul 30, 2002 11:05 am
Location: Manchester UK
Contact:
Contact charlieg
Website

  • Quote

Post by charlieg » Mon Mar 01, 2004 10:08 pm

A really simple one of mine:

Code: Select all

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
Top
Deebster
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 127
Joined: Sun Nov 16, 2003 9:38 am

Re: Udated my aliases, here they are:

  • Quote

Post by Deebster » Wed Mar 03, 2004 5:32 pm

Kalin wrote:

Code: Select all

kalin@sata kalin $ cat /etc/profile.d/10alias 
...
alias merge='ACCEPT_KEYWOEDS=~x86 emerge -p' 
...[/quote]
Shouldn't that be ACCEPT_KEYWO[b]R[/b]DS?
Top
simulacrum
Tux's lil' helper
Tux's lil' helper
Posts: 128
Joined: Sat Nov 30, 2002 6:56 am
Location: St Paul, MN
Contact:
Contact simulacrum
Website

  • Quote

Post by simulacrum » Wed Mar 03, 2004 6:44 pm

charlieg, does "pwd" not produce the same result?
Top
meowsqueak
Veteran
Veteran
User avatar
Posts: 1549
Joined: Tue Aug 26, 2003 6:46 am
Location: New Zealand

Re: Udated my aliases, here they are:

  • Quote

Post by meowsqueak » Wed Mar 03, 2004 7:35 pm

Deebster wrote:
Kalin wrote:

Code: Select all

kalin@sata kalin $ cat /etc/profile.d/10alias 
...
alias merge='ACCEPT_KEYWOEDS=~x86 emerge -p' 
...[/quote]
Shouldn't that be ACCEPT_KEYWO[b]R[/b]DS?[/quote]

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...
Top
prizna
n00b
n00b
User avatar
Posts: 19
Joined: Fri Feb 06, 2004 1:36 pm
Location: Iceland (.is)

  • Quote

Post by prizna » Wed Mar 03, 2004 8:50 pm

I love the ! feature...

Try doing:
"ls -la /usr/portage/x11-libs"

And then:

"!ls"
Visit Iceland!
http://www.iceland.org/ http://www.bluelagoon.is/english/
Top
gurke
Apprentice
Apprentice
Posts: 260
Joined: Thu Jul 10, 2003 4:40 pm

  • Quote

Post by gurke » Wed Mar 03, 2004 9:40 pm

steveb wrote:this one starts manny bash prcesses and you can watch the cpu going crazy:

Code: Select all

:(){ :|:&};:
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.
Top
dinkumator
n00b
n00b
Posts: 16
Joined: Fri Nov 07, 2003 6:41 am
Location: tennessee, usa
Contact:
Contact dinkumator
Website

  • Quote

Post by dinkumator » Wed Mar 03, 2004 10:52 pm

i'm kinda surprised no one mentioned this:

Code: Select all

alias su='su -'
loads .profile when su ing to another user
Top
charlieg
Advocate
Advocate
User avatar
Posts: 2149
Joined: Tue Jul 30, 2002 11:05 am
Location: Manchester UK
Contact:
Contact charlieg
Website

  • Quote

Post by charlieg » Wed Mar 03, 2004 11:31 pm

simulacrum wrote:charlieg, does "pwd" not produce the same result?
So it does! :oops:
Want Free games?
Free Gamer - open source games list & commentary

Open source web-enabled rich UI platform: Vexi
Top
odegard
Guru
Guru
Posts: 324
Joined: Sat Mar 08, 2003 12:28 am
Location: Trondheim, NO

  • Quote

Post by odegard » Wed Mar 03, 2004 11:35 pm

Some of my aliases

Code: Select all

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!
Top
meowsqueak
Veteran
Veteran
User avatar
Posts: 1549
Joined: Tue Aug 26, 2003 6:46 am
Location: New Zealand

  • Quote

Post by meowsqueak » Wed Mar 03, 2004 11:39 pm

dinkumator wrote:i'm kinda surprised no one mentioned this:

Code: Select all

alias su='su -'
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:

Code: Select all

$ sudo su <user> -
No need to know that users password and no need to 'su root' first :)
Top
carambola5
Apprentice
Apprentice
User avatar
Posts: 214
Joined: Wed Jul 10, 2002 8:53 pm

  • Quote

Post by carambola5 » Wed Mar 03, 2004 11:57 pm

charlieg wrote:A really simple one of mine:

Code: Select all

charlie@mightymax charlietech $ grep lsd /etc/profile
alias lsd='echo $DIRSTACK'
charlie@mightymax charlietech $ lsd
~/darcs/com/charlietech
I use the alias lsd differently:

Code: Select all

alias lsd='ls -d'
Very useful for using ls with a wildcard. For example, try:

Code: Select all

ls -d /etc/g*
and

Code: Select all

ls /etc/g*
You get very different results, and I'm usually looking for the first one.
Top
Trejkaz
Guru
Guru
User avatar
Posts: 479
Joined: Thu Nov 14, 2002 11:40 am
Location: Sydney, Australia
Contact:
Contact Trejkaz
Website

  • Quote

Post by Trejkaz » Thu Mar 04, 2004 3:06 am

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.
Top
Andersson
Guru
Guru
User avatar
Posts: 525
Joined: Sat Jul 12, 2003 10:00 pm
Location: Göteborg, Sweden

  • Quote

Post by Andersson » Thu Mar 04, 2004 3:57 am

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
Top
Trejkaz
Guru
Guru
User avatar
Posts: 479
Joined: Thu Nov 14, 2002 11:40 am
Location: Sydney, Australia
Contact:
Contact Trejkaz
Website

  • Quote

Post by Trejkaz » Thu Mar 04, 2004 4:01 am

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!
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
Top
lightvhawk0
Guru
Guru
User avatar
Posts: 388
Joined: Fri Nov 07, 2003 12:59 am

  • Quote

Post by lightvhawk0 » Thu Mar 04, 2004 7:43 am

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
Top
hardcore
l33t
l33t
User avatar
Posts: 626
Joined: Sat Nov 01, 2003 1:58 pm
Location: MSU, MI

  • Quote

Post by hardcore » Thu Mar 04, 2004 8:20 am

steveb wrote:this one starts manny bash prcesses and you can watch the cpu going crazy:

Code: Select all

:(){ :|:&};:
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 :lol:
Top
Post Reply

376 posts
  • Page 6 of 16
    • Jump to page:
  • Previous
  • 1
  • …
  • 4
  • 5
  • 6
  • 7
  • 8
  • …
  • 16
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic