mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2025-02-16 15:22:44 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
ce835189f9
32
README.md
32
README.md
@ -43,6 +43,8 @@ Ctrl + d : if you've type something, Ctrl + d deletes the character under the cu
|
|||||||
Ctrl + k : delete all text from the cursor to the end of line.
|
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 + 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 + 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 + 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 + x + Ctrl + e : launch editor define by $EDITOR
|
Ctrl + x + Ctrl + e : launch editor define by $EDITOR
|
||||||
```
|
```
|
||||||
##### Change case
|
##### Change case
|
||||||
@ -50,7 +52,7 @@ Ctrl + x + Ctrl + e : launch editor define by $EDITOR
|
|||||||
Esc + u
|
Esc + u
|
||||||
# converts text from cursor to the end of the word to uppercase.
|
# converts text from cursor to the end of the word to uppercase.
|
||||||
Esc + l
|
Esc + l
|
||||||
# converts text from cursor to the end of the word to uppercase.
|
# converts text from cursor to the end of the word to case.
|
||||||
Esc + c
|
Esc + c
|
||||||
# converts letter under the cursor to uppercase.
|
# converts letter under the cursor to uppercase.
|
||||||
```
|
```
|
||||||
@ -874,7 +876,7 @@ find . -type d
|
|||||||
##### Edit all files under current directory (e.g. replace 'www' with 'ww')
|
##### Edit all files under current directory (e.g. replace 'www' with 'ww')
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
find . name '*.php' -exec sed -i 's/www/w/g' {} \;
|
find . -name '*.php' -exec sed -i 's/www/w/g' {} \;
|
||||||
```
|
```
|
||||||
if no subdirectory
|
if no subdirectory
|
||||||
|
|
||||||
@ -941,7 +943,7 @@ if ((x >= 5)); then …
|
|||||||
if ((j==u+2))
|
if ((j==u+2))
|
||||||
|
|
||||||
# Use [[ ]] for comparison
|
# Use [[ ]] for comparison
|
||||||
if [[$age >21]]
|
if [[ $age -gt 21 ]]
|
||||||
```
|
```
|
||||||
|
|
||||||
[More if commands](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html)
|
[More if commands](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html)
|
||||||
@ -1015,9 +1017,13 @@ echo ${#var}
|
|||||||
```
|
```
|
||||||
##### get the first character of the variable
|
##### get the first character of the variable
|
||||||
```bash
|
```bash
|
||||||
var="some string"
|
var=string
|
||||||
|
echo "${var:0:1}"
|
||||||
|
#s
|
||||||
|
|
||||||
|
#or
|
||||||
echo ${var%%"${var#?}"}
|
echo ${var%%"${var#?}"}
|
||||||
#s
|
|
||||||
```
|
```
|
||||||
##### remove the first or last string from variable
|
##### remove the first or last string from variable
|
||||||
```bash
|
```bash
|
||||||
@ -1193,7 +1199,7 @@ curl https://transfer.sh/tG8rM/filename.txt -o filename.txt
|
|||||||
```bash
|
```bash
|
||||||
data=file.txt
|
data=file.txt
|
||||||
url=http://www.example.com/$data
|
url=http://www.example.com/$data
|
||||||
if [! -s $data];then
|
if [ ! -s $data ];then
|
||||||
echo "downloading test data..."
|
echo "downloading test data..."
|
||||||
wget $url
|
wget $url
|
||||||
fi
|
fi
|
||||||
@ -1488,7 +1494,13 @@ cp -rp /path/to/directory
|
|||||||
##### Store current directory
|
##### Store current directory
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pushd . $popd ;dirs -l
|
pushd .
|
||||||
|
|
||||||
|
# then pop
|
||||||
|
popd
|
||||||
|
|
||||||
|
#or use dirs to display the list of currently remembered directories.
|
||||||
|
dirs -l
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Show disk usage
|
##### Show disk usage
|
||||||
@ -2484,6 +2496,12 @@ echo -e ' \t '
|
|||||||
|
|
||||||
##### Array
|
##### Array
|
||||||
```bash
|
```bash
|
||||||
|
declare -a array=()
|
||||||
|
|
||||||
|
#or
|
||||||
|
declare array=()
|
||||||
|
|
||||||
|
#or associative array
|
||||||
declare -A array=()
|
declare -A array=()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user