mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2024-12-23 00:36:35 +00:00
commit
6b13a272d6
33
README.md
33
README.md
@ -1,5 +1,5 @@
|
||||
# Bash-Oneliner
|
||||
I am glad that you are here! I started working on bioinformatics a few years ago (recently switched to cloud computing), and was amazed by those single-word bash commands which are much faster than my dull scripts, time saved through learning command-line shortcuts and scripting. Not all the code here is oneliner, but i put effort on making them brief and swift. I am mainly using Ubuntu, RedHat and Linux Mint and CentOS, sorry if the commands dont work on your system.
|
||||
I am glad that you are here! I started working on bioinformatics a few years ago (recently switched to cloud computing), and was amazed by those single-word bash commands which are much faster than my dull scripts, time saved through learning command-line shortcuts and scripting. Not all the code here is oneliner, but i put effort on making them brief and swift. I am mainly using Ubuntu, RedHat and Linux Mint and CentOS, sorry if the commands don't work on your system.
|
||||
|
||||
This blog will focus on simple bash commands for parsing data and Linux system maintenance that i acquired from work and LPIC exam. I apologize that there are no detailed citation for all the commands, but they are probably from dear Google and Stackoverflow.
|
||||
|
||||
@ -34,8 +34,7 @@ Here's a more stylish version of [Bash-Oneliner](http://onceupon.github.io/Bash-
|
||||
```bash
|
||||
Ctrl + n : same as Down arrow.
|
||||
Ctrl + p : same as Up arrow.
|
||||
Ctrl + r : begins a backward search through cammand history.(keep pressing Ctrl + r to move backward)
|
||||
Ctrl + l : Clear the terminal
|
||||
Ctrl + r : begins a backward search through command history.(keep pressing Ctrl + r to move backward)
|
||||
Ctrl + s : to stop output to terminal.
|
||||
Ctrl + q : to resume output to terminal after Ctrl + s.
|
||||
Ctrl + a : move to the beginning of line.
|
||||
@ -158,7 +157,7 @@ grep -C 3 'bbo'
|
||||
grep -o 'S.*'
|
||||
```
|
||||
|
||||
##### Extract text bewteen words (e.g. w1,w2)
|
||||
##### Extract text between words (e.g. w1,w2)
|
||||
|
||||
```bash
|
||||
grep -o -P '(?<=w1).*(?=w2)'
|
||||
@ -582,7 +581,7 @@ awk '$1~/,/ {print}'
|
||||
awk '{split($2, a,",");for (i in a) print $1"\t"a[i]}' filename
|
||||
```
|
||||
|
||||
##### Print all lines before nth occurence 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
|
||||
awk -v N=7 '{print}/bbo/&& --N<=0 {exit}'
|
||||
@ -981,7 +980,7 @@ while read a b c; do echo $(($c-$b));done < <(head filename)
|
||||
# Sum up column subtraction
|
||||
i=0; while read a b c; do ((i+=$c-$b)); echo $i; done < <(head filename)
|
||||
|
||||
# Keep checking a running process (e.g. perl) and start another new process (e.g. python) immetiately after it. (BETTER use the wait command! Ctrl+F 'wait')
|
||||
# Keep checking a running process (e.g. perl) and start another new process (e.g. python) immediately after it. (BETTER use the wait command! Ctrl+F 'wait')
|
||||
while [[ $(pidof perl) ]];do echo f;sleep 10;done && python timetorunpython.py
|
||||
```
|
||||
|
||||
@ -1136,7 +1135,7 @@ TMOUT=10
|
||||
|
||||
##### Set how long you want to run a command
|
||||
```bash
|
||||
#This will run the commmand 'sleep 10' for only 1 second.
|
||||
#This will run the command 'sleep 10' for only 1 second.
|
||||
timeout 1 sleep 10
|
||||
```
|
||||
|
||||
@ -1370,7 +1369,7 @@ jobs -l
|
||||
export PATH=$PATH:~/path/you/want
|
||||
```
|
||||
|
||||
##### Make file execuable
|
||||
##### Make file executable
|
||||
|
||||
```bash
|
||||
chmod +x filename
|
||||
@ -1660,7 +1659,7 @@ quota -v username
|
||||
```
|
||||
|
||||
##### Fork bomb
|
||||
# dont try this at home
|
||||
# don't try this at home
|
||||
```bash
|
||||
:(){:|:&};:
|
||||
```
|
||||
@ -1698,7 +1697,7 @@ ulimit -u
|
||||
|
||||
```bash
|
||||
nmap -sT -O localhost
|
||||
#notice that some commpanies might not like you using nmap
|
||||
#notice that some companies might not like you using nmap
|
||||
```
|
||||
|
||||
##### Print out number of cores/ processors
|
||||
@ -1731,7 +1730,7 @@ shutdown -r +5 "Server will restart in 5 minutes. Please save your work."
|
||||
shutdown -c
|
||||
```
|
||||
|
||||
##### Boardcast to all users
|
||||
##### Broadcast to all users
|
||||
```bash
|
||||
wall -n hihi
|
||||
```
|
||||
@ -1908,7 +1907,7 @@ ssh -f -L 9000:targetservername:8088 root@192.168.14.72 -N
|
||||
#pidof
|
||||
pidof sublime_text
|
||||
|
||||
#pgrep, you dont have to type the whole program name
|
||||
#pgrep, you don't have to type the whole program name
|
||||
pgrep sublim
|
||||
|
||||
#top, takes longer time
|
||||
@ -1930,7 +1929,7 @@ top|grep sublime_text
|
||||
[ioblazer](https://labs.vmware.com/flings/ioblazer) - multi-platform storage stack micro-benchmark.
|
||||
[iozone](http://www.iozone.org/) - filesystem benchmark.
|
||||
[iperf3](https://iperf.fr/iperf-download.php) - measure TCP/UDP/SCTP performance.
|
||||
[kcbench](https://github.com/knurd/kcbench) - kernel compile benchmark, compiles a kernel and messures the time it takes.
|
||||
[kcbench](https://github.com/knurd/kcbench) - kernel compile benchmark, compiles a kernel and measures the time it takes.
|
||||
[lmbench](http://www.bitmover.com/lmbench/) - Suite of simple, portable benchmarks.
|
||||
[netperf](https://github.com/HewlettPackard/netperf) - measure network performance, test unidirectional throughput, and end-to-end latency.
|
||||
[netpipe](https://linux.die.net/man/1/netpipe) - network protocol independent performance evaluator.
|
||||
@ -2074,7 +2073,7 @@ ip a
|
||||
ip r
|
||||
```
|
||||
|
||||
##### Display ARP cache (ARP cache displays the MAC addresses of deveice in the same network that you have connected to)
|
||||
##### Display ARP cache (ARP cache displays the MAC addresses of device in the same network that you have connected to)
|
||||
```bash
|
||||
ip n
|
||||
```
|
||||
@ -2701,7 +2700,7 @@ example:
|
||||
q -d "," "select c3,c4,c5 from /path/to/file.txt where c3='foo' and c5='boo'"
|
||||
```
|
||||
|
||||
##### Sreen and tmux
|
||||
##### Screen and tmux
|
||||
create session and attach:
|
||||
```bash
|
||||
screen
|
||||
@ -2751,7 +2750,7 @@ or
|
||||
tmux kill-session -t foo
|
||||
```
|
||||
scroll:
|
||||
(screeen)
|
||||
(screen)
|
||||
Hit your screen prefix combination (C-a / control+A), then hit Escape.
|
||||
Move up/down with the arrow keys (↑ and ↓).
|
||||
|
||||
@ -2844,7 +2843,7 @@ tree
|
||||
```bash
|
||||
#1. install virtualenv.
|
||||
sudo apt-get install virtualenv
|
||||
#2. Creat a directory (name it .venv or whatever name your want) for your new shiny isolated environment.
|
||||
#2. Create a directory (name it .venv or whatever name your want) for your new shiny isolated environment.
|
||||
virtualenv .venv
|
||||
#3. source virtual bin
|
||||
source .venv/bin/activate
|
||||
|
Loading…
Reference in New Issue
Block a user