I was tearing away this morning configuring something in the shell. My wife peaks over my shoulder and says “How do you do that?!” I have a nice laugh and there was born an idea for my next post. This post outlines
some basic shell shortcuts. note: these use the default shell bindings, based on emacs.

Shell Shortcuts

First lets start with some simple stuff.

Clearing the screen. I still see a lot of people using the old ‘clear’ command to do that. A shorter method is:

ctrl-l

Exiting the shell or logging out. I’m sure the most common way to exit your terminal session is using the ‘exit’ command. This can also be done with:

ctrl-d

Searching the history. I’m guessing you’re familiar with using the up/down arrow keys for finding previous run commands. Did you know you can search through your history too, helping avoid hitting up a hundred times.

ctrl-r + command

The above will find the most recent match. If you’d like to go further back hit the key sequense again and it’ll toggle through matches of ‘command’ deeper into your history.

Using the previous argument. This is one of my favorites, and really can save some typing and monotony. You can drop in previously used arguments to your current commands with:

esc-. or alt-.

These are all that came to me off the top of my head. What other shortcuts do you use for the default shell? I’ll have a future post about set -o vi, so if you’ve got tips for that hold them for now.

You also might be interested in an earlier post on using copy and paste within the terminal.

I post tutorials very regularly on this site. You may want to consider subscribing to the RSS feed. Or if you'd prefer these tips sent to your inbox you can use Email Subscriptions.

I installed Fedora 8 on my macbook the other day just to tinker and see how the other side live and I wanted to make sure I got a few things written down concerning the installation. I had to dig & dig to get it to work, so here’s to hoping others will not have the same problem. (Anyone else notice there seems to be much more Ubuntu documentation than there is for Fedora and other distributions?)

Installation

The first issue I had was that the installer would begin, load the kernel from the CD and then just freeze and hang. The fix I found for this was using two kernel parameters:

nohz=off nolapic

Once getting past that I then had a really annoying key press repeat error. Anything I pressed on the keyboard was inputted twice. To get rid of that I also used:

irqpoll

In the end, to get the installer to work on my Macbook (C2D, second gen) I hit esc at the installer initial prompt and entered the following:

linux askmethod irqpoll nohz=off nolapic

After installation everything seems to work well enough. I’ve found a few annoyances like the touchpad not having the features it does out-of-the-box like Ubuntu (scrolling, right-click, etc). Also my wireless will work after building from source (also something needed on Ubuntu), but it won’t actually connect to anything. If anyone has any tips in that regard it is a:

02:00.0 Network controller: Atheros Communications, Inc. AR5418 802.11a/b/g/n Wireless PCI Express Adapter (rev 01)

update: the above restriction only applies to NetworkManager 0.7.  If I configure it manually it’ll work fine..

Sound seems to work ok. Resolution and graphics are fine as well. Volume and brightness hotkeys don’t work as they do in Ubuntu, but that isn’t a huge deal. Probably something that can be fixed with a couple quick bug reports. Over all, not too shabby… other than the initial trouble of actually getting it to work!

Suppressing Login Messages 

I do a lot of remote remote maintenance via ssh on my machines and one thing that I’ve long wondered about is the message outputted when you login.  You know, the system information output plus the notice concerning the warranty, etc.  Here is the output I’m referring to when connecting to my Sun Sparc Ultra 10 server via ssh:

Linux sparc 2.6.15-51-sparc64 #1 Tue Oct 23 21:46:00 UTC 2007 sparc64 GNU/Linux

The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
Last login: Sun Dec  9 12:50:43 2007 from 192.168.0.6

Now, that information is not ultra annoying by any means, but sometimes after repeated connections I just really don’t want to see it.  So, I finally found way that the information above can be suppressed.  All you need to do is create an empty file in your home folder and those login messages will be suppressed.

touch .hushlogin

Run that command, which just “touches” a file into creation with no contents.  If the login system finds that file it’ll suppress the login message above.  Note: if you want login messages suppressed on remote machines you need to create this file on the remote end.

Enabling Login Messages

The login message above actually comes from a file on the machine at /etc/motd.  If you’d like to change the message on your machine you can simply edit that file.

sudo vim /etc/motd

If you’d like to enable a different login message, which can often be used to pass messages to anyone logging into the system, this might be a good place to do it.

I spent the day teaching a class on Redhat Enterprise Linux 5 and in doing so got in the habit of using some Redhat specific commands. After class when I got back on my Ubuntu laptop I attempted to restart a service using “service network restart”. Instead of complaining about the service command not being found it instructed me that if I wanted that tool I would need to install the sysvconfig.

If you’re familiar with the Redat tool, service, and would like that functionality on Ubuntu simply do the following:

sudo aptitude install sysvconfig

Once this package is installed you can then start, stop or restart services on your machine using commands like:

sudo service apache2 restart
sudo service ntpd stop
sudo service network restart

As far as I understand this is equivalent to running:

sudo /etc/init.d/apache2 restart

If anyone knows any other differences between ’service’ and ‘/etc/init.d/’ I’d be interested in hearing about them. Enjoy.

This vim tip of the week was submitted by Andrew.  Many thanks.  Do you have a vi/vim tip that you’d like to share with the world?  Visit my contact page and send me your idea!

This vim tip relates to updating multiple windows or tabs within vim with a single command.  If you ever edit multiple files at once, or use the tabbing or windowing feature of vim this can save you some typing.  To do this we’d use the command:

:windo {cmd}

As Andrew outlines in his submission:

This is a fantastic command that has saved me much typing since I discovered it. Put simply, it executes {cmd} once for each open Vim window. If you've just opened a large number of files each in their own window and need to do the same thing in each, this is what you want.

Here is an example of using :window {cmd} to do a find and replace across multiple files:

 :windo %s/search/replace/g

There are also the :windo related commands such as:

:bufdo {cmd} - run {cmd} in each buffer

:tabdo {cmd} - run {cmd} in each tab

:argdo {cmd} - run {cmd} in each file in an argument list

I want to thank Andrew again for his submission.  If you have a vim tip that you’d like to share feel free to submit it via my contact page.

I realize I haven’t posted a Vim Tip of the Week for the past few weeks. I’ve been out on the road for work running ragged and just trying to keep up. Now that I’m home for the weekend I thought I would try to catch up a bit.

My suggestion this week for all of you that really want to get comfortable and master the art of Vi/Vim is to pick up this title from O’Reilly. VI Editor Pocket Reference.

This book is really handy for quick reminders during the initial learning curve and is small enough to actually fit in your pocket. Yeah, it peeks out just a bit, but definitely not something difficult to bring around in your back pocket or bookbag.

While the more advanced user may not find this terribly helpful (as you’ve probably already mastered most shortcuts) this is definitely a great reference for new users. It also covers the vi relatives / forks like nvi, elvis and vile.

All in all I recommend this book for new users as it covers most of the basics in a quick reference guide style. It doesn’t go into a lot of deep detail though, so if you’ve been using vi/vim for a while now you probably wont learn much more from it.

Today’s post is a quickie, and more along the lines of a “package of the day”, but I thought it would be interesting to share.

The time command in Linux will offer you system resource summaries and total time taken to complete the job requested. Usage of the time command is very simple (although see man time for more information).

I used this command last to see how long it took to write psuedo-random data to a 6G USB disk:

time dd if=/dev/urandom of=/dev/sdb bs=4096

(example output, not accurate for this command)
real 22m1.513s
user 0m0.076s
sys 0m0.016s

The time command can be a prefix to just about any command you run and want a timed output for.  Give it a try.

I’ll preface this post with a quote from one of our local users, findlay:

11:15 < findlay-w> I can edit google's homepage from within vim?!
11:15 < findlay-w> now that's a powerful editor!

That’s right vim is a powerful editor! Now, of course, you can’t publicly change Google’s homepage with vim but you can edit it directly to be saved elsewhere. Same with any other web-based file or file on a remote machine. Here are some examples:

vim scp://user@hostname/path/to/file (remotely edit a file via scp)

vim ftp://user@hostname/path/to/file remotely edit a file via ftp)

vim scp://user@hostname/path/to/dir (remotely show directory contents with the ability to select and edit a file)

And from within vim, if you’d like to open a remote file or create a remote file.

:e http://google.com/ (remotely see/edit the contents of Google's homepage)

:e http://yourwebsitehere.tld/ (remotely see/edit the contents of your homepage)

:e scp://user@host.tld//etc/apt/sources.list (remotely edit the sources.list file on another machine via scp)

:e ftp://user@host.tld//pub/somefile (remotely edit somefile on another machine via ftp)

...or the examples above prefixed with :e

I’m sure that is enough to get you in trouble–err, I man, started. Enjoy. For more information on how all of this works and additional options, please see the help for netrw within vim (:help netrw).

And that has been this weeks “Vim Tip of the Week!”

This tip will be a quick one, and I want to thank one of the commentors on a previous post for pointing this out to me.  The vim that comes installed on your base machine is not the full vim, for some reason.  I guess its the basic “this’ll get the job done”-vim, but not the “this has all the cool features”-vim.

To install the full vim use your favorite package manager or install the package using this command:

sudo aptitude install vim-full

From the package description:

Vim is an almost compatible version of the UNIX editor Vi.

Many new features have been added: multi level undo, syntax highlighting, command line history, on-line help, filename completion, block operations, folding, Unicode support, etc.

This package contains a version of vim compiled with support for the GNOME2 GUI and scripting support for Perl, Python, Ruby, and TCL.

This package provides the full vim command line editor and also the gvim GUI front-end of the same.

If you use vim and you haven’t installed the vim-full package you don’t know what you’re missing!

Well these Vim tips have really been one of the more popular topics to come through this blog in a while.  I’d like to keep with tradition and keep these going each Friday.  This weeks tip is reverting or redoing changes based on time, vs simply the undo command (’u') and redo command (’ctrl-r’).

From the vim :help section:

:earlier {count}    Go to older text state {count} times.

:earlier {N}s    Go to older text state {N} seconds before.

:earlier {N}m    Go to older text state {N} minutes before.

:earlier {N}h    Go to older text state {N} hours before.

Also supported is the :later command following the same syntax pattern. Easily revert to changes at previous times with the :earlier, or re-do changes forward with :later.  Of course :later won’t read your mind and create your document for you, but once you’ve gone back in time you can go back to the future.

For more info on this tip type “:help earlier” within vim.

Next Page →

    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Get Ubuntu!



  • Blogroll

  • Ads by Google