linuxdot.org Linux Expo Birmingham 2002
Linux news | Newbie's Linux manual | Linux links | Link us
The Linux columns | Book reviews
  DistroWatch + TuxReports October 28, 2002

Contents | Previous | Next | Download

The command history and other shell tricks

Press the up and down cursor keys to move through your command history, and press Enter to run the command.

Note:

What you're actually looking at is the line-by-line contents of your ~/.bash_history file. All the commands you entered during a session will be appended to this file each time you log-out.


$ history

history
Display your entire command history.


history | less
Display your entire command history in the less program.


history 4
Display the last four commands you entered.


!ls
Re-run the last command that started with: ls

Intermediate tip:

Instead you could press Ctrl+R for the more powerful reverse incremental search, which builds the search string as you type.


!16
Re-run the command with the ID 16, i.e. the 16th line in your ~/.bash_history file.


history | grep home
List the commands from your command history containing the string, 'home'.


Other shell tricks

Press the Tab key where a filename or directoryname is expected, to have the bash shell attempt to complete the filename or directoryname. (Referred to as tab completion.) If the computer beeps, press the Tab key again to list all possibilities.

Note:

If it's not clear to the shell that you want a filename or directoryname completed, for example, by typing rm at the start of the command-line and pressing the Tab key, the shell will attempt to complete a filename from your path. This can be useful for displaying the commands that begin with a particular string. (See Environment variables chapter for explanation of your path.)


Press Ctrl+Page Up or Ctrl+Page Down to scroll back and forward half a screen, respectively.


Press Ctrl+U to clear the input line.


Press Ctrl+A or Ctrl+E to move to the start and end of the input line, respectively.


Press Ctrl+T (transpose), to have the two characters before the cursor switch places (if no character is under the cursor), or the character under the cursor and the previous character. Used to correct typos.


Separate commands with a semi-colon (;), to enter multiple commands in one go, e.g.:

clear; ls -alh


If a filename has a space in it, either enclose the path in single or double quotes or escape each space with a backslash, e.g.:

cd 'work/my reports'
cd "work/my reports"
cd work/my\ reports

Contents | Previous | Next | Download

About us  
Latest stable kernel: 2.4.19 | Latest development kernel: 2.5.44
Copyright © 1998-2002 Linuxdot.org.
Linux ® is a registered trademark of Linus Torvalds.