Linux
wukong

Linux

[TOC]

Base

bash

查看当前shell echo $SHELL

列出所有shell cat /etc/shells

切换shell bash 直接输入shell名

安装 bash-it

修改bash ~/.inputrc

1
2
3
4
set show-all-if-ambiguous on  # 一次tab键显示补全列表
set visible-stats on # 结尾增加文件类型 @ 链接 / 目录
set colored-completion-prefix on # 增加颜色显示prefix
set completion-ignore-case on # 忽略大小写

删除上一条命令多余输入 ^1 替换 ^1^2,替换或删除 找到的第一个

1
2
cat file1, ^1,   cat file
cat fiel1, ^1^2, cat file2

全局替换

1
2
3
ansible nginx -a 'which nginx'
!:gs/nginx/haproxy # 全局(g)替换(s)
ansible haproxy -a 'which haproxy'

家目录 ~

root用户 /root
普通用户 /home

How

$……
whatis command简要说明
man command说明文档
which commandbinary 文件路径
whereis command搜索路径

DIRECTORIES

$……
pwdDisplay path of current working directory
cd directoryChange directory to directory
ls -lhList directory contents
mkdir directoryCreate new directory named directory
ls -lhList directory contents
tree -hList the contents of the directory in a tree view

OUTPUT

$……
cat file>Output the contents of file
less fileOutput the contents of file using the less command
head fileOutput the first 10 lines of file
cmd > fileDirect the output of cmd into file
cmd >> fileAppend the output of cmd to file
clearClear the command line window

FILES

$……
rm fileDelete file
rm -r directoryDelete directory
rm -f fileForce-delete file (add -r to force-delete a directory)
mv file-old file-newRename file-old to file-new
mv file directoryMove file todirectory (overwriting an existing file)
cp file directoryCopy file todirectory (overwriting an existing file)
touch fileUpdate file access & modification time (and create file if it doesn’t exist)

PERMISSIONS

$……
chmod 755 fileChange permissions of file to 755
chmod -R 600 directoryChange permissions of directory (and its contents) to 600
chown user:group fileChange ownership of file to user and group (add -R to include a directory’s contents)
$……
find dir -name “ fileFind all files named file inside dir
grep “ textfileOutput all occurrences of text inside file (add -i for case-insensitivity)
grep -rl “textdirSearch for all files containing text inside dir

CTRL

$……
CTRL+Amove the caret to the beginning
CTRL+Emove the caret to the end of the line
CTRL+Kdelete all characters after the caret
CTRL+Udelete all characters in front of the caret
CTRL+Lclear  command
CTRL+Cabort a running command

Note

alias

永久命名别名,查看 ~/.bashrc 文件,发现这样一段代码

1
2
3
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

新建文件 .bash_alases , 写入 alias ll='ll -lh' , 保存后执行 source ~/.bashrc

替换 man 为中文

apt-get install manpages-zh
vi /etc/manpath.config
:1,$s#/usr/share/man#/usr/share/man/zh_CN#g

1.在用 vi 命令编辑文件,使用命令前先按:键,然后输入命令 1,$s#/usr/share/man#/usr/share/man/zh_CN#g,回车即可 2.替换第 1 行开始到最后一行中所有的 /usr/share/man 为 /usr/share/man/zh_CN

开启远程ssh登录

  1. 安装openssh-server: sudo apt-get install openssh-server
  2. 开机自动启动ssh命令: sudo systemctl enable ssh
  3. 关闭ssh开机自动启动命令: sudo systemctl disable ssh
  4. 单次开启ssh: sudo systemctl start ssh
  5. 单次关闭ssh: sudo systemctl stop ssh
  6. 设置好后重启系统 reboot
  7. 查看ssh是否启动,看到Active: active (running)即表示成功 sudo systemctl status ssh

ssh生成密钥:ssh-keygen

复制本地公钥到服务器:ssh-copy-id user@remoteip

复制器配置别名 code ~/.ssh/config 可通过ssh deepin 登录服务器

1
2
3
4
Host deeping
HostName 192.168.0.118
User wukong
IdentitiesOnly yes

byobu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
F2 - Create a new win
F3 - Move to previous win
F4 - Move to next win
F5 - Reload prof
F6 - Detach from this sess
F7 - Enter copy/scrollback m
F8 - Re-title a win
F9 - Configuration M
F12 - Lock this termi
shift-F2 - Split the screen horizonta
ctrl-F2 - Split the screen vertica
shift-F3 - Shift the focus to the previous split reg
shift-F4 - Shift the focus to the next split reg
shift-F5 - Join all spl
ctrl-F6 - Remove this sp
ctrl-F5 - Reconnect GPG and SSH sock
shift-F6 - Detach, but do not log
alt-pgup - Enter scrollback m
alt-pgdn - Enter scrollback m
Ctrl-a $ - show detailed sta
Ctrl-a R - Reload prof
Ctrl-a ! - Toggle key bindings on and
Ctrl-a k - Kill the current win
Ctrl-a ~ - Save the current window's scrollback buffer

micro

下载 curl https://getmic.ro | bash

设置全局使用 mv ~/micro /usr/bin/micro

tldr

下载tldr替代 ls man

https://mp.weixin.qq.com/s/qPhUxmIF2ar2pQbJe6Buyg

bat 替代 cat

bat

比Cat更好用的命令!

使用 batcat,建议 修改 alias cat=’batcat’

 Comments