Advanced

CLI Magic: Using command history in the bash shell

Posted by dcparris on · 9 comments
Linux.com; By Mark Sobell
Mail this story
Print this story

The Bourne Again Shell's history mechanism, a feature adapted from the C Shell, maintains a list of recently issued command lines, also called events, providing a quick way to reexecute any of the events in the list. This mechanism also enables you to execute variations of previous commands and to reuse arguments from them. You can replicate complicated commands and arguments that you used earlier in this login session or in a previous one and enter a series of commands that differ from one another in minor ways. The history list also serves as a record of what you have done. It can prove helpful when you have made a mistake and are not sure what you did, or when you want to keep a record of a procedure that involved a series of commands.

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (9)

Revisiting the basics is always good, especially for all the flocks of noobs swarming to Linux.

Speaking of, am I the only who sees an awful lot of "nooo don't make me type a command" posts on forums and user lists? Is someone going to door-to-door to new Linux users and telling them frightening command-line stories?
tuxchick2:

Our old buddy BillG has spent many years trying to convince people that typing is only for word processing; clicking is for commanding your computer, er, I mean, your app.

Deliberately avoiding the command line is as silly as a carpenter who won't touch a tool that doesn't plug in. Even Norm Abrams picks up a hammer and chisel occasionally.

(For those outside the US, "Norm Abrams" refers to a carpenter/cabinet maker on tv who is known for using lots of power toys, er, tools).
We have done extensive work with both senior citizens and jr high level kids and have found a good way to "sell" the command line. See, the command line is a "bonus" you can't even Find in windows.

"Here, look at how fast I can install foo.rpm or slocate -i nickleback. Try THAT in windows". I then show them a bunch of the cool stuff you can do. Really, and this is so silly...if you change the background schema of the konsole, it makes a big difference. go figure.

The surprising thing about it is that it has worked well. I am listing it as one of the three ideas that DNH in my life. (did no harm). And no...we WILL NOT discuss the garage roof Slip-n-slide I packaged in 77. That case has been closed for years.
Saved by the statute of limitations again, helios?

:)
> I then show them a bunch of the cool stuff you can do. Really, and this is so silly...if you change the background schema of the konsole, it makes a big difference. go figure.

I find nothing odd or silly about wanting a nice looking console. I suspect that there are sound psychological reasons behind a users aversion to a little black window or worse yet, a totally black screen. I've worked with command lines from DOS on and a plain (usually black or white) screen is not a comforting feature, even after all my years of experience.... Always nice to have a little color :).
Run a little head-to-head contest with an MS Windows user. Set up a directory full of jpg images and have them resize all the images to some web-page size, like a maximum of 800 for either vertical or horizontal size, while maintaining aspect ratio. As they start to click the menus to find PhotoShop or whatever...

mogrify -geometry 800x800 ./*.jpg

And announce you're done.
Heh... 'mogrify'.I hadn't looked at that one in a while. Resize and a lot of other parameters. Very clever grouch.
You can really show off with Dave Madison's Album, which incorporates Image Magick. You can do the resizing and create a photo gallery with thumbnails all with one command. http://marginalhacks.com/Hacks/album/
Thanks for the link, tuxchick2.

Maybe we need a bash script tips thread. A very short one that I find myself using pretty frequently is simply:

for n in * ; do if [ -d $n ]; then du -hs $n ; fi ; done

I bet the bash reference manual is sufficient to scare the beejeezus out of some newbies. It's like dropping a Neanderthal into a modern car; he will think he has to know all about every button, gauge, lever and light before he can drive. It's nice to have climate controls for every seat, but they're not necessary to make the car do something useful.

http://www.gnu.org/software/bash/manual/bash.html

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post