Compare commits

..

No commits in common. "3e6bbf7c2036ab6d3bca1cc72c0648d68960ff67" and "671c0eb16f2219a147d84814a885cd4831408531" have entirely different histories.

View File

@ -33,23 +33,22 @@ Here's a more stylish version of [Bash-Oneliner](https://onceupon.github.io/Bash
##### Using Ctrl keys ##### Using Ctrl keys
``` ```
Ctrl + a : move to the beginning of line.
Ctrl + d : if you've type something, Ctrl + d deletes the character under the cursor, else, it escapes the current shell.
Ctrl + e : move to the end of line.
Ctrl + k : delete all text from the cursor to the end of line.
Ctrl + l : equivalent to clear.
Ctrl + n : same as Down arrow. Ctrl + n : same as Down arrow.
Ctrl + p : same as Up arrow. Ctrl + p : same as Up arrow.
Ctrl + q : to resume output to terminal after Ctrl + s.
Ctrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward) Ctrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward)
Ctrl + s : to stop output to terminal. Ctrl + s : to stop output to terminal.
Ctrl + t : transpose the character before the cursor with the one under the cursor, press Esc + t to transposes the two words before the cursor. Ctrl + q : to resume output to terminal after Ctrl + s.
Ctrl + u : cut the line before the cursor; then Ctrl + y paste it Ctrl + a : move to the beginning of line.
Ctrl + w : cut the word before the cursor; then Ctrl + y paste it Ctrl + e : move to the end of line.
Ctrl + d : if you've type something, Ctrl + d deletes the character under the cursor, else, it escapes the current shell.
Ctrl + k : delete all text from the cursor to the end of line.
Ctrl + x + backspace : delete all text from the beginning of line to the cursor. Ctrl + x + backspace : delete all text from the beginning of line to the cursor.
Ctrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Useful for multi-line commands. Ctrl + t : transpose the character before the cursor with the one under the cursor, press Esc + t to transposes the two words before the cursor.
Ctrl + z : stop current running process and keep it in background. You can use `fg` to continue the process in the foreground, or `bg` to continue the process in the background. Ctrl + w : cut the word before the cursor; then Ctrl + y paste it
Ctrl + u : cut the line before the cursor; then Ctrl + y paste it
Ctrl + _ : undo typing. Ctrl + _ : undo typing.
Ctrl + l : equivalent to clear.
Ctrl + x + Ctrl + e : launch editor defined by $EDITOR to input your command. Useful for multi-line commands.
``` ```
##### Change case ##### Change case
```bash ```bash
@ -60,7 +59,6 @@ Esc + l
Esc + c Esc + c
# converts letter under the cursor to uppercase, rest of the word to lowercase. # converts letter under the cursor to uppercase, rest of the word to lowercase.
``` ```
##### Run history number (e.g. 53) ##### Run history number (e.g. 53)
```bash ```bash
!53 !53
@ -131,31 +129,6 @@ $USER current username
$HOSTNAME current hostname $HOSTNAME current hostname
``` ```
##### Using vi-mode in your shell
```bash
set -o vi
# change bash shell to vi mode
# then hit the Esc key to change to vi edit mode (when `set -o vi` is set)
k
# in vi edit mode - previous command
j
# in vi edit mode - next command
0
# in vi edit mode - beginning of the command
R
# in vi edit mode - replace current characters of command
2w
# in vi edit mode - next to 2nd word
b
# in vi edit mode - previous word
i
# in vi edit mode - go to insert mode
v
# in vi edit mode - edit current command in vi
man 3 readline
# man page for complete readline mapping
```
## Variable ## Variable
[[back to top](#handy-bash-one-liners)] [[back to top](#handy-bash-one-liners)]
##### Variable substitution within quotes ##### Variable substitution within quotes
@ -171,7 +144,7 @@ echo '$foo'
# single quotes within double quotes will not cancel expansion and will be part of the output # single quotes within double quotes will not cancel expansion and will be part of the output
echo "'$foo'" echo "'$foo'"
# 'bar' # 'bar'
# doubled single quotes act as if there are no quotes at all # doubled single quotes act as double quotes making variables expand
echo ''$foo'' echo ''$foo''
# bar # bar
``` ```
@ -2101,6 +2074,11 @@ killall pulseaudio
# then press Alt-F2 and type in pulseaudio # then press Alt-F2 and type in pulseaudio
``` ```
##### When sound not working
```bash
killall pulseaudio
```
##### List information about SCSI devices ##### List information about SCSI devices
```bash ```bash
lsscsi lsscsi
@ -3166,40 +3144,11 @@ rsync -av directory user@ip_address:/path/to/directory.bak
# skip files that are newer on receiver (i prefer this one!) # skip files that are newer on receiver (i prefer this one!)
``` ```
##### Create a temporary directory and `cd` into it
```bash
cd $(mktemp -d)
# for example, this will create a temporary directory "/tmp/tmp.TivmPLUXFT"
```
##### Make all directories at one time! ##### Make all directories at one time!
```bash ```bash
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat} mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat}
# -p: make parent directory # -p: make parent directory
# this will create: # this will create project/doc/html/; project/doc/info; project/lib/ext ,etc
# project/
# project/bin/
# project/demo/
# project/demo/stat/
# project/doc/
# project/doc/html/
# project/doc/info/
# project/doc/pdf/
# project/lib/
# project/lib/ext/
# project/src/
#
# project/
# ├── bin
# ├── demo
# │ └── stat
# ├── doc
# │ ├── html
# │ ├── info
# │ └── pdf
# ├── lib
# │ └── ext
# └── src
``` ```
##### Run command only if another command returns zero exit status (well done) ##### Run command only if another command returns zero exit status (well done)