Repeating an argumentYou can repeat the last argument of the previous command in multiple ways. Have a look at this example:
$ mkdir /path/to/dir
$ cd !$
The second command might look a little strange, but it will just cd to /path/to/dir.
Some keyboard shortcuts for editing
There are some pretty useful keyboard shortcuts for editing in bash. They might appear familiar to Emacs users:
• Ctrl + a => Return to the start of the command you're typing
• Ctrl + e => Go to the end of the command you're typing
• Ctrl + u => Cut everything before the cursor to a special clipboard
• Ctrl + k => Cut everything after the cursor to a special clipboard
• Ctrl + y => Paste from the special clipboard that Ctrl + u and Ctrl + k save their data to
• Ctrl + t => Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
• Ctrl + w => Delete the word / argument left of the cursor
• Ctrl + l => Clear the screen
Redirecting both Standard Output and Standard Error:
# ls -ltR 2>&1 > /tmp/temp.txt
Specify this in .bashrc
Make Bash append rather than overwrite the history on disk:
# shopt -s histappend
Whenever displaying the prompt, write the previous line to disk:
# export PROMPT_COMMAND=’history -a’
To erase duplicate entries in History.
# export HISTCONTROL=erasedups
(or)
# export HISTCONTROL=ignoreboth
To see the history with timestamps
# export HISTTIMEFORMAT="%d/%m/%Y-%H:%M:%S "
To set the Size of the historyHISTSIZE: The number of commands to remember in the command history. The default value is 500.
# export HISTSIZE=500
Searching the Past
$ mkdir /path/to/dir
$ cd !$
The second command might look a little strange, but it will just cd to /path/to/dir.
Some keyboard shortcuts for editing
There are some pretty useful keyboard shortcuts for editing in bash. They might appear familiar to Emacs users:
• Ctrl + a => Return to the start of the command you're typing
• Ctrl + e => Go to the end of the command you're typing
• Ctrl + u => Cut everything before the cursor to a special clipboard
• Ctrl + k => Cut everything after the cursor to a special clipboard
• Ctrl + y => Paste from the special clipboard that Ctrl + u and Ctrl + k save their data to
• Ctrl + t => Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
• Ctrl + w => Delete the word / argument left of the cursor
• Ctrl + l => Clear the screen
Redirecting both Standard Output and Standard Error:
# ls -ltR 2>&1 > /tmp/temp.txt
Specify this in .bashrc
Make Bash append rather than overwrite the history on disk:
# shopt -s histappend
Whenever displaying the prompt, write the previous line to disk:
# export PROMPT_COMMAND=’history -a’
To erase duplicate entries in History.
# export HISTCONTROL=erasedups
(or)
# export HISTCONTROL=ignoreboth
To see the history with timestamps
# export HISTTIMEFORMAT="%d/%m/%Y-%H:%M:%S "
To set the Size of the historyHISTSIZE: The number of commands to remember in the command history. The default value is 500.
# export HISTSIZE=500
Searching the Past
- Ctrl+R searches previous lines
- !tcp will execute the previous command which starts with "tcp"