Learn linux command
Write down a command-line to see the help text that matches each argument
% echo foo.{rb,go}
foo.rb foo.go
# Useful for changing file extention as the same name.
% cp foo.{rb,go}
foo.rb -> foo.go
Ctrl+u
: Cut all before the cusor and insert it in the kill ring.
Ctrl+k
: Cut all after the cusor and insert it in the kill ring.
Ctrl+w
: Cut a word before the cusor and insert it in the kill ring.
Ctrl+y
: Reinserts the text of the most recent kill.
# Ctrl+u
% ls /usr/local/etc(here is cusor)
%
# Ctrl+k
% ls (here is cusor) /usr/local/etc
% ls
# Ctrl+w
% ls /usr/local/etc
% ls /usr/local/
# Ctrl+y: 'ls /usr/local/' is in kill ring.
%
% ls /usr/local
- Display an entry for each specified file
% du -sh ${fileName}
10M ${filename}
% df (mitsu/feature/fastSelling/ASA-207|✔)
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 xxxxxxxxx xxxxxxxxx xxxxxxx 85% xxxx xx 85% /
devfs 366 366 0 100% 634 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home
map -fstab 0 0 0 100% 0 0 100% /Network/Servers
# Bash string difference
# http://stackoverflow.com/questions/454427/bash-string-difference
% diff <(echo $string1) <(echo $string2)
[http://www.cyberciti.biz/faq/bash-for-loop/]
% ls file*
file1 file2 file3
for i in file{1,2,3}
do
echo ${i}
done
# file1
# file2
# file3
for (( i=0; i<5; i++ ))
do
echo 'muhaha'
done
-- Compare string with regular expressions
#!/bin/sh
if expr "xxx/yyy" : "xxx*" ; then
echo "Match!"
fi
#!/usr/bin/zsh
if [[ "xxx/yyy" =~ "xxx*" ]]; then
echo "Match!"
fi
# Show only hidden files
% ls -ld .?*
# Show only symlinks
% ls -la | grep '\->'
-- pattern-directed scanning and processing language
% sed -n '/startline/,/endline/p' xxx.log | awk '{print $1}' | sort | uniq -c
- exp ~ /regexp/
% awk '$1 ~ /foo/' xxx.log
- [ -F fs ] : separator
% awk -F':' '{print $1}' xxx.log
- Extract specific string
sed -e 's/patternA\(target\)patternB/\1/'
- bulk wording replace
# Use gsed for mac
% find . -name '*.yml' | xargs sed -i "s/xxx/yyy/g"
-- compression/decompression tool using Lempel-Ziv coding (LZ77)
% gzcat ${file}
-- manipulate tape archives
# Extract to disk from the archive. e.g. xxx.tar
% tar zcvf $file.tar.gz $file
# Compress the resulting archive with gzip(1).
% tar zxvf $file
% echo " muhaha " | xargs
muhaha
-- file perusal filter for crt viewing of compressed text
% zless xxx.gz
% bindkey -L
-
ctrl + A
: moves to the start of the line -
ctrl + E
: moves to the end of the line -
ctrl + B
: move back one character -
ctrl + F
: move forward one character -
esc + B
: move back one word -
esc + F
: move forward one word
Note that Esc, b and Esc, f (back/forward one word) are bound to Opt-b/f (when you set the terminal to recognize Opt as Meta)
sample
- Keep Alive
% cat .ssh/config
ServerAliveInterval 30
- With PORT, other user
% ssh -p1234 -i ~/.ssh/tomato_id_rsa [email protected]
Host sample
HostName 0.0.0.0
User tomato
Port 1234
IdentityFile ~/.ssh/tomato_id_rsa
- proxy command
Host sample
HostName 0.0.0.0
ProxyCommand ssh -W %h:%p 1.1.1.1
% cat << EOF > .gitignore
node_modules
EOF
# ubuntu
% cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
# centos
% cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
# Architecture type
% arch
i386
-> dig
or host
-- Change login shell
% chsh -s /usr/local/bin/zsh