xargs命令介绍

文章未完工。

xargs官方介绍:从标准输入创建和执行命令

什么是GNU version of xargs?(待完善)

可能上面的解释不是很好理解,那直接从例子开始吧:

在目录/tmp下或者其子目录下查找名字为core的文件,并且将它们删除(提示:如果查找到的文件名称含有空格或者换行符时可能会产生错误):

find /tmp -name core -type f -print | xargs /bin/rm -f

Continue reading "xargs命令介绍"

vim常用操作

启动

# 打开文件时跳到第92行
vi /usr/local/etc/httpd/extra/httpd-ssl.conf +92

daw – delete a word 删除光标处单词
dw – 同上,但是只删除单词中光标右侧的那一部分

caw – delete the word under the cursor and put you in insert mode 删除并进入到插入模式
cw – 同上,但是只删除单词中光标右侧的那一部分

配置sudo保存

使用 :w!! 保存readonly文件(非常方便): 执行 echo 'cmap w!! w !sudo tee % > /dev/null' >> ~/.vimrc
Continue reading "vim常用操作"

Linux简单笔记

grep 在当前目录下全局查找,并且排除目录,并显示行号
grep -Rn --exclude-dir=storage/ 'makePayVerificationCode'

创建文件:
dd if=/dev/zero of=500mb.zip bs=1024k count=500

踢出一个用户:
pkill -kill -t pts/1

显示当前目录下的内容占用的硬盘大小:
du -lh --max-depth=1

显示文件夹的总占用硬盘大小:

du -sh /path
du -hsx * | sort -rh | head -10
sudo du -lh --max-depth=1 /var/lib

全局查找:

grep -rnw '/path/to/somewhere/' -e "pattern"

在home目录下所有文件中查找,包括close的文件,并分页输出
grep -r "close" /home/* | more

samba命令行的连接:
smbclient //ip/test -U <password>

连接mysql:
mysql -h127.0.0.1 -uroot -p<password>

备份数据库命令
mysqldump -uroot -p<password> -h127.0.0.1 --all-databases > "%y-%m-%d.sql";

等待用户输入并放到password变量中:
read -p "enter your password:" password

解压
tar –zxvf redis-2.4.6.tar.gz

连接fpt,账号 ftpstatic, 密码 <password>
ftp <server> 21

使用scp复制远程服务器的文件到本地,需要输入密码
scp root@<server>:/root/php.ini ~/php.iii

使用scp传送文件到远端服务器
scp -P 22 /c/Users/Administrator/Downloads/redis_cheat_sheet.pdf root@<server>:/root/books/redis_cheat_sheet.pdf

查看内存使用情况
free -h --si

git clone 远程仓库
git clone ssh://root@<server>:<port>/root/repository/maxcho/maxcho.git you_local_folder

封锁一个ip
iptables -I INPUT -s 117.21.191.98 -j DROP

python使用豆瓣镜像
easy_install -i http://pypi.douban.com/simple/ sphinx

创建软链接
ln -s <path> <dest-path>

修改时区
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

限制IP 进行ssh登录
vi /etc/hosts.allow 添加: sshd:<ip>
vi /etc/hosts.deny 添加:sshd:all

设置ssh cli不掉线
vi /etc/ssh/sshd_config
ClientAliveInterval 60
ClientAliveCountMax 3

  • 1=x:可执行
  • 2=w:可写
  • 4=r:可读

权限顺序为:用户.群组.其他用户

crontab

1    2    3    4    5
*    *    *    *    *   command
分   时   日   月   周    命令
  • uname -r && lsb_realse -a
    查看系统的内核版本和(linux standard base)

  • tcpdump -i eth1 ‘port 80’ -x -vv – 抓包

运维相关知识

1 . 在文件 /var/log/cron.log/var/spool/mail/root 两个文件中可以看得到crontab运行的记录和错误日志
2 . 在文件 /etc/motd 中可以修改登录上来的欢迎文字
3 . 在文件 /etc/ssh/sshd_config 中可以修改ssh配置信息
4 . 在文件 /etc/sysconfig/iptables 中可以修改iptables配置信息
5 . 在文件 /proc/cpuinfo 可以看到cpu的相关信息

something to do
1. .bashrc 老是不生效,咋回事啊?
3. 写一篇文章《使用openssl代替mcrypt》
4. 开始慌了,进步太慢了吧,学习一下elasticseach的mapping优化
6. symfony 的ACLs 还有voter是个啥东西?
7. wireshake是个好东西啊
10. 修改了swap分区的大小,增加了1G

bash语法

if 判断语句

var=$1
if [ $var -eq 1 ]; then
    echo 'var is 1'
elif [ $var -eq 2 ]; then
    echo 'var is 2'
else
    echo 'var is not 1 and 2'
fi

# case 选择语句, 即我们一般语法中的switch
case $var in
    'value1')
        echo -e 'var is value1 for first place'
    ;;

    'value2')
        echo -e 'var is value2 for second place'
    ;;

    *)
        echo -e 'var is eq value1 or value2, so this is a default ouptput'
    ;;
esac

for 循环语句

  • case 1 输入数字
for i in 1 2 3 4 5 6
do 
    echo -e "current value is $i"
done
  • case 2 输出字符串
for i in 'this is a string , will be output one by one'
do 
    echo $i
done
  • case 3 输出文件夹
for file in $HOME/.*
do
    echo $file
done
  • case 4 输出数组
for ele in (1,2,3,4,hello)
do
    echo $ele
done
  • case 5 遍历文件夹
for file in <path>
do
    if test -f $file;then
       rm $file
    else
        echo "$file is a dir"
    fi
done




代码示例1(迁移文件夹):

#!/bin/bash

# 检查参数
if [ ! -n "${1}" ];then
    echo "请指定一个目录来进行迁移: ls ~/Library/Application\ Support/"
    exit -1
fi
Entity=$1
# 检查路径是否存在
SourceFolder="${HOME}/Library/Application Support/${Entity}"
if [ ! -d "${SourceFolder}" ];then
    echo "${SourceFolder}目录不存在!"
    exit -1
fi
echo "即将迁移:${SourceFolder}"

# 检查覆盖
if [ -L "${SourceFolder}" ];then
    echo "源路径已经是符号连接"
    ls -l "${SourceFolder}"
    exit -1
fi

# 确定目标设备
TargetDevice="/Volumes/External"
read -p "目标设备为(默认 ${TargetDevice}): " InputTargetDevice
if [[ -n $InputTargetDevice && "$TargetDevice" != "$InputTargetDevice" ]];then
    TargetDevice=$InputTargetDevice
fi
TargetFolder="${TargetDevice}/Library/Application Support/${Entity}"
if [ -d "${TargetFolder}" ];then
    echo 目标路径"${TargetFolder}已经存在,将进行覆盖才做"
fi

# 准备迁移
echo "正在准备迁移 ${SourceFolder} => ${TargetFolder}"
mkdir -p "${TargetDevice}/Library/Application Support" \
    && mv -vn "${SourceFolder}"/* "${TargetFolder}/" \
    && rmdir "${SourceFolder}" \
    && ln -s "${TargetFolder}" "${SourceFolder}" \
    && echo "迁移成功!" \
    && exit 0

echo "迁移失败!"

tmux使用教程

命令

  • tmux 新建一个会话
  • tmux ls 查看会话列表
  • tmux attach-session -t 进入到一个session
  • tmux kill-session -t 删除一个session

快捷键

  • C-b % 竖向分屏
  • C-b " 横向分屏
  • C-b x 关闭当前面板
  • C-b c 新建window
  • C-b o 面板之间跳转
  • C-b C-o 旋转面板的位置
  • C-b [ 进入到复制模式 复制模式按空格键复制,回车退出,C-b ] 粘贴复制的内容
  • C-b n/p 前后window选择
  • C-b w 显示window列表
  • C-b d 退出当前会话
  • C-b z [toggle] 面板全屏/非全屏切换

配置参考

    unbind C-b
    set -g prefix C-b

    set-option -g status on
    set-option -g status-bg green

    set-window-option -g mode-mouse off

    setw -g mode-keys vi