bingooyong / note

1 stars 1 forks source link

玩转 Linux Command Shell #12

Open bingooyong opened 5 years ago

bingooyong commented 5 years ago

How to append multiple lines to a file

cat

# possibility 1:
echo "line 1" >> greetings.txt
echo "line 2" >> greetings.txt

# possibility 2:
echo "line 1
line 2" >> greetings.txt

# possibility 3:
cat <<EOT >> greetings.txt
line 1
line 2
EOT

printf

printf '%s\n    %s\n' 'Host localhost' 'ForwardAgent yes' >> file.txt

tee

tee -a ~/.ssh/config << END
Host localhost
  ForwardAgent yes
END
bingooyong commented 5 years ago

bench execl sql file

for SQL in *.sql; do mysql -h ip -uroot -p"password" < $SQL; done

bingooyong commented 5 years ago

解释:将ngix的安装包及其各种依赖包,指定下载到/root目录下

yum install --downloadonly --downloaddir=/root nginx
bingooyong commented 4 years ago

linux 删除当前目录下旧文件 保留最新的1个文件

ls -t|awk '{if(NR>1){print $1}}' | xargs rm -rf {};
bingooyong commented 3 years ago

Linux的du用法排除某个目录

例如我想得到根目录下所有目录或文件的占用空间大小,并且想要排除名字中包含 proc 的文件或目录,可以使用如下命令

du -sh /* --exclude="proc"
或使用 模糊匹配 都行
du -sh /* --exclude="*proc*"

扩展内容,想要排除多个文件或文件夹,且只想看到空间大于 G 的结果

du -sh /* \
--exclude="proc" \
--exclude="cgroup" \
--exclude="selinux" \
--exclude="*bin" \
--exclude="lib*" \
--exclude="etc" \
--exclude="sys" \
--exclude="boot" \
--exclude="data*" | grep G
bingoohuang commented 3 years ago

du -sh * | sort -rh

[footstone@trace01-192-168-29-27 ~]$ du -sh * | sort -rh
1.2G    otter
281M    bingoohuang
174M    apache-skywalking-apm-bin
135M    apache-skywalking-apm-bin.zip
61M logs
39M 2927_otter_manager1117_bak.tar.gz
14M apm-demo
12M hebe.linux.bin
12M hebe
6.1M    hebe.linux.bin.tar.gz
1.8M    es_clean_cron.log
16K trace-buffer
8.0K    mesh-buffer
8.0K    application.yml
4.0K    webapp.yml
4.0K    test.txt
4.0K    id_rsa.pub
4.0K    clean.sh
bingooyong commented 10 months ago

快速删除 known_hosts2

➜  ~ ssh 10.211.55.27
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:otUwBKeh79nBguE8P0amYAymuNVKYYHDc1qmTn5zK+M.
Please contact your system administrator.
Add correct host key in /Users/bingooyong/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/bingooyong/.ssh/known_hosts2:725
Host key for 10.211.55.27 has changed and you have requested strict checking.
Host key verification failed.

使用 ssh-keygen -R hostname 来清除

ssh-keygen -R 10.211.55.27
ssh-keygen -R 10.211.55.27 -f /Users/bingooyong/.ssh/known_hosts2