byobu

Byobu with tmux back end To start a new Byobu session with a specified name:

byobu new -s <session-name>

To change the name of a pre-existing session:

byobu rename -t <session-name> <new-session-name>

bash cheat sheet

One of the most popular shells, bash - Bourne Again SHell, uses GNU’s Readline library for reading the command line. Both emacs and vi editing modes are available.

For the default, emacs, editing mode in bash (also available in most text input places, eg. : location bar in the browser, text field in the webpage):

Moving

  • Ctrl + A: move to the beginning of the line
  • Ctrl + E: move to the end of the line
  • Alt + B: move back one word
  • Alt + F: move forward one word
  • Ctrl+ XX: toggle between first and current position

Delete/Cut/Paste

  • Ctrl + U: delete to the beginning of the line
  • Ctrl + K: delete to the end of the line
  • Ctrl + W: delete the last word
  • Ctrl + Y: paste the last deleted command

Util

  • Ctrl + _: undo
  • Ctrl + C: cancel the current command/line
  • Ctrl + L: clear the terminal
  • Ctrl + N: Next command from the History
  • Ctrl + P: previous command from the History

Search

  • Ctrl + R: search command in history - type the search term
  • Ctrl + J: end the search at current history entry
  • Ctrl + G: cancel the search and restore original line

http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-sheet/

linux command cheat sheet

curl

post json using curl

curl -H "token: YOUR_TOKEN" \
-H "Content-Type: application/json" \
--request POST --data '{"top_count": 5, "days": 7}' \
"http://YOUR_IP/detect/v1/top_pkg/"

pbcopy/pbpaste: copy/paste lines

Use “pbcopy” to copy content of file to your clipboard. For example:

$ pbcopy < file.txt

or

cat file.txt | pbcopy

iptables

add to top:
sudo iptables -I INPUT 1 -i lo -j ACCEPT
allow a port:
sudo iptables -A INPUT -p tcp --dport 8880 -j ACCEPT

add group

sudo groupadd docker

add user to group

sudo usermod -aG docker $USER

ln -s /path/to/file /path/to/symlinksudo
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

delete first 3 lines from file

sed -i ‘1,3d’ file.txt

Could not open a connection to your authentication agent

eval ssh-agent -s

ssh remote port forwarding

ssh -nNT -L 9000:ifconfig.me:80 mords

ubuntu set default editor

sudo update-alternatives --config editor

find and delete files

find . -name "*.pyc" -delete

add BOM to UTF-8 files

many programs will have trouble reading UTF-8 text files if they don’t have a BOM.

printf '\xEF\xBB\xBF' | cat - source.txt > source-with-bom.txt

The cat - bit says to concatenate to the front of source.txt what’s being piped in from the print command.

Enable or Disable Service

CentOS 7 or Ubuntu 16.06

systemd is a system and service manager for Linux operating systems. It is now used by default in most Linux distributions and is fully supported in Ubuntu-15.04 and later releases. It goes with systemctl command line tool, that among the other things, can enable and disable services at boot time.

Check if service is enabled or disabled on startup:

sudo systemctl is-enabled SERVICE

Enable/Disable service autostart:

sudo systemctl enable/disable SERVICE

CentOS 6

Check if service is enabled or disabled on startup:

sudo chkconfig --list | grep SERVICE

Enable/Disable service autostart:

chkconfig SERVICE on/off

快捷操作:ssh登录远端执行命令并返回

有的时候我们需要ssh到远端机器,执行一个脚本,然后退出。 此时,通常需要三步:

ssh remote-machine
./run_some_script.sh
exit

並不算很麻烦,但是其实可以一条命令完成这些操作:

ssh remote-machine < ./run_some_script.sh

这样就可以在远端机器执行完命令后自然回到本地terminal。 以上这条命名使用了IO redirect, 要求run_some_script.sh这个文件在本地. 要是执行远程机器上的脚本呢?

ssh remote-machine ./run_some_script.sh

直接接命令就可以了.