Linux 常用命令
收集一些常用的 Linux 命令,方便查找。
文件命令
touch
创建文件。
- touch hi.txt 在当前目录创建 hi.txt 文件。
- echo “hello” > hi.txt 创建文件,并写入内容。
cat
查看文件命令,并显示在终端。
- cat hi.txt 查看 hi.txt 文件的内容。
echo
文件导航命令
pwd
打印当前工作目录的名字。
cd
- cd [~]: 当前用户的主目录
- cd ..: 父目录
- cd -(破折号): 之前所在的目录
ls
用法:ls [选项]… [文件]…
列出 <文件>(默认为当前目录)的信息。
如果既没有指定 -cftuvSUX 中任何一个,也没有指定 –sort,则按字母排序项目。
选项:
- -a 不要隐藏以 . 开头的项目
- -l 使用长列表格式
- -F 显示文件类型。
/
表示这是一个目录;*
表示可执行文件;@
表示链接 - -h 同时使用 -l 或 -s 时,将大小表示为 1K 234M 2G 等
- -t 按时间排序,最新的最前
查找文本命令
Grep
用法: grep [选项]… 模式 [文件]…
在每个<文件>中查找给定<模式>。
例如:grep -i ‘hello world’ menu.h main.c
模式选择与解释:
- -i, –ignore-case 在模式和数据中忽略大小写
–no-ignore-case 不要忽略大小写(默认)
输出控制:
- -n, –line-number 输出的同时打印行号
- -r, –recursive 等同于–directories=recurse
示例:
1 | grep "hello" hi.txt hi2.txt #从指定文件查找字符串 |
ack-grep
ag
A code-searching tool similar to ack, but faster.
ag [options] pattern [path …]
ag [可选项] 匹配模式 [路径…]
安装:
- ubuntu: apt-get install silversearcher-ag
fzf
fzf is a general-purpose command-line fuzzy finder.
fzf 是一个通用的命令行模糊搜索工具,用 golang 编写。
安装:
- APT: sudo apt-get install fzf
- Pacman: sudo pacman -S fzf