Skip to content

Instantly share code, notes, and snippets.

@kongliangzhong
Last active December 15, 2015 11:09
Show Gist options
  • Save kongliangzhong/5251195 to your computer and use it in GitHub Desktop.
Save kongliangzhong/5251195 to your computer and use it in GitHub Desktop.
linux-stuff
######### ubuntu linux #########
1) host file:
127.0.0.1 localhost
127.0.1.1 zhongkongliang-desktop
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
2) bash:
a) check exit code and exit. use if statement:
if [ $? -ne 0 ]; then ## notice the space between [ and $ .
exit 1
fi
3) display linux system info: uname -a
4) E: Unmet dependencies:
use: sudo apt-get --purge autoremove -f to remove uncomplete packages or reinstall them.
### System Manage:
1) find where a pakage is installed:
dpkg -l |grep name
dpkg -s pkgName
2) query package: rpm -q <pkg-name>
3) install rpm pakage in ubuntu:
try rpm -ivh my-pkg.rpm and get the following error msg:
RPM should not be used directly install RPM packages, use Alien instead
so:
sudo apt-get install alien
sudo alien my-pkg.rpm
sudo -i my-pkg.deb
4) manage jobs:
"Ctrl-z" : suspend running task
jobs: list background jobs.
fg: make background job running in frontground. e.g. fg %1
bg: background job.
kill background job: kill %1 , num 1 is the num in the jobs list.
5) search software: e.g.
sudo apt-cache search jdk
show package info: sudo apt-cache show pkg-name
################################
######## Mac OS: ########
1) install port:
a) sudo port -d selfupdate
install some pkgs using port:
b) sudo port install iterm2
c) sudo port install tree // the tree command on linux.
2) use port to install emacs:
$ sudo port install emacs
Or, if you want the Aqua version:
$ sudo port install emacs-app
To keep it up to date:
$ sudo port -u upgrade emacs
3) macos emacs: esc+x = M-x
#########################
############# Shell commands: ##############
1) unzip -l : list the contents of a zip archive. e.g.
unzip -l maven-hello-world-portlet.zip
similar as: tar -tf and jar -tf
2) find exclude directory:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache -prune \) -print ## The -prune option make sure that you do not descend into directory
3) delete all directories under curr-directory except ROOT :
find . -maxdepth 1 -type d \( ! -name "ROOT" \) -print0 | xargs -0 rm -rf
4) sudo sh : get root shell.
5) replace one char in filename for all matched files:
find . -name "*-*" -exec bash -c 'mv "$1" "${1//-/_}"' _ {} \;
## replace word in file name:
find . -name "*.html" -exec bash -c 'mv "$1" "${1//html/scala.html}"' _ {} \;
6) delete all .svn directories recursively:
find . -type d -name ".svn" exec rm -rf {} \;
7) execute a line of commands with one sudo: sudo sh -c ??
e.g. sudo sh -c "echo 2 >> /data/zookeeper/myid"
8) count occurrences of a char in a text file:
fgrep -o <xxx> <file> |wc -l
### locale:
can not write and view chinese character in terminal. locale -l, not find zh_CN.UTF-8
1) sudo locale-gen zh_CN.UTF-8
2) echo "export LC_ALL=zh_CN.UTF-8" >> ~/.bashrc
3) restart terminal
4) use LC_ALL=C.UTF-8 can work too. but LC_ALL=C will not work.
key point: if locale -l not have zh_CN.UTF-8, then generate one.
upgrade ubuntu failed:
run these commands in terminal:
sudo apt-get update
sudo apt-get upgrade
find . -type f -print0 | "xargs" -0 -e grep -nH -e
-- show linux version:
uname -a
-- show distribution info:
lsb_release -a
-- count disk usage in curr dir:
du -hs .
-- find a command on shell:
--> which cmd
--> alias -p | grep cmd
### PROCESS SUPERVISION:
1) via supervisord :
supervisorctl
supervisord will auto load all *.conf file in /etc/supervisor/conf.d/*.conf
(configured in /etc/supervisor/supervisord.conf, see the files section)
supervisor conf example:
[program:nodehook]
command=/usr/bin/node /srv/http.js
directory=/srv
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/webhook/nodehook.err.log
stdout_logfile=/var/log/webhook/nodehook.out.log
user=root
environment=SECRET_PASSPHRASE='this is secret',SECRET_TWO='another secret'
run: sudo supervisorctl update to load new conf file.
############################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment