mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2024-11-22 12:57:01 +00:00
add command to 'system' section
printing last reboot history
This commit is contained in:
parent
b26a489a1a
commit
3ca70751ab
41
README.md
41
README.md
@ -195,7 +195,7 @@ grep -o 'S.*'
|
|||||||
grep -o -P '(?<=w1).*(?=w2)'
|
grep -o -P '(?<=w1).*(?=w2)'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Grep lines without word (e.g. bbo)
|
##### Grep lines without word (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -v bbo filename
|
grep -v bbo filename
|
||||||
```
|
```
|
||||||
@ -205,18 +205,18 @@ grep -v bbo filename
|
|||||||
grep -v '^#' file.txt
|
grep -v '^#' file.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Grep variables with space within it (e.g. bbo="some strings")
|
##### Grep variables with space within it (e.g. myvar="some strings")
|
||||||
```bash
|
```bash
|
||||||
grep "$boo" filename
|
grep "$myvar" filename
|
||||||
#remember to quote the variable!
|
#remember to quote the variable!
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Grep only one/first match (e.g. bbo)
|
##### Grep only one/first match (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -m 1 bbo filename
|
grep -m 1 bbo filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Grep and return number of matching line(e.g. bbo)
|
##### Grep and return number of matching line(e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -c bbo filename
|
grep -c bbo filename
|
||||||
```
|
```
|
||||||
@ -226,29 +226,29 @@ grep -c bbo filename
|
|||||||
grep -o bbo filename |wc -l
|
grep -o bbo filename |wc -l
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Case insensitive grep (e.g. bbo/BBO/Bbo)
|
##### Case insensitive grep (e.g. 'bbo'/'BBO'/'Bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -i "bbo" filename
|
grep -i "bbo" filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### COLOR the match (e.g. bbo)!
|
##### COLOR the match (e.g. 'bbo')!
|
||||||
```bash
|
```bash
|
||||||
grep --color bbo filename
|
grep --color bbo filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Grep search all files in a directory(e.g. bbo)
|
##### Grep search all files in a directory(e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -R bbo /path/to/directory
|
grep -R bbo /path/to/directory
|
||||||
# or
|
# or
|
||||||
grep -r bbo /path/to/directory
|
grep -r bbo /path/to/directory
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Search all files in directory, do not ouput the filenames (e.g. bbo)
|
##### Search all files in directory, do not ouput the filenames (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -rh bbo /path/to/directory
|
grep -rh bbo /path/to/directory
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Search all files in directory, output ONLY the filenames with matches(e.g. bbo)
|
##### Search all files in directory, output ONLY the filenames with matches(e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -rl bbo /path/to/directory
|
grep -rl bbo /path/to/directory
|
||||||
```
|
```
|
||||||
@ -302,7 +302,7 @@ grep -o -w "\w\{10\}\-R\w\{1\}"
|
|||||||
# \w word character [0-9a-zA-Z_] \W not word character
|
# \w word character [0-9a-zA-Z_] \W not word character
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Skip directory (e.g. bbo)
|
##### Skip directory (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
grep -d skip 'bbo' /path/to/files/*
|
grep -d skip 'bbo' /path/to/files/*
|
||||||
```
|
```
|
||||||
@ -321,7 +321,7 @@ sed 1d filename
|
|||||||
sed 1,100d filename
|
sed 1,100d filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Remove lines with string (e.g. bbo)
|
##### Remove lines with string (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
sed "/bbo/d" filename
|
sed "/bbo/d" filename
|
||||||
- case insensitive:
|
- case insensitive:
|
||||||
@ -334,10 +334,11 @@ sed -E '/^.{5}[^2]/d'
|
|||||||
#aaaa1aaa (delete!)
|
#aaaa1aaa (delete!)
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Edit infile (edit and save)
|
##### Edit infile (edit and save to file), (e.g. deleting the lines with 'bbo' and save to file)
|
||||||
```bash
|
```bash
|
||||||
sed -i "/bbo/d" filename
|
sed -i "/bbo/d" filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### When using variable (e.g. $i), use double quotes " "
|
##### When using variable (e.g. $i), use double quotes " "
|
||||||
```bash
|
```bash
|
||||||
# e.g. add >$i to the first line (to make a bioinformatics FASTA file)
|
# e.g. add >$i to the first line (to make a bioinformatics FASTA file)
|
||||||
@ -389,7 +390,7 @@ sed '$s/$/]/' filename
|
|||||||
sed '$a\'
|
sed '$a\'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Add string to beginning of every line (e.g. bbo)
|
##### Add string to beginning of every line (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
sed -e 's/^/bbo/' file
|
sed -e 's/^/bbo/' file
|
||||||
```
|
```
|
||||||
@ -419,11 +420,11 @@ sed 's/A/B/g' filename
|
|||||||
sed "s/aaa=.*/aaa=\/my\/new\/path/g"
|
sed "s/aaa=.*/aaa=\/my\/new\/path/g"
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Select lines start with string (e.g. bbo)
|
##### Select lines start with string (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
sed -n '/^@S/p'
|
sed -n '/^@S/p'
|
||||||
```
|
```
|
||||||
##### Delete lines with string (e.g. bbo)
|
##### Delete lines with string (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
sed '/bbo/d' filename
|
sed '/bbo/d' filename
|
||||||
```
|
```
|
||||||
@ -560,7 +561,7 @@ awk '$1~/,/ {print}'
|
|||||||
awk '{split($2, a,",");for (i in a) print $1"\t"a[i]}' filename
|
awk '{split($2, a,",");for (i in a) print $1"\t"a[i]}' filename
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Print all lines before nth occurrence of a string (e.g stop print lines when bbo appears 7 times)
|
##### Print all lines before nth occurrence of a string (e.g stop print lines when 'bbo' appears 7 times)
|
||||||
```bash
|
```bash
|
||||||
awk -v N=7 '{print}/bbo/&& --N<=0 {exit}'
|
awk -v N=7 '{print}/bbo/&& --N<=0 {exit}'
|
||||||
```
|
```
|
||||||
@ -575,7 +576,7 @@ ls|xargs -n1 -I file awk '{s=$0};END{print FILENAME,s}' file
|
|||||||
awk 'BEGIN{OFS="\t"}$3="chr"$3'
|
awk 'BEGIN{OFS="\t"}$3="chr"$3'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Remove lines with string (e.g. bbo)
|
##### Remove lines with string (e.g. 'bbo')
|
||||||
```bash
|
```bash
|
||||||
awk '!/bbo/' file
|
awk '!/bbo/' file
|
||||||
```
|
```
|
||||||
@ -1723,6 +1724,10 @@ ldd /bin/ls
|
|||||||
```bash
|
```bash
|
||||||
lastlog
|
lastlog
|
||||||
```
|
```
|
||||||
|
##### Check last reboot history
|
||||||
|
```bash
|
||||||
|
last reboot
|
||||||
|
```
|
||||||
|
|
||||||
##### Edit path for all users
|
##### Edit path for all users
|
||||||
```bash
|
```bash
|
||||||
|
Loading…
Reference in New Issue
Block a user