Bash tips and tricks

25 11 2007

This post is at my new blog at Interesting Things. Thanks.


Actions

Information

102 responses

25 11 2007
Maarten Kooiker

Thanks for the tips. Though I use the terminal only once in a while, I (and many others with me I guess) prefer not to use it…. at least 90% percent of the persons that use computers panic if there is no mouse…….command line? what’s that?
But thanks anyway!
Cheers,
Maarten

25 11 2007
Subban

Excellent info, the way history was handled was pretty annoying but I hadn’t got around to looking whether it could be changed in any way, you just saved me a job and for that I thank you :]

25 11 2007
Basic bash setup tips « 0ddn1x: tricks with *nix

[…] Basic bash setup tips Filed under: Linux, OSX — 0ddn1x @ 2007-11-25 23:39:10 +0000 https://richbradshaw.wordpress.com/2007/11/25/bash-tips-and-tricks/ […]

26 11 2007
Ryan Neufeld

I have been using linux now for about three years. This is a great set of tips!!

26 11 2007
Jamax

The best set of bash tips:

* emerge zsh
* apt-get zsh
* yum zsh

Zsh does all this and more, like floating point math, for ((i=0; i<aval; i++) loops, “prog | read aval” (and aval is useable in rest of script), etc.

26 11 2007
Eliena Andrews

You rock man, thanks for the hot tips. U saved lot of time for us. Thanks

Eliena Andrews

26 11 2007
Bash tips and tricks « Richard’s linux, web design and e-learning collection

[…] simmosays wrote an interesting post today onHere’s a quick excerpt […]

26 11 2007
Linux UNIX top DIGG news » Bash tips and tricks

[…] read more | digg story […]

26 11 2007
pappugulal

Same here … saved a job… was wanting to get to history overwriting for some time now. Thanks.

26 11 2007
Marc

Good bash tips. I’ve also got some miscellaneous bash tips at my site:

http://marc-abramowitz.com/archives/category/computers/software/unix/bash/

26 11 2007
Ally

Try this:
$ history | grep "foo"

Where “foo” is what you want to find in your recent history. Useful if it was a complicated command.

26 11 2007
Mackenzie

Marten:
Mice are for window management (focus-follows-mouse ftw!) and photo-editing only. Anything else, the terminal can do much faster. I’d feel right at home with no mouse as long as I had a nice bash shell (Windows’ big suckage point for me is its shitty shell).

The history cleaner-uppers look pretty useful. Thanks!

26 11 2007
Metagg

Metagg is tracking this post

Find out what Social News Sites are discussing this post over at metagg.com

26 11 2007
Superb link for Today at 4rif wicaksono

[…] 2.Cool bash tricks and tips : actually i want to write how to coloring bash in linux ,but it’s an old tricks so this one is not just ordinary bash tricks(i hope ;D) https://richbradshaw.wordpress.com/2007/11/25/bash-tips-and-tricks/ […]

26 11 2007
David Thomas

I use Ctrl+R alot for a bash history search. Open a terminal, press Ctrl+R, start typing a recent command and it will find it for you 🙂

26 11 2007
ayaz

Helpful tips. I love to customise the shell on my home system as much as I want, and while that is done both out of convenience and taste, it runs the risk of ruining my habits when I have to sit behind other shells or shells on other systems where my customisations are either not available.

26 11 2007
Sébastien Wains homepage » Bash tips and tricks

[…] Richard posted some nice tips about bash history.. […]

26 11 2007
26 11 2007
ecelis

Just to pin point, bash is not the default shell on Ubuntu since 6.10

26 11 2007
Josh

I don’t have any tips for you but I do have a question. How does one go about getting un-hitched from the MS wagon without trashing all your computer stuff? I mean you practically MUST have a computer to pay bills and shop and things…Is there a good way to flip it?

Here’s a frame of reference for the question: I was thinking about this yesterday: the last Microsoft operating system I really liked was MS DOS 6.x–any suggestions?

26 11 2007
rungss

If you want to just copy paste here is the code compiled for this purpose.

# Bash tips and tricks for History related preferences
# see https://richbradshaw.wordpress.com/2007/11/25/bash-tips-and-tricks/

# == 1 Lost bash history ==
# the bash history is only saved when you close the terminal, not after each command. fix it..
shopt -s histappend
PROMPT_COMMAND=’history -a’

# == 2. Stupid spelling mistakes ==
# This will make sure that spelling mistakes such as ect instead of etc are ignored.
shopt -s cdspell

# == 3. Duplicate entries in bash history ==
# This will ignore duplicates, as well as ls, bg, fg and exit as well, making for a cleaner bash history.
export HISTIGNORE="&:ls:[bf]g:exit"

# == 4 Multiple line commands split up in history ==
# this will change multiple line commands into single lines for easy editing.
shopt -s cmdhist

26 11 2007
Andrew

Esc .! Typing this into the bash shell brings up the last “word” from the previous command. Often that’s the file or object you are dealing with. Note you can also use Esc and “_” but typing “_” requires a shift – “.” doesn’t. So then you can do stuff like:

$ ls file
$ more file
$ rm file

The object here is “file”. So you probably typed “ls file” or did filename completion. Then you say to youself “Hmmm what’s in file?” and type more. Just type Esc . and file will be filled in for you. Of course, file can be some real long path too. After looking at the contents of file you decide to get rid of it so you type rm then Esc . again recalling file.

26 11 2007
Fourbissime

thanks for the tips.

Alternatively to the ctrl+R, a simple way to recall a command you’ve done earlier is :

!xxx

where “xxx” are the first few letters of the command.

26 11 2007
Planet Malaysia

Thanks for the tips. Never use before.

26 11 2007
extrapreneur

Cool tips mate, I think I’ll try some. Check out my blog at http://www.extrapreneur.wordpress.com

26 11 2007
Basic bash setup tips « 0ddn1x: tricks with *nix

[…] Basic bash setup tips Filed under: Linux, OSX — 0ddn1x @ 2007-11-26 15:49:53 +0000 https://richbradshaw.wordpress.com/2007/11/25/bash-tips-and-tricks/ […]

26 11 2007
26 11 2007
BASH history preferences « Brave Dave’s Musings

[…] history preferences See this blogpost for tips on modifying BASH command line history […]

26 11 2007
David

Ctrl+R is part of series of shortcuts that come from emacs, so just learn emacs and you learn to better manipulate the bash shell. Like Ctrl+w, Ctrl+d, Alt+d, Ctrl+y, Ctrl+a, Alt+a, Ctrl+e, Alt+e, etc. etc….hell it evens supports undo try Ctrl+_
Or if your more a vi person just do set -o vi and follow the same principle.
Another nice tip: ^foo^bar to substitute foo by bar in the previous command

26 11 2007
rungss

I entered these commands and later when I started terminal which was after I rebooted the system I got the following error.

bash: -a’: command not found
rungss@rungss-ubuntu:~$ gedit ~/.bashrc &

this I suppose was because of the line

PROMPT_COMMAND=’history -a’

any idea why this is happening??

26 11 2007
davesmylie

For getting the last object referred to, another way to do (that’s slightly quicker/easier to type than ESC + .) is:

Alt + . (I find it a lot easier to hit alt + . as to get escape requires moving hands quite a bit from the home row)

By far the coolest bash trick, (that I only learnt about last year) is repeating multiple parts of the commant with curly brackets {}. Ie, if you are in home and need to quickly make a backup copy of /etc/apache2/httpd.conf (to pick a file at random), instead of typing
cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bak
you can type
cp /etc/apache2/httpd.conf{,.bak}

I use that trick a *lot*.

26 11 2007
richbradshaw

@rungss: make sure you use a normal ' not a ‘ – I’ve changed the text above to make it work properly now.

26 11 2007
it’s about time» Blog Archive » links for 2007-11-26

[…] Bash tips and tricks « Richard’s linux, web design and e-learning collection wonderful stuff people – bash is not scary, its a doorway to power and control. (tags: bash blog command commandline commands history howto job sysadmin unix linux shell tips) […]

26 11 2007
blstern

I like beans

27 11 2007
links for 2007-11-27 « Bijay Rungta’s Weblog

[…] Bash tips and tricks « Richard’s linux, web design and e-learning collection (tags: ubuntu shell commands bash linux tips unix howto sysadmin productivity documentation my_settings dev_environment) […]

27 11 2007
shanti

Great tips, mate!

27 11 2007
Jason

when trying to track down a file(s) that are hogging up disk space, I use:


for each in `ls -1`;do du -sh $each;done
528M cache
39M lib
8.0K local
32K lock
262M log
16K lost+found
4.0K mail

and then cd and follow the big directories to the big files

26 10 2011
Nell

Why not type
du -sh * | sort -n
it will list the hoggers at the bottom

27 11 2007
Тут Хумора.NET » Выпуск #335

[…] #335 Bash tips and tricks. Несколько полезных хитростей популярной в среде […]

27 11 2007
Pádraig Brady

Jason, have a look at dutop.
Also baobab presents disk usage is a nice graphical way

27 11 2007
kranken

Very nice tips.

Using ctrl-R to search history is way better than “cat .bash_history | grep foo” which I’ve been using.

27 11 2007
katm

I’ll definitely have to try some of these. I’ve been getting myself more and more comfortable in a shell. I find there are certain things I can do faster from the command line and certain things I still do faster from the GUI. But I’m learning.

Thanks.

27 11 2007
Pavan

Very useful article indeed. Thanks!

To refer to the last parameter in the previous command you can use $_
(a specific instance of an object)

Eg.
ls /tmp
echo $_ # prints /tmp

On a bash shell, you can navigate with these commands
* ALT f – one word forward
* ALT b – one word back
(in case you are typing a loooooong command)
* CTRL a – beginning of current command line
* CTRL e – end of the current line

Further, to toggle cases of the command/arguments,
* ALT l (it is eL small case) to change the next word to all smallcase letters
* ALT u to change the next word to all uppercase letters

* CTRL w deletes a word backwords (more like backspace, but for an entire word)
* CTRL k deletes the rest of the line after cursor

27 11 2007
27 11 2007
richbradshaw

Thanks for everyone’s comments – there’s more useful info in the comments than in the article now!

27 11 2007
Pierre

Great tips, thanks alot!

28 11 2007
Tech interview questions » Blog Archive » Bash history tips

[…] Bradshaw posted some useful bash tips – making bash remember your history, making the shell forget your spelling mistakes, removing […]

29 11 2007
links for 2007-11-29 « J.Uma Shankar Ladha

[…] Bash tips and tricks « Richard’s linux, web design and e-learning collection (tags: bash tips linux shell unix sysadmin commands) […]

30 11 2007
x140x1n

Maybe Maarten should reconsider Windowz.
How can you be using linux and avoid the terminal.

http://www.catb.org/~esr/writings/unix-koans/gui-programmer.html
🙂

30 11 2007
\x6a\x61\x6b\x65

VERY nice article (and comments!) for those trying to convert from the dark ways of the M$.

4 12 2007
expatCM

Richard, you wrote “make sure you use a normal ‘ not a ‘ – I’ve changed the text above to make it work properly now.”

I copied and pasted but I still get “bash: -a’: command not found” (also on an Ubuntu machine)

4 12 2007
expatCM

Richard, you wrote “make sure you use a normal ‘ not a ‘ – I’ve changed the text above to make it work properly now.”

I copied and pasted but I still get “bash: -a’: command not found” (also on an Ubuntu machine)

4 12 2007
richbradshaw

Doh – you are right. Just make sure you use real apostrophes then. After pasting it change both to a normal apostrophe – damn blog template!

5 12 2007
expatCM

Spot on …. that fixes it, thank you 🙂

6 12 2007
Abhishek

I am using linux since last three years and history allawys annoyed me…thnaks for your tips, it did a great work for me

7 12 2007
alp082

I have another good suggestion to improve your bash history control, i recommend to use it: Extended Bash History like in Gentoo

12 12 2007
Concatenation: Encrypt /home, An Introduction to Wine, Some really cool bash tips « Random Viking

[…] Richards linux, web design and e-learning collection: Bash Tips and Tricks […]

13 12 2007
Linux в digg на русском » Blog Archive » Советы и подсказки по bash

[…] Перевод заметки Bash tips and tricks […]

14 12 2007
Советы и подсказки по bash - This Might Be Useful

[…] Источник заметки Оригинал на английском […]

18 12 2007
R.J. Mote

Re: Ecelis’ comment: “Just to pin point, bash is not the default shell on Ubuntu since 6.10”:

This is true, but also false. Gnome-terminal is the default terminal emulator, but by default it operates in a bash shell environment, and bash is part of the default install from 6.10 straight through to the current 7.10 (and before, and likely after, though the zsh lobby is still fairly strong on the Ubuntu forums, and I can see the advantages of zsh myself). I added most of these tips to my .bashrc, tweaked a few other settings, cranked up the terminal, and they all worked and applied. If you have a ~$ at your prompt, odds are you are running a bash shell in your terminal, too.

22 12 2007
One set of developer tools for Drupal | Mastering Drupal

[…] a parting shot, I recommend reading Bash tips and tricks and 10 Linux shell tricks you don’t already know if you run Linux. Bookmark/Search this post […]

21 01 2008
Richard Sheppard

Excellent stuff. Most all of these work with OS X as well.

If you don’t have a .bashrc file in the terminal, then it could be the .profile file instead. It was the case for me, and after adding the mods to it, they functioned just as they would if I were using linux.

🙂

23 02 2008
teich

If you are using multiple terminals and want to share the history between them as you are working, you should instead use:

PROMPT_COMMAND=’history -a && history -n’

You’ll need to press enter once before you get the history from the other bash shell(s) though.

3 04 2008
d1s4st3r

Nice, thanks!

15 04 2008
iosakwe

Very nice article indeed and superb comments, I am especially fond of Pavan’s contribution.

5 05 2008
Of bash, history and you

[…] Editing your .bashrc file so that you could keep your commands appended to the history instead of overwriting the history. What to write in .bashrc? This: […]

18 07 2008
sejeff

Take a look at this page right here:
http://digitalprognosis.com/blog/2008/06/13/increasing-command-line-productivity-in-the-bash-shell-pt-ii/

It shows you how to add timestamps to your history. This is a great article and I’ll do a followup with some of the tricks from here. Keep up the good work.

18 07 2008
BASH Shortcuts « Random Musings

[…] are some really cool Bash tips and tricks on this blog i just […]

1 09 2008
name

Hi!,

2 09 2008
guido

Some useful Bash hints also here:

http://codesnippets.joyent.com/tag/bash

7 09 2008
Bnetfdgsjieoc

joe arroyo no le pegue a la negra mp3 usc classical music listen music now rap

21 09 2008
redzone

nice post and nice blog

23 10 2008
EugeneVC

I use zsh, but bash is compatible.

21 11 2008
linux tips

Nice set of tips. PLease have a look at my set of tips at

Linux tips and tricks

5 01 2009
Bash tips and tricks « Basil’s World

[…] Read more here […]

30 01 2009
Legal Hallucinogens

Where is the new address?

30 01 2009
MedsOnline

I can’t find the new site…

30 01 2009
Get Bigger Breast

Anyone could help me?

30 01 2009
Male Masturbator

I don’t get it!!!

10 09 2009
sandrar

Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

11 10 2009
Hafodax

Если не сложно… хочу сайт про яхты сделать. У тебя вроде сайт на вордпрессе – не мог бы подсказать где морских шаблонов взять? Плиз – скажи тут (я на рсс подписался) или кинь линку на мыло Hafodax(гав-гав)gbail.com
Заранее спасибо – пост грохни если чо 🙂 Сорри что не в тему.

16 10 2009
Amirtham Purendra Raman

good and useful blog,here is other one blog http://bamirthampr.wordpress.com

28 02 2010
Erection pills

realy useful tricks

10 04 2010
Tighten Your Vagina

The default items on the page include a teaching timetable, a calendar, email, online file storage, some educational bookmarks, photos tagged education, a todo list and a google search box.

19 04 2010
Website laten maken

Thnx for Sharing this!

11 05 2010
DMashups » Blog Archive » Bash tips and tricks

[…] read more | digg story Posted in Tutorials | No Comments » Leave a Comment […]

17 06 2010
Meds

Meds online – fast and cheap way to buy medications

9 07 2010
Meds order

Order meds online

10 08 2010
wedding magician london

Thanks for the tips I use command line all the time – i love it when people say where’s your mouse!

Roger

10 08 2010
photographer hampshire

I tried linux once – got the ubuntu cd and installed it – could never get on with the command line stuff – so went back to windows

11 08 2010
CCIE to be Roger Perkin

I am studying for my CCIE and everything is on the command line – I love it!

18 11 2010
SEO

Could be me, but where is the info?

15 01 2011
rapidleech

This post is great. thank you for sharing these helpful infos. I appreciate your work man

15 01 2011
rapidleech

hi,
I am very glad to thank yousharing this post.I also appreciate your work here.nice blog

11 07 2011
crystal admiral

Thanks for sharing! New site looks perfect.

1 09 2011
Suffolk Wedding Photographer

Great info! Thanks very much!

13 11 2011
overnight generic meds

reliable store, fast delivery

21 02 2012
Jerome Lantheaume

This is really top noch info! Thanx a lot, find some really useful stuff in here.

11 01 2013
http://tinyurl.com/cheashore52687

I personally blog too and I am creating something comparable
to this particular blog post, “Bash tips and tricks Richards
linux, web design and e-learning collection”.
Would you care if Imake use of several of your personal suggestions?
Thanks for your time ,Morgan

23 09 2013
marriage counselor play cast

Marrage rates apparently are to the drop. While it’s
an oft-repeated information that 50-percent of first partnerships end in
divorce, that range has remained unchanged for your past 30 years.
Breakup rates also change with the partners’ level of spiritual morals, training, and a great many other components.

Marriage counseling, also known as partners therapy, can
be a sort of psychotherapy. Marriage counseling helps couples
of most types improve their associations and identify annd handle conflicts.
Through marriage counseling, you possibly can make considerate
decisions about re-building your partnership or heading your separate ways.

We’ve been together for fifteen years and we have two
children. For me to know that I loathe being in couples therapy
with him since he never changes we have been in couples therapy enough different times.
It’s been more productive for me personally to go to remedy alone, where no less than I can accomplish things.
Nevertheless now we’re desperate, so I’ve capitulated.

When relationships commence proceeeding sour, lovers teend tto be urged to go view a
psychologist or to attend a workshop or seminar to aid lessen
their complications. But these selections tend to be
quite expensive and outside a budget. It’s not
likely a clever concept to incorporate economic pressure too the challenge
by ponying up $100 one hour for professional counseling, if
there’s alkready stress within your marriage. And a great deal of men aren’t interested inn referring to their feelings
to your stranger or a room filled with strangers. We prefer to handle dilemmas ourselves.

An excellent marriage counselor assists loers prevent a number oof these psychological landmines and is there
for damage control if they are triggered. He/she
does this by knowing the gteat stress partners are under while they are
facing one among their greatest crises.
marriage counselor play cast
When one oor both partners become sentimentally upset, he/she gets the ability too analyze and treatt the
mental reactions effectively. I counsel with a psychiatrist who prescribes psychotropic
medicine (anti-anxiety and anti-depressants) to alleviate tthe emotional pain that typically accompanies the process
of marriage adjustment.

An excellent counselor knows how-to calm tthe pair down and assurte them that their emotional reactions aren’t
an indicator of despairing incompatibility.

2 01 2014
presto bad credit auto loans phoenix arizona

Money is borrowed by car dealers at wholesale rates of interest, that they then mark up and spread
to you. Since the dealer’s rate is lower, the rate you get may be no higher than one you arranged oneself.

Still, the only method to ensure of the would be to understand
what your best charge is before you can the dealer.

Till you’ve etermined why yyou wee rejected don’t try,
try again, if initially you don’t triumph and took actions to deal with it.
Credit ratings will be the primary determinant of who
gets accepted for loans, and if you didn’t check your credit
score before you used the first time, it behooves you
to do so before implementing again. Several loan purposes quickly trigger a credit check, all of which may hit a few more items off
your credit score, making what could have been a
negative situation a whole lot worse.
presto bad credit auto loans phoenix arizona
And you’ve taken all possible ways to improve
it, you’re able to do what we suggest for all car buyers:
Look around for an excellent interest-rate before returning to your dealer if your credit score is accurate.
Credit unions are a fantastic choice; while they’re perceived as unique, their interest levels are usually lower-than many banks
and they’re more prone to analyze a sub-prime customer’s situation
and make exceptions if bothersome credit history benefits from one-periodmedical costs,
unemployment or divorce.

Don’t disregard the bank where you’ve a savings
or checking account. Your financial background will not be
a mystery to any potential lender, as it’s easier for a bank to sell solutions to its customers than
it’s to find new customers, but a current connection can work within
your favor.

Eventually, don’t exclude financing a car at the dealership.
Only a dealership could possibly offer brand-new -car financial rates
in the automaker; these rates are occasionally the bottom offered.
If you’ve taken our suggestons but had minor success using different loan places, a store may bbe morre willing if you’re purchasing
one of its automobiles, especially an used one to make loans lodgings, additionally.
A larger one may have more tolerance for risk or
have good relationships with more lenders, if the dealership that refused
you the first time was smaller.
cash time auto aaa car title loans phoenix az
Interest rate – affirm the APR, or annual percentage rate, to your loan
and whether it is fixed or adjustable rate

Total amount funded – make certain the amount on your own loan
docs will be the identical to everything you expected for

Monthly payments – confirm you’re able too afford to really make the payments

Prospective fines – iis it possible too pay your loan off early without paing a fee?
Or even, discover how much you would spend. At Wells Fargo,
you will find no pre-payment charges.

Feasible hidden charges – credit insurance or additional expenses could possibly be inclouded in your loan.
Unless you need them don’t pay for these services.

8 02 2014
EdwardThef

We are specialize in Bulk email marketing services using powermta4 + interspire. I can give complete set up of bulkemailing where you can send 500k emails a day. Setup includes installation of powermta4+interspire+dki/spf/rdns.

Contact me on skype for more details : Skype ID – smith.alfred86.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: