Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > navigating around the commandline

navigating around the commandline
Thread Tools
Forum Regular
Join Date: Oct 2000
Location: Raleigh, NC, USA
Status: Offline
Reply With Quote
Feb 1, 2006, 06:22 PM
 
This is a pretty trivial thing... but it would save me a lot of time in the long run.

Often I'll type a long string in the Terminal, and after hitting Enter, I'll realize that I made a mistake. For instance, maybe I forgot to put "sudo" at the beginning of the command. So, I'll hit the up-arrow to bring it back up. Then I hold down the left-arrow to slowly move the caret to the beginning of the line, so that I can fix the mistake.

My question is... is there any easier way to get the caret to the beginning of the line? None of the typical word processing tricks work (command-arrow, etc).

Thanks :]
Justin
     
Grizzled Veteran
Join Date: Apr 2002
Location: case.edu
Status: Offline
Reply With Quote
Feb 1, 2006, 07:41 PM
 
Yes, there is.

Short answer: Control-A.

Long answer: the shell (bash) uses a library called readline which lets you use emacs-style (or optionally vi-style) editing commands at the command line. Some emacs keystrokes that also work in bash:
C-a (means Control-A): go to beginning of line
C-e: go to end of line
C-w: delete one word
C-k: Kill (cut) from cursor to end of line
C-y: Yank (paste)

And a bash-only one:
C-x C-e: Edit the command line in your $EDITOR (probably vi or nano if you haven't set it up)

Really long answer: "man bash" and/or "man readline"

Oh, and when you forget to type sudo: '!!' expands to the last command entered, so you can just type 'sudo !!' and it will do what you want.

pb 1440x960 | 1.67, 1.5, 128, 80 | leopard
     
Forum Regular
Join Date: Oct 2000
Location: Raleigh, NC, USA
Status: Offline
Reply With Quote
Feb 1, 2006, 08:04 PM
 
Man, I should have asked that question a looong time ago

Thanks a lot... don't know how I've lived without knowing that.
     
Grizzled Veteran
Join Date: Apr 2002
Location: case.edu
Status: Offline
Reply With Quote
Feb 1, 2006, 08:07 PM
 
One more thing:

Once you become addicted to those keystrokes, try them in a regular Mac text field (like TextEdit). Lots of them work there too, thanks to the good folks at Apple.

pb 1440x960 | 1.67, 1.5, 128, 80 | leopard
     
Forum Regular
Join Date: Oct 2000
Location: Raleigh, NC, USA
Status: Offline
Reply With Quote
Feb 1, 2006, 08:10 PM
 
Oh, beautiful
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:30 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2