Nov 01, 2018
分区
parted -s -a optimal /dev/sda mklabel gpt -- mkpart primary ext4 1 -1s
创建文件系统
查看分区结果
复制数据
首先挂载到临时分区
把之前的数据考进去
# rsync -av /home/* /mnt/
OR
# cp -aR /home/* /mnt/
校验数据
删除老数据
挂载 …
Apr 01, 2018
fd
(https://github.com/sharkdp/fd) 是 find
命令的一个更现代的替换。
fd
(https://github.com/sharkdp/fd)is a modern and nicer replacement to the traditional find
command.
对比一下 Some comparisons
查找名字含有某个字符的文件 Find a filename with certain string
OLD
-> % find . -name "*hello*"
./courses/hello_world.go
./courses/chapter_01/hello_world.go
./courses/chapter_01/hello_world …
Jan 28, 2018
最近工作中经常用到的一些组合命令,本来想提交到 commandlinefu.com 上,但是忘记了密码,怎么也登录不上去了,记到这里吧
set -x # 显示每个执行的命令
set -e # 当有程序返回非0值时直接退出,相当于抛出异常
cat << EOF > /tmp/yourfilehere
These contents will be written to the file.
This line is indented.
EOF
Jul 16, 2017
变量和值
variables are referenced by $var or ${var}. Global variables are visible to all sub bash sessions, and are often called env variables, local variables are only visible to local session, not subsessions.
Global variables can be viewed as env
, and can be created by export
.
TEST=testing; export $TEST …
Jun 30, 2017
$ EDITOR=vi visudo
# then add this
ALL ALL=(ALL) NOPASSWD: ALL
username ALL=(ALL) NOPASSWD: ALL
%group ALL=(ALL) NOPASSWD: ALL
Defaults env_keep += "EDITOR"
May 30, 2017
get current file path
| #!/bin/bash
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
echo $SCRIPTPATH
|
这些程序基本都有一个模式:如果不给定文件作为参数,那么就从stdin读取,从 stdout 输出,非常适合 …
May 30, 2017
加载速度对于网页的体验还是很重要的, 而每个页面比较耗费带宽的资源就是图片了, 所以在页面发布后对图像做适当的压缩是很有必要的.
常用的图片格式基本有三种: jpg, png 和 gif, 分别有不同的压缩工具
JPG 压缩建议使用 jpegoptim, 实测压缩比在40%左右, 最常用的语法是
jpegoptim -p -m<dd> <imagefile>
其中 -p 是保留 mtime 的意思, 也可以用 --perserve, -m 后面跟两个数字表示, 压缩的比例, 一般用90即可, 肉眼无法分辨, 且能够压缩掉40%左右
png 压缩有两个选项, 常规的 optipng 和另一个新一点 pngquant, 测试了一下, 发现 optipng 速度慢而且压缩效率低, pngquant 则表现相当优秀, 但是需要注意 pngquant 是有损压缩.
pngquant …
May 30, 2017
Converting MP4 to gif
To convert the entire video to GIF, use the following command:
ffmpeg -i small.mp4 small.gif
To convert just a portion of a video clip to GIF, use the following command:
ffmpeg -t 3 -ss 00:00:02 -i small.webm small-clip.gif
The snippet …
May 29, 2017
执行 sudo vi /etc/suduers
, 然后输入:
username ALL=(ALL) NOPASSWD: ALL
useradd -m USERNAME # add a user
userdel USERNAME # delete a user
passwd -e # password expire next time user login
groups username # view username groups
usermod -G groupname username # add user to a group
usermod -g groupname username # set user …