Linux 50个简单命令

工作中常用的50+ Linux 命令,

以下是一些在日常使用中非常有用的命令和它们的基本用法:

文件和目录操作

ls:列出目录内容

ls
ls -l  # 详细信息
ls -a  # 包含隐藏文件
ls -lh # 详细信息并显示人类可读格式大小


cd:更改目录

cd /path/to/directory
cd ~  # 回到用户主目录
cd -  # 回到上一个目录


pwd:显示当前工作目录

pwd


cp:复制文件或目录

cp source_file destination_file
cp -r source_directory destination_directory


mv:移动或重命名文件或目录

mv old_name new_name
mv /path/to/file /new/path/


rm:删除文件或目录

rm file
rm -r directory  # 递归删除目录


mkdir:创建目录

mkdir new_directory
mkdir -p parent_directory/new_directory  # 递归创建目录


rmdir:删除空目录

rmdir empty_directory


文件查看和处理
cat:连接文件并打印到标准输出

cat file


less:逐页查看文件内容

less file


head:查看文件开头部分

head -n 10 file  # 查看前10行


tail:查看文件末尾部分

tail -n 10 file  # 查看后10行
tail -f file     # 实时追踪文件末尾的更新


grep:在文件中搜索字符串

grep "search_string" file
grep -r "search_string" directory  # 递归搜索目录


系统监控和管理

top:实时显示系统资源使用情况
htop:更友好的 top 版本,需要安装
ps:显示当前进程
ps aux
ps -ef
kill:终止进程
kill pid
kill -9 pid  # 强制终止



网络操作

ping:测试网络连通性
ping hostname_or_ip
curl:发送网络请求
curl http://example.com
wget:下载文件
wget http://example.com/file
ssh:远程登录
ssh user@hostname_or_ip


chmod 命令
 

chmod:更改文件权限
chmod 755 file
chown 命令
chown:更改文件所有者
chown user:group file


ln 命令

ln:创建符号链接或硬链接
ln -s target link_name  # 创建符号链接
ln target link_name     # 创建硬链接


Vim 命令

编辑文档时,直接跳到最后一行命令:
shift + G 或者 G
跳到文件的第一行。
gg
跳到第 n 行,比如 10G 跳到第 10 行。
nG 
跳到当前屏幕的第一行。
H
跳到当前屏幕的中间行。
M
跳到当前屏幕的最后一行。
L


Shell 命令

快速跳到第一个字母和最后一个字母
ctrl+a: 光标移到行首。

ctrl+e: 光标移到行尾。

杀死当前进程。
ctrl+c


查端口命令

使用 netstat 查端口命令
netstat -ntpl | grep 8083
使用 lsof 查端口号
lsof -i :8888  


查路径

查找某个文件所在路径
find / -name flink

find /path/to/search -name "filename"
查找大于100M的文件路径
find / -type f -size +100M


zip/uzip 解压缩

压缩
zip -r data.zip data/
解压缩
unzip data.zip


查磁盘使用

查看指定文件磁盘使用情况
du -sh data.csv
从高到底依次显示文件和目录大小
du -sk * | sort -rn
查看整体磁盘使用情况
df -h


查内存

查看服务器总内存
free -mh
查看内存使用情况
free -h


查文本行数

查 data.csv 文本行数
wc -l data.csv


tar解压缩

压缩
tar -zcvf obproxy-macos.tar.gz obproxy-macos
图片
解压缩
tar -zxvf obproxy-macos.tar.gz

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沐之白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值