大醉和尚  
qq:3262641915,如有问题,欢迎讨论.
for i in {1..10}  
do  
echo $(expr $i \* 3 + 1);  
done  


list="rootfs usr data data2"  
for i in $list;  
do  
echo $i is appoint ;  
done

  

  • 添加环境变量

export PATH=/Users/ChenQiushi/Library/Android/sdk/platform-tools:$PATH

echo $PATH
  • shell

a='abc'
b=123
echo ${a}_${b}
  • shell判断

a=1
b=2
c=3
d=4
if [ $a -lt $a ] && [ $c = $d ]
then
    echo 'a'
else
    if [ $a -lt $b ]
    then
        echo 'b'
    fi
fi

 

  • shell for 循环

 

list="rootfs usr data data2"  
for i in $list;  
do  
echo $i is appoint ;  
done


for((i=1;i<=10;i++));  
do   
echo $(expr $i \* 3 + 1);  
done  

  

l=(sp1 spark002 doris003)
for i in ${l[@]};do echo $i;done
  • shell 日期循环

startdate=$1
enddate=$2
table=$3

curr="$startdate"
while true; do
    echo "$curr"
    [ "$curr" \< "$enddate" ] || break
    curr=$( date +%Y%m%d --date "$curr +1 day" )
done

  

  • 文件变更时间

touch -m -r /root/.file1 /root/file2
  •  查看所有用户定时任务

cat /etc/passwd | cut -f 1 -d : |xargs -I {} crontab -l -u {}

 

  • ls 排序

ll -h -Slr  # 文件大小
ll -h -tr  # 更新时间

  

 

  • mv 目录太多

find books/book_xml_* -name '*.*' -exec mv {} book_all \;

 

  • find

find /var -name alertMail.py

  

  • 正则find

find book_xml_all -name '[1][0-9]{6}.*' -exec mv {} book_200w \;

  find . | grep  '[6]\{5\}.xml';

  

  • find 正则删mv

find -E book_xml_all -regex '.*/[4-9]{5}\.xml' -exec mv {} ../book_all \;

  

  • grep 正则

ls -l test_d2 | grep -E "[0-9]{2}.xml"
  • grep排除 -v

cnt=`ps x | grep 'python3 run' | grep -v 'grep'| wc -l`

  

  • 删除多目录下内容

find book_xml_* -name '*.*' -exec rm -f {} \;

  

find / -name pip 2> /dev/null

 

  • 根据时间删除

# 删除2-10天前,kernel开头的文件
find . -mtime +2 -mtime -10 -name "kernel-*" -delete;

# 删除 50M-100M
find . -size -size +50M -size -100M -delete;

 

# find 时间条件

-amin n: 查找n分钟以前被访问过的所有文件。
-atime n: 查找n天以前被访问过的所有文件。
-cmin n: 查找n分钟以前文件状态被修改过的所有文件。
-ctime n: 查找n天以前文件状态被修改过的所有文件。
-mmin n: 查找n分钟以前文件内容被修改过的所有文件。
-mtime n: 查找n天以前文件内容被修改过的所有文件。

  

  • mac下快速删除大量文件

option + command + delete

  • 查看目录下文件个数

ls -l | grep "^-" | wc -l
  • 查看目录下存储大小

du -h --max-depth=1 .
  • ** mac 查看目录存储
du -d 1 .

  

  • 查看目录下的部分文件

ll -t book_200w | head -n 100

  

时间

另外,下面三个的区别:
-amin n  查找系统中最后N分钟访问的文件
-atime n  查找系统中最后n*24小时访问的文件
-cmin n  查找系统中最后N分钟被改变文件状态的文件
-ctime n  查找系统中最后n*24小时被改变文件状态的文件
-mmin n  查找系统中最后N分钟被改变文件数据的文件
-mtime n  查找系统中最后n*24小时被改变文件数据的文件

  

  • 显示20分钟前的文件

find ./book_xml -type f -mmin +20 -exec ls -ltr {} \;

  

  • 删除20分钟前的文件

find ./book_xml -type f -mmin +20 -exec rm {} \;

  

  • scp 拷贝文件下文件,包括文件夹

scp -r ubuntu@ec2-54-219-184-219.us-west-1.compute.amazonaws.com:/home/ubuntu/book_xml book_xml/
  •  临时scp加速

1、sudo vim /etc/ssh/sshd_config
# 末尾添加 !! 不安全做法
GSSAPIAuthentication no
Ciphers aes256-ctr,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc,chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com

2、重启
sudo service sshd restart

  

scp -c aes192-cbc ubuntu@ip:/home/ubuntu/file.zip .

  •  zip

zip -rq bcd.zip fold1 fold2
zip -r fold.zip fold* 
zip -rmq fold.zip fold # 压缩后,删除fold

zip -er fold.zip fold # 加密压缩 unzip prd.zip unzip
-n prd.zip # 不覆盖已有文件

 zip -r /datad/notebook_20220902.zip   /datae/jupyter/notebook -x '*.csv'  # 排除 csv文件


unzip -nd /tmp prd.zip  # -d 目录
  •  tar

tar格式介绍:https://tarcommand.com/

 

 

 

# 最大压缩率
tar cJf test.tar.xz test

# 解压
tar xf test.tar.xz -C /root/

 

使用多核压缩

sudo apt install pigz
yum install pigz

tar --use-compress-program=pigz -cJf book_100w.tar.xz book_100w

设置别名

alias tar="tar --use-compress-program=pigz"

 

# 压缩率
env GZIP=-9 tar czf file.tar.gz /path/to/directory

# 解压
tar xzf file.tar.gz -C "/root/path"

  

  • vim 全局替换

:%s/old/new/g
  • vim配置 sudo vim /etc/vim/vimrc
# sudo vim /etc/vim/vimrc
syntax on set nu! set autoindent set tabstop=4

 

第几行:1gg

跳到文本的最后一行:G

shift+6 行首  或 0

$行末
o:在当前行下面插入一个新行
O:在当前行上面插入一个新行

上:k nk:向上移动n行 9999k或gg可以移到第一行 G移到最后一行
下:j nj:向下移动n行
左:h nh:向左移动n列
右:l nl:向右移动n列

 

复原

u 会删除到刚打开时状态或者上一次 :w 保存的状态

 

阿里云

la -al `which python`

  

ps -ef | grep 9200

 

删除行

:1,.d
当前光标 delete to beginning of file

:.,$d
当前光标 delete to end of file

:1,3d
删除1到3行 # 注意没有0行

  

复制内容

```

:set paste

```

 

  • 后台运行python脚本
python  run.py  >& logs.txt &

  

  • bash_history

vim ~/.bash_history 
history -r  # 退出前,删除当前会话的记录

  

posted on 2019-07-15 09:27  大醉和尚  阅读(161)  评论(0编辑  收藏  举报