Shell Code Snippets - WBowam/wbowam.github.com GitHub Wiki

Date: 2015-03-30
Title: Shell 代码片段
Tags: Snippets, Shell
Category: IT

-hl 参数

ls -hl
-h, --human-readable
    with -l, print sizes in human readable format (e.g., 1K 234M 2G)
$ df -hl
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        92G   20G   68G  23% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            2.9G  4.0K  2.9G   1% /dev
tmpfs           584M  1.3M  582M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.9G   21M  2.9G   1% /run/shm
none            100M   32K  100M   1% /run/user

man命令比help更可阅读

shell: count files in dir

ls -1 | wc -l

shell: size of dir

du -hl dir/

Automatically Create Recursive Directory

mkdir -p exist/notexist

linux查找并列出十大文件

$ sudo du -sh /* | sort -nr | head
954M    /usr
684M    /lib
656K    /run
97M     /boot
36K     /root
23M     /home
17G     /var
16K     /lost+found
13M     /sbin
12M     /bin

shell 查看 / 内文件大小

du --max-depth=1 -h /| sort -n -r

docker blog script

docker run -it -v /home/ymj/workplace/blog/content:/home/tulpar/blog_new/blog/content -v /home/ymj/workplace/blog/output:/home/tulpar/blog_new/blog/output tulpar008/blog:v2.0 /bin/sh -c 'cd /home/tulpar/blog_new/blog/;make html'

ssh by public key |snipets

  1. add your public key into remote server's authorized_keys
cat .ssh/id_rsa.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"
  1. scp yuor authorized_keys to remote server
scp ~/.ssh/authorized_keys [email protected]:~/.ssh/
  1. ~/.ssh/authorized_keys must be writable only by you

mkdir -p

mkdir -p blog/{posts,output,templates,static}/{test,yep}