大家好,欢迎来到IT知识分享网。
Linux 高阶命令-常用命令详解
思维导图版本
C which
which 命令用于查看可执行命令的文件位置。
示例
bash
which ls which python #技术分享
find
find 命令用于查找文件。
常用选项
- -name : 按文件名查找
- -size : 按文件大小查找
- 通配符支持: * (匹配任意字符), ? (匹配单个字符)
示例
bash
# 查找当前目录下所有.txt文件 find . -name "*.txt" # 查找/home目录下大于100MB的文件 find /home -size +100M # 查找/etc目录下以.conf结尾的文件 find /etc -name "*.conf" # 查找当前目录下名为test.txt的文件 find . -name test.txt
df
df 命令用于显示磁盘空间使用情况。
示例
bash
df -h df -t ext4
du
du 命令用于查看文件和目录的磁盘使用情况。
示例
bash
du -sh * du -sh /home/user du -h --max-depth=1 /var/log
grep
grep 命令用于文本搜索。
常用选项
- -n : 显示匹配行的行号
- -i : 忽略大小写
- -v : 反向匹配(显示不包含模式的行)
示例
bash
grep '命运' aa.txt cat aa.txt | grep '命运' cat aa.txt | grep '命运' | grep '硬币' cat a.txt | grep -n '123' ls | grep '.doc' pip list | grep 'ss' find /etc | grep 'ss'
C echo
echo 命令用于输出文本。
重定向操作符
- > : 覆盖输出到文件
- >> : 追加输出到文件
示例
bash
echo "Hello World" echo "一些文字" > a.txt echo "一串文字" >> a.txt echo -e "第一行\n 第二行" > multiline.txt
vim
Vim 是一个强大的文本编辑器,有三种工作模式。
工作模式
- 命令模式 :默认模式,用于导航和操作文本
- dd – 删除当前行
- yy – 复制当前行
- p – 粘贴
- u – 撤销
- 输入模式 :用于编辑文本内容
- 按 i 进入插入模式
- 按 a 进入追加模式
- 按 o 在当前行下方新建一行
- 底线命令模式 :用于保存文件、退出等操作
- :w – 保存文件
- :q – 退出vim
- :wq 或 :x – 保存并退出
- :q! – 强制退出不保存
- :wq! – 强制保存并退出(需要文件所有者权限)
- :set number – 显示行号
示例
bash
vim filename.txt i [编辑文本] ESC :wq
用户管理
创建用户
bash
useradd xxx1 useradd xxx2 passwd xxx1 passwd xxx2 getent passwd id id username
切换用户
bash
su username su -
借用管理员权限
bash
sudo command sudo visudo
删除用户
bash
userdel username userdel -r username
群组管理
用户组操作
bash
# 添加用户组 groupadd group1 # 查看用户组 getent group # 将用户添加到附加组 usermod -aG group1 username # 删除用户组 groupdel group1
权限管理
chmod – 更改文件权限
bash
chmod +x filename chmod 755 filename chmod 644 filename chmod -R 755 directory/
chown – 更改文件所有者
bash
chown root hello.txt chown :root hello.txt chown root:itheima hello.txt chown -R root test_directory
链接
软链接(符号链接)
bash
ln -s /path/to/file link_name ln -s /var/log/syslog log_link
硬链接
bash
ln file new_file ln original.txt backup.txt
进程管理
查看进程
bash
ps -ef ps -u username pstree top
历史命令
使用历史命令
bash
history history | grep 'apt' !number !string Ctrl+R
其他实用技巧
命令组合示例
bash
find . -name "*.log" -exec grep -l "error" {} ; wc -l filename sort file.txt | uniq tail -f /var/log/syslog
通配符使用
bash
cp *.txt /backup/ ls file?.txt ls file[0-9].txt ls {*.txt,*.log}
希望这份详细的文档能帮助您更好地理解和使用 Linux 命令。每个命令都有更多高级选项,可以通过 man command (如 man find )查看完整手册。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/189776.html