Junyangz's docs
  • Introduction
  • Ops
    • Linux-tips
    • MySQL-5.7.20
    • Upgrading MySQL
    • Upgrade OpenSSH to 7.7p1 in CentOS 6
    • Linux PERSISTENT NAMING
    • Use Kafka with Flume - CRS2
    • Setup Chroot SFTP in CentOS
    • Setup software RAID-5 in CentOS
    • SSH-port-forwarding
    • Elasticsearch In Production
    • ELK-simple-tutorial
    • Ansible Playbooks for Apache Kafka in production
    • GitHub Actions depoly Hexo
    • Test HTTP3/QUIC docker
    • Docker tutorial
    • SFTP-auth-pubkey
    • Linux Process Substitution
  • Note
    • Interview
      • interview-prepare
      • 2020-campus-recruiting
    • Android Tips
    • MacOS tips
    • Secret knowledge
    • GPG-Note
    • ud185
    • ud185-2
    • Introducing Tensorflow Federated
    • Tensorflow Federated
    • Expert Python Programing
    • What happens when zh_CN
    • TILGC
    • VScode keyboard shortcuts
    • Abseil Python
    • Latex Note
    • Git Cheatsheet
    • Study Smarter Not Harder
    • Machine Learning Interviews
    • 深度学习中的优化
    • Beej's Guide to Network Programming Note
      • ch4
      • ch5
      • ch6
      • ch7
  • [Share]
    • What to do after what to do
    • Truman is everywhere
    • Way2outer
    • 未来十五年
  • Quote
Powered by GitBook
On this page

Was this helpful?

  1. Ops

Linux-tips

Last updated: 2023-02-23

# sudo no password
echo "$(whoami)" ALL=(ALL) NOPASSWD:ALL >> /etc/sudoers
# copy ssh keys
ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
ssh-copy-id -f -i ~/.ssh/id_rsa.pub user@host # force add without checking if key exists
# not fancy way
ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

VIM

# delete a world: `daw`
# delete a sentence: `das`
#  __d__elete, __y__ank, __c__hange, > (indent in)
# b for before, e for end, a for append, i for insert.
# caw - perform the c operator on the aw text object (ergo, change the "a word" that the cursor is currently on).
# dd for delete line, yy for copy line, cc for change line
# >> for align line right, << for align line left
# :%s/old/new/g for replace all
# :%s/old/new/gc for replace all with confirm
# :%s/old/new/gcI for replace all with confirm and ignore case
# BdW (go to first whitespace delete to next whitespace)
# bdw, back delete word.
# Scroll: Ctrl-u (up), Ctrl-d (down)
# Find: f{character}, t{character}, F{character}, T{character}
# find/to forward/backward {character} on the current line
# , / ; for navigating matches
# Search: /{regex}, n / N for navigating matches
# %s/foo/bar/g replace foo with bar globally in file
# To switch to the right window, press “Ctrl + w”, then “l”. To go to the left window, it's “Ctrl + w”, then “h”. If you did a horizontal split, then going up and down is necessary. For going up, press “Ctrl + w”, then “k”. For going down, press “Ctrl + w”, then “j”.
# set :nu for line numbers

BASH

# $_ - Last argument from the last command
# $! - PID of the last background command
# $@ - All arguments
# $* - All arguments, unquoted
# $? - Exit status of the last command
# $$ - PID of the current shell
# $0 - Name of the current script
# $# - Number of arguments passed to script
# !! - Entire last command, including arguments. A common pattern is to execute a command only for it to fail due to missing permissions; you can quickly re-execute the command with sudo by doing sudo !!
# ESC . - last argument from the previous command
# !:n - nth argument from the previous command
bash -c 'cat < "TEST"'
#bash: TEST: No such file or directory means that the shell is trying to read from a file called TEST
bash -c 'cat << "TEST"'
#bash: warning: here-document at line 0 delimited by end-of-file (wanted `TEST') means that the shell is trying to read from here-document 
bash -c 'cat <<< "TEST"'
#TEST means that the shell is trying to read from here-string
# process substitution
# <(command) - read from the output of command
# >(command) - write to the input of command
# bash coproc (> bash 4.0)
# coproc NAME { command; }
# $NAME_PID - PID of the coprocess
# ${NAME[@]} - file descriptor of the coprocess
# ${NAME[0]} - ouput file descriptor of the coprocess
# ${NAME[1]} - input file descriptor of the coprocess

set -e
set -x

coproc macaroons (echo $(date))

echo "The coprocess array: ${macaroons[@]}"
echo "The PID of the coprocess is ${macaroons_PID}"
# Read the output off the first file descriptor of the array.                                                                                
read -r output <&"${macaroons[0]}" # read -r -u "${macaroons[0]}" output
echo "The output of the coprocess is ${output}"
# https://copyconstruct.medium.com/bash-coprocess-2092a93ad912
PreviousOpsNextMySQL-5.7.20

Last updated 2 years ago

Was this helpful?