Linux常用的基础命令(最新)

Linux常用的基础命令(最新)

当前文章的状态:

  • 结束更新
  • 正在更新

1. 状态类检查

1.1 系统运行与停止

shutdown: #命令安全地将系统关机。 
  [-t] 在改变到其它runlevel之前﹐告诉init多久以后关机。
  [-r] 重启计算器。
  [-k] 并不真正关机﹐只是送警告信号给每位登录者〔login〕。
  [-h] 关机后关闭电源〔halt〕。
  [-c] cancel current process取消目前正在执行的关机程序。
  [-f] 在重启计算器〔reboot〕时忽略fsck。
  [-F] 在重启计算器〔reboot〕时强迫fsck。
  [-time] 设定关机〔shutdown〕前的时间。

halt  #最简单的关机命令(调用shutdown -h)
  [-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
  [-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
  [-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
  [-f] 没有调用shutdown而强制关机或重启。
  [-i] 关机〔或重启〕前﹐关掉所有的网络接口。
  [-p] 该选项为缺省选项。就是关机时调用poweroff。
 
reboot  #重启
  [-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
  [-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
  [-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
  [-f] 没有调用shutdown而强制关机或重启。
  [-i] 关机〔或重启〕前﹐关掉所有的网络接口。
	[-p] 该选项为缺省选项。就是关机时调用poweroff。
  

1.2 系统检查

cat /etc/redhat-release   # Redhat操作系统
cat /etc/os-release # Centos操作系统
lscpu   # cpu详细信息
sudo dmidecode -t processor # cpu详细信息
grep MemTotal /proc/meminfo   # 内存 
grep SwapTotal /proc/meminfo   # 内存
df -h   # 磁盘容量查看

1.3 防火墙检查

  1. CentOS6 (转载1)
检查防火墙状态:service iptable status
临时启动防火墙:servcie iptables start 
临时关闭防火墙:servcie iptables stop
开机启用防火墙:chkconfig iptables on
开机禁用防火墙:chkconfig iptables off
  1. CentOS7
 检查防火墙状态:systemctl status firewalld.service 
 临时启动防火墙:systemctl start firewalld.service 
 临时关闭防火墙:systemctl stop firewalld.service
 开机启用防火墙:systemctl enable firewalld.service 
 开机禁用防火墙:systemctl disable firewalld.service
  1. kylin10
sudo systemctl status firewalld   # 当前防火墙状态
   Active: active (running) #运行中
   Active: inactive (dead) #已关闭
sudo systemctl start firewalld  # 开启防火墙
sudo systemctl stop firewalld   # 关闭防火墙

1.1.4 系统时间检查

  date   #查询时间
  
  tzselect   #更改时区
  
  date -s "YYYY-MM-DD HH:MM:SS"   #手动修改时间
  

1.1.5 进程检查

 ps -ef|grep java  #查询进程<java>相关
 kill -9 <进程号>  # 杀掉某进程

 kill -9 <进程号>  # 杀掉某进程
 killall -u <用户名>  # 杀掉用户下全部进程(方式一)
 pkill   -u <用户名>  # 杀掉用户下全部进程(方式二)

2. 用户管理

2.1 用户创建与删除

useradd [用户名]   # 创建用户
passwd [用户名]   # 修改用户密码
userdel -r [用户名]   # 删除用户
find / -name "*[用户名]*"   # 查询删除用户后是否残余文件

2.2 用户组创建与删除

groupadd [组名] -g 2001   # 创建用户所在的组
useradd  -G [组名] -m -d /home/dmdba -s /bin/bash -u 2001 dmdba   # 创建用户
groups [用户名]   # 查询用户组名

3. 文档管理

3.1 文件信息查询

du -sh *   # 当前路径下所有文件大小、名称
ll   # 当前路径下所有文件权限、大小、名称、创建时间
ls   # 当前路径下所有文件名称

3.2 文件创建

文件:touch 文件夹:mkdir

touch demo.txt   #文件创建
mkdir LOGS   #文件夹创建

3.3 文件迁移

复制:cp 移动:mv 删除:rm

cp /lujing1/file1 /lujing2/file2		#复制
mv /lujing1/file1 /lujing2/file2		#迁移
rm [参数] /lujing1/file1		#删除
   -f:强制删除,包含正在运行文件
   -i:删除前询问用户是否操作
   -r:递归删除,常用在目录的删除
   例:rm -rf /home/app/log.txt

3.4 文件压缩

1.tar.gz文件管理

tar -zcvf			# 压缩
tar -zxvf			# 解压

2.zip文件管理

zip [参数] [压缩后名称] [压缩前文件名称]		# 压缩
	-q	不显示执行过程
	-r	包含子目录
	-z	给压缩文件加上注释
	-v	显示执行过程
	例:zip -r log_20221212.zip log
unzip 文件名.zip		# 解压

3.5 远程文件传输

# 使用scp命令从本地复制到远程服务器     
scp /path/to/local/file username@remote_host:/path/to/remote/directory 
# 使用scp命令从远程服务器复制到本地     
scp username@remote_host:/path/to/remote/file /path/to/local/directory 
# 使用scp命令复制目录     
scp -r /path/to/local/directory  username@remote_host:/path/to/remote/directory 
# 使用scp命令使用特定端口     
scp -P port /path/to/local/file username@remote_host:/path/to/remote/directory 
# 使用scp命令使用特定SSH密钥进行身份验证     
scp -i /path/to/key_file /path/to/local/file username@remote_host:/path/to/remote/directory 
# 使用scp命令时跳过确认     
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /path/to/local/file username@remote_host:/path/to/remote/directory 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值