Introduction
This is a complete set of commonly used Linux commands, and welcome to visit my blog
Commonly used shortcut keys
button | effect |
---|---|
Ctrl+d | End of keyboard input or exit the terminal |
Ctrl+s | Pause the current program, press any key to resume operation after pausing |
Ctrl+z | Put the current program to run in the background and restore it to the foreground as the command fg |
Ctrl+a | Move the cursor to the beginning of the input line, equivalent to the Home key |
Ctrl+e | Move the cursor to the end of the input line, equivalent to the End key |
Ctrl+k | Delete from the cursor position to the end of the line |
Ctrl+c | Use the key to forcibly terminate the current program |
Alt+Backspace | Delete one word forward |
Shift+PgUp | Scroll up the terminal display |
Shift+PgDn | Scroll down the terminal display |
Function Manual (man)
You can use the function manual to view the specific usage of a command
$ man <command_type> <command_name>
# `man 1 ls` 这条命令可以查看`ls`有哪些用法
# comman_type 的选择如下
# 1 一般命令
# 2 系统调用
# 3 库函数,涵盖了C标准函数库
# 4 特殊文件(通常是/dev中的设备)和驱动程序
# 5 文件格式和约定
# 6 游戏和屏保
# 7 杂项
# 8 系统管理命令和守护进程
User Management
- View users
The specific usage can be: man 1 who
open the function manual
# 查看当前用户的两种写法
who am i
who mom likes
- Create user
# 创建新用户 woyao
sudo adduser woyao
# 更新用户密码
passwd woyao
- Switch user
su -l woyao
su woyao
- delete users
sudo userdel woyao -f
File processing
- create
# 创建文件
touch 1.txt 2.txt
touch love_{1..10}_woyao.txt
# 创建目录
mkdir mydir
mkdir -p user/woyao/name
- copy
# 复制文件
cp a.txt user/woyao/name
# 复制目录
# 将father内的子文件复制到family文件夹
cp -r father family
- delete
# 删除文件
rm a.txt
rm -f a.txt
# 删除目录
rm -rf father
- Move files and rename files:
# a.txt 移动到 father
mv a.txt father
# a.txt 重命名为b.txt
mv a.txt b.txt
# 批量将后缀为 .txt 的文本文件重命名为以 .c 为后缀的文件:
rename 's/.txt/.c/' *.txt
# 批量将文件,文件名和后缀改为大写:
rename 'y/a-z/A-Z/' *.c
- View
cat a.txt
# -n 参数显示行号
cat -n a.txt
# 更多显示
more a.txt
# 显示一部分
less a.txt
# 文件的最后一行
tail -n 1 /father/son/grandson/a.txt
# 文件的开始
head b.txt
# 查看文件类型
file a.txt
# 查看文件大小
du -h -d 0 *.zip ~ | sort
du -h woyao.zip
- search for
# 匹配所有文件名带a.txt的路径
locate a.txt
# 在root目录下,查找有a.txt的路径
find /root/ -name a.txt
- File permission management
# 'r'读4, 'w'写2, 'x'可执行1
# 600 等价于 -wr-----
# 644 等价于 -rw-r--r--
chmod 600 a.txt
# 变更文件所有者
sudo chown chen a.txt
- File compression, decompression, packaging
# 把woyao文件夹压缩成woyao.zip
cd /Desktop
zip -r -q -o woyao.zip woyao
# 解压woyao.zip
unzip woyao.zip
# 解压到指定目录
unzip -q woyao.zip -d /Desktop/tomas
# 查看zip压缩包的内容
unzip -l woyao.zip
# 把woyao文件夹压缩成woyao.tar
cd /Desktop
tar -cf woyao.tar woyao
# 解压woyao.tar
tar -xf woyao.tar
# 解压到指定目录
tar -xf woyao.tar -C /Desktop/tomas
# 查看tar压缩包的内容
tar -tf woyao.tar
Environment variable
# 使用 declare 命令创建一个变量名为 tmp 的变量:
declare tmp
tmp=woyao
# $符号用于表示引用一个变量的值,
echo $tmp
Sao operations (pipes, redirects,...)
# 家目录 ~
echo ~
# 重定向 >, >>, tee
# 输出重定向覆盖模式(会覆盖原文件内容)
cat b.gua > c.gua
echo "hello gua" > c.gua
# 输出重定向的追加模式,不会覆盖文件内容
echo "hello gua" >> c.gua
# 管道 |
# 管道符号把输出传给另一个程序作为输入
cat c.gua | tee f.gua
# 显示历史密令中带有cat命令的字符串
history | grep cat
tee: 把输入过来的数据输出到屏幕上并且重定向一份到文件
history | grep cat | tee new.txt
# 让程序在后台运行 &
# 可以使运行的Firefox在终端后台运行
firefox &
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。