You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
4 years ago | |
|---|---|---|
| .. | ||
| README.md | 5 years ago | |
| misc.md | 4 years ago | |
| shell-script.md | 5 years ago | |
| systemctl.md | 5 years ago | |
README.md
Useful shell command
- commands
// add a user to root group
$ visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
newuser ALL=(ALL:ALL)ALL
hold `ctrl` and press `x` to save and exit
// list all running process
$ ps aux
- run as root
user@host$ sudo su -
// prompt will show root login
root@host$
- add a user to a group
// create docker group
$ sudo groupadd docker
// add current user to group
$ sudo usermod -aG docker ${USER}
// restart to take effect
- change file permission
// excecute, read, write
$ chmod 777 filename
// made executable
$ chmod +x envtest.sh
node version manager nvm
- For proper installing, using version manager for nodejs to install nodejs/npm
- use nvm
- to avoid npm version conflict installation with nodejs
- to install / switch to lower / newer version on any version ubuntu
- ubuntu 20.10 default support node 12
- ubuntu 19.10 default support node 10
// installation
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
$ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
# This loads nvm
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
// to install node version 10.10.0
$ nvm install 10.10.0
// remove node to solve conflicting version
$ sudo apt-get remove nodejs
$ sudo apt autoremove
- ssh id
$ ssh-keygen
// copy ssh public key to host .ssh/authorized_keys to allow passwordless ssh
$ ssh-copy-id -i abc@host
// alternatively, copy local .ssh/rsa_id.pub content into target server authorized_keys
- environments
// add global variable
// method1 : cli
$ export VARNAME="value"
$ set VARNAME="Value"
// add local variable
$ VARNAME=Value
// remove
$ unset VARNAME
$ VARNAME=''
// user wide env
$ sudo vi ~/.bashrc
..
export NAME=Value
...
// system wide ENV file
$ nano /etc/environment
// reload a file
$ source /etc/bash.bashrc
// show a variable
$ echo $VARNAME
// show all variables
$ printenv | sort | less
$ env | grep GNOME
$ myvar=(first second third)
$ echo ${myvar[2]}
third
$ echo ${myvar[*]}
first second third
-
startup file execution order from login shell
/etc/profile$HOME/.bash_login$HOME/.bash_profile$HOME/.profile
-
startup file from interactive shell
.bashrcinstead of/etc/profile
Rebuild HOME
-
Repair fstab
// find the new UUID $ blkid // update the UUID $ nano /etc/fstab -
login as su
$ sudo su // $ mkhomedir_helper <username>