» tagged pages
» logout

sorted by: recent | see : popular
Content Tagged with bash + Programming

Mastering The Linux Shell - Bash Shortcuts Explained (Now With Cheat Sheets)

imageDuring my day-to-day activities, I use the Bash shell a lot. My #1 policy is to optimize the most frequently used activities as much as possible, so I’ve compiled these handy bash shortcuts and hints (tested in SecureCRT on Windows and Konsole on Linux). The article only touches on the default bash mode – emacs, not vi. If you haven’t specifically assigned your shell mode to vi (set –o vi), you’re almost certainly using the emacs mode. Learn these and your shell productivity will skyrocket, I guarantee it.

Update #1: By the way, as duly noted in the comments, all of these tricks work on the mysql command line, so you can, for example, ctrl-R through your previously executed mysql commands.

Update #2: In response to a few people saying this list is too short and “[he] could've added something to it, to atleast make it look longer” (quote from one of Stumbleupon reviewers), I want to clarify something. I deliberately did not include every single bash shortcut there is. I included what I personally thought were the best and most useful commands. I did not want to make the list too cluttered and wanted the cheat sheet to fit on one page without going to a smaller font size.

Update #3: For all the WP-Greetbox haters out there (apparently there are a few), please don’t mix hating content with hating the greeting. A few stumblers seem to be annoyed at the plugin (written by my good friend Thaya btw) but I frankly don’t see how this justifies such negativity. /vent

Without further ado (see bottom of the page for cheat sheet download links):


Keyboard shortcut

Action

Navigation

ctrl-A Go to the beginning of the line (note that if you use GNU screen, you can use the Home button to do this, especially considering that ctrl-A is a special control character in screen).
ctrl-E Go to the end of the line (note that if you use GNU screen, you can use the End button to do this).
alt-B or esc, left arrow Jump back one word*.
alt-F or esc, right arrow Jump forward one word*.
Ctrl-PgUp or Shift-PgUp This may or may not work, and it works differently on different console apps. It will either scroll up one line at a time, 1 page at a time, or it may not work at all. I'm inclined to think it's not a bash shortcut at all.
Ctrl-PgDn or Shift-PgDn Same as the above but scrolling is done in the opposite direction.
Up/Down Previous/Next command in history. This one is way too obvious but I'm including it for completeness.

Command Line Manipulation

ctrl-W Cut to the previous white space (one word*).
alt-backspace Cut to the previous non-alphanumeric character (different from ctrl-W, for example, abc;bcd will cut to abc;).
ctrl-K Cut everything to the end of the line.
ctrl-U Cut everything to the beginning of the line.
ctrl-T Flip the current character with the previous one. I almost never use this. Never mind, I never use it, but someone might find it useful.
ctrl-Y Paste whatever was cut by the last cut command.
ctrl-V Insert the next character literally. For example, Ctrl-V TAB inserts the actual TAB character. This shortcut is often misunderstood because of mistyping ctrl-V and not realizing what it does.

Terminal control

ctrl-L Clear screen while keeping whatever is already typed in the command line intact.
ctrl-S Suspend currently running terminal.
ctrl-Q Unsuspend the terminal suspended by ctrl-S. You need to be aware of this shortcut because 99% of the time you’ve accidentally pressed ctrl-S and need to undo its effects.
ctrl-R History search. For example, ctrl-R svn ctrl-R ctrl-R … will cycle through all recently run commands with the ‘svn’ in them. It is one of the most useful shortcuts in bash.
ctrl-Z Suspend the currently running process (usually followed by bg to resume it in the background or fg to resume in the foreground).
TAB Autocomplete. Start typing, then hit TAB. You will either get a list of possible completion values (2 TABs needed) or the only choice will be filled in (only 1 TAB is needed). This shortcut is quite obvious and well known, so I put it at the bottom of the list.

* Note that a word seems to be defined as a series of alphanumeric characters, so deleting one word would delete to the next non-alphanumeric character.

Hope you guys will find this list helpful. I think it is relatively complete, but feel free to add any omissions. I’m also considering making it into a PDF cheat sheet. Here are the cheat sheets I made:

 image 

Version 1.11 (12/24/08):

Edit #1: There’s a nice visual cheat sheet here: http://www.jamesconner.us/images/bash_sheet.png but I find it too busy and complicated.

Edit #2: A decent tutorial style bash guide here: http://www.hypexr.org/bash_tutorial.php.

Similar Posts:

Share/Save/Bookmark

MySQL: Planet MySQL

Mastering The Linux Shell - Bash Shortcuts Explained

image During my day-to-day activities, I use the Bash shell a lot. My #1 policy is to optimize the most frequently used activities as much as possible, so I’ve compiled this handy bash shortcuts and hints (tested in SecureCRT on Windows and Konsole on Linux). It only touches on the default bash mode – emacs, not vi. If you haven’t specifically assigned your shell mode to vi (set –o vi), you’re almost certainly using the emacs mode. Learn these and your shell productivity will skyrocket, I guarantee it.

Without further ado:


Keyboard shortcut

Action

Navigation

ctrl-A Go to the beginning of the line (note that if you use GNU screen, you can use the Home button to do this, especially considering that ctrl-a is a special control character in screen).
ctrl-E Go to the end of the line (note that if you use GNU screen, you can use the End button to do this).
alt-B or esc, left arrow Jump back one word*.
alt-F or esc, right arrow Jump forward one word*.
Ctrl-PgUp or Shift-PgUp This may or may not work, and it works differently on different console apps. It will either scroll up one line at a time, 1 page at a time, or it may not work at all. I'm inclined to think it's not a bash shortcut at all.
Ctrl-PgDn or Shift-PgDn Same as the above but scrolling is done in the opposite direction.
Up/Down Previous/Next command in history. This one is way too obvious but I'm including it for completeness.

Command Line Manipulation

ctrl-W Cut to the previous white space (one word*).
alt-backspace Cut to the previous non-alphanumeric character (different from ctrl-w, for example, abc;bcd will cut to abc;).
ctrl-K Cut everything to the end of the line.
ctrl-U Cut everything to the beginning of the line.
ctrl-T Flip the current character with the previous one. I almost never use this. Never mind, I never use it, but someone might find it useful.
ctrl-Y Paste whatever was cut by the last cut command.
ctrl-V Insert the next character literally. For example, Ctrl-V TAB inserts the actual TAB character. This shortcut is often misunderstood because of mistyping ctrl-V and not realizing what it does.

Terminal control

ctrl-L Clear screen while keeping whatever is already typed in the command line intact.
ctrl-S Suspend currently running terminal.
ctrl-Q Unsuspend the terminal suspended by ctrl-s. You need to be aware of this shortcut because 99% of the time you’ve accidentally pressed ctrl-s and need to undo its effects.
ctrl-R History search. For example, ctrl-r svn ctrl-r ctrl-r … will cycle through all recently run commands with the word ‘svn’ in them. This is one of the most useful shortcuts in bash.
TAB Autocomplete. Start typing something, then hit TAB. You will either get a list of possible completion values (2 TABs needed) or the only choice will be filled in (only 1 TAB is needed). This shortcut is quite obvious and well known, so I put it at the bottom of the list.

* Note that a word seems to be defined as a series of alphanumeric characters, so deleting one word would delete to the next non-alphanumeric character.

Hope you guys will find this list helpful. I think it is relatively complete, but feel free to add any omissions. I’m also considering making it into a PDF cheat sheet.

Edit: There’s a nice visual cheat sheet here: http://www.jamesconner.us/images/bash_sheet.png but I find it too busy and complicated.

Edit #2: A decent tutorial style bash guide here: http://www.hypexr.org/bash_tutorial.php.

Similar Posts:

MySQL: Planet MySQL

Getting Around Bash – Bash Shortcuts

During my day-to-day activities, I use the Bash shell a lot. My #1 policy is to optimize the most frequently used activities as much as possible, so I’ve compiled this handy bash shortcuts and hints (tested in SecureCRT on Windows and Konsole on Linux). It only touches on the default bash mode – emacs, not vi. If you haven’t specifically assigned your shell mode to vi (set –o vi), you’re almost certainly using the emacs mode. Learn these and your shell productivity will skyrocket, I guarantee it.

Without further ado:


Keyboard shortcut

Action

Navigation

ctrl-A Go to the beginning of the line (note that if you use GNU screen, you can use the Home button to do this, especially considering that ctrl-a is a special control character in screen).
ctrl-E Go to the end of the line (note that if you use GNU screen, you can use the End button to do this).
alt-B or esc, left arrow Jump back one word*.
alt-F or esc, right arrow Jump forward one word*.
Ctrl-PgUp or Shift-PgUp This may or may not work, and it works differently on different console apps. It will either scroll up one line at a time, 1 page at a time, or it may not work at all. I'm inclined to think it's not a bash shortcut at all.
Ctrl-PgDn or Shift-PgDn Same as the above but scrolling is done in the opposite direction.
Up/Down Previous/Next command in history. This one is way too obvious but I'm including it for completeness.

Command Line Manipulation

ctrl-W Cut to the previous white space (one word*).
alt-backspace Cut to the previous non-alphanumeric character (different from ctrl-w, for example, abc;bcd will cut to abc;).
ctrl-K Cut everything to the end of the line.
ctrl-U Cut everything to the beginning of the line.
ctrl-T Flip the current character with the previous one. I almost never use this. Never mind, I never use it, but someone might find it useful.
ctrl-Y Paste whatever was cut by the last cut command.
ctrl-V Insert the next character literally. For example, Ctrl-V TAB inserts the actual TAB character. This shortcut is often misunderstood because of mistyping ctrl-V and not realizing what it does.

Terminal control

ctrl-L Clear screen while keeping whatever is already typed in the command line intact.
ctrl-S Suspend currently running terminal.
ctrl-Q Unsuspend the terminal suspended by ctrl-s. You need to be aware of this shortcut because 99% of the time you’ve accidentally pressed ctrl-s and need to undo its effects.
ctrl-R History search. For example, ctrl-r svn ctrl-r ctrl-r … will cycle through all recently run commands with the word ‘svn’ in them. This is one of the most useful shortcuts in bash.
TAB Autocomplete. Start typing something, then hit TAB. You will either get a list of possible completion values (2 TABs needed) or the only choice will be filled in (only 1 TAB is needed). This shortcut is quite obvious and well known, so I put it at the bottom of the list.

* Note that a word seems to be defined as a series of alphanumeric characters, so deleting one word would delete to the next non-alphanumeric character.

Hope you guys will find this list helpful. I think it is relatively complete, but feel free to add any omissions. I’m also considering making it into a PDF cheat sheet.

Similar Posts:

MySQL: Planet MySQL

BASH with Debugger and Improved Debug Support and Error Handling

The Bash Debugger Project contains the most comprehensive source-code debugger for bash that has been written.

User:daveg: del.icio.us/daveg

Git Utilities You Can't Live Without

Completion, custom prompt and rake tasks

git: del.icio.us tag/git

rtomayko's git-sh at master — GitHub

"A customized bash environment suitable for git work."

git: del.icio.us tag/git

Git Utilities You Can't Live Without - bitfluent

Dude, seriously. All that switching around, fetching, rebasing, merging? I bet only Linus Torvalds remembers the whole sequence off the top of his head.

git: del.icio.us tag/git

git-sh

A customized bash environment suitable for git work.

git: del.icio.us tag/git

On Searching " philiKON - a journal

Use bash’s ability to search the command history when repetitively using commands on the command line. Don’t bother hitting the Up key for a 100 times, trying to find that hugely complicated command you typed in two hours ago. Hit Ctrl+R, start typing parts of the command and it’ll appear as you type. Didn’t know this feature yet? Ain’t it cool? Will it save you time? Maybe. Will it save you much aggrevation? Quite probably.

Emacs: del.icio.us tag/emacs

Es: A shell with higher-order functions

"...led us to wonder whether a more general approach to the design of shells was possible, and this paper describes the result of that experimentation. "

plan9: del.icio.us/tag/plan9

Various Bash Scripts

Including at least one that uses docstrings, and one that is object oriented!

opensource: del.icio.us tag/opensource

KoanLogic Srl - embedded software engineering

MaKL is a simple and light framework for building multi-platform C projects, purely based on the Bourne Shell and GNU Make. Ideal for embedded systems due to its cross-compilation, multiplatform toolchaining mechanisms, and minimal external dependencies

opensource: del.icio.us tag/opensource

Emacs - Cygwin Customizations

Nice reference for setting up emacs to work with cygwin, also other good info.

Emacs: del.icio.us tag/emacs

Bash Emacs Editing Mode Cheat Sheet

Usando el modo edición de Emacs en la shell Bash

Emacs: del.icio.us tag/emacs

Git Utilities You Can't Live Without - bitfluent

git-completion, git-ps1, git rake task

git: del.icio.us tag/git

Page 1 | Next >>
All original text is available as Creative Commons Attribution-ShareAlike
Privacy. Terms. Credits. π