linux常用操作命令
1、查看系统信息
# top # 查看谁最占用cpu, 谁最占用资源等,Shift+m可以按内存占用来排序
# cat /etc/redhat-release #查看发行版
# uname -a # 查看内核/操作系统/CPU信息
# cat /proc/version # 查看内核
# cat /proc/cpuinfo # 查看CPU信息
# cat /proc/meminfo # 查看内存信息
# free -m/h # 查看内存使用量和交换区使用量
# hostname # 查看计算机名
# lspci -tv # 列出所有PCI设备
# lsusb -tv # 列出所有USB设备
# lsmod # 列出加载的内核模块
# env # 查看环境变量资源
# df -h # 查看各分区使用情况
# dmesg # 查看内核信息
# uptime # cpu 运行时间
# whoami # 查看登陆的终端名称
# rpm -qa # 查看所有安装包
# rpm -qf # 查看文件属于哪个包
# rpm -ql <package-name> # 查询一个已安装软件包里所包含的文件
# rpm -qc <package-name> # 查看一个已安装软件包的配置文件位置
# rpm -qi <package-name> # 查询一个已安装软件包的描述信息
# rpm -qd <package-name> # 查看一个已安装软件包的文档安装位置
# ps -ef # 查看进程信息
# ps -aux # 查看进程信息
2、echo
echo "`ls -l`" 详细显示ls -l 并按照原有格式显示
echo $SHELL 显示变量的的值
后续shell编程会经常使用此命令
3、date
date 时间日期
cal 当月日历
cal 2019 2019日历
datetime以及修改时间在后续ntp中再说明
4、wget命令
wget命令用于在终端中下载网络文件,格式为“wget [参数] 下载地址”。
wget命令的参数以及作用
参数 | 作用 |
-b | 后台下载模式 |
-P | 下载到指定目录 |
-t | 最大尝试次数 |
-c | 断点续传 |
-p | 下载页面内所有资源,包括图片、视频等 |
-r | 递归下载 |
5、ps
R(运行):进程正在运行或在运行队列中等待。
S(中断):进程处于休眠中,当某个条件形成后或者接收到信号时,则脱离该 状态。
D(不可中断):进程不响应系统异步信号,即便用kill命令也不能将其中断。
Z(僵死):进程已经终止,但进程描述符依然存在, 直到父进程调用wait4()系统函数后将进程释放。
T(停止):进程收到停止信号后停止运行。
[root@localhost docs]# ps --help
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
[root@localhost docs]# ps --help list
Usage:
ps [options]
Selection by list:
-C <command> command name
-G, --Group <GID> real group id or name
-g, --group <group> session or effective group name
-p, p, --pid <PID> process id
--ppid <PID> parent process id
-q, q, --quick-pid <PID>
process id (quick mode)
-s, --sid <session> session id
-t, t, --tty <tty> terminal
-u, U, --user <UID> effective user id or name
-U, --User <UID> real user id or name
The selection options take as their argument either:
a comma-separated list e.g. '-u root,nobody' or
a blank-separated list e.g. '-p 123 4567'
For more details see ps(1).
[root@localhost docs]# ps --help simple
Usage:
ps [options]
Basic options:
-A, -e all processes
-a all with tty, except session leaders
a all with tty, including other users
-d all except session leaders
-N, --deselect negate selection
r only running processes
T all processes on this terminal
x processes without controlling ttys
For more details see ps(1).
[root@localhost docs]# ps --help output
Usage:
ps [options]
Output formats:
-F extra full
-f full-format, including command lines
f, --forest ascii art process tree
-H show process hierarchy
-j jobs format
j BSD job control format
-l long format
l BSD long format
-M, Z add security data (for SELinux)
-O <format> preloaded with default columns
O <format> as -O, with BSD personality
-o, o, --format <format>
user-defined format
s signal format
u user-oriented format
v virtual memory format
X register format
-y do not show flags, show rss vs. addr (used with -l)
--context display security context (for SELinux)
--headers repeat header lines, one per page
--no-headers do not print header at all
--cols, --columns, --width <num>
set screen width
--rows, --lines <num>
set screen height
For more details see ps(1).
[root@localhost docs]#
6、
lsof - list open files
列出打开的文件
pidof -- find the process ID of a running program.
pidof 找出当前运行程序的进程ID
pgrep, pkill - look up or signal processes based on name and other
pgrep 是通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行。
kill pid 中止进程
7、ifconfig
8、
cat 查看
zcat 直接查看.zip文件,在一些日志中比较常用
more 可以一行一行的看
head -n 可以看前n行
tail -n 可以看末尾n行
tail -f 实施查看末尾的变化,在查最新变化的日志时使用
tr [a-z] [A-Z] char 替换,sed弱化版
wc -l/w/c line word char 统计行数,字数,字符数
stat 查看文件属性详情
cut命令
cut命令用于按“列”提取文本字符,格式为“cut [参数] 文本”。
diff 比较文件差异
9、
touch file 新建一个空白文件
mkdir -p 新建一个目录,如果父目录不存在,同时创建父目录
cp /dev/a.txt /bb/cc.aa
rm -rf 递归并直接删除文件或文件夹下所有内容
mv 移动文件,可以用来对文件改名
10、
find
find / -name *file*
grep 在结果中筛选
如 cat aaa.txt | grep -C 5 version 在aaa.txt文件中version 的上下五行显示出来
locate
该命令不会实时检索,只是根据已有的索引信息查找,对于刚下载的文件,查找结果不够准确
11、
tar
-c 创建新的文档。
-v 显示详细的tar处理的文件信息
-f 要操作的文件名
-t 表示查看文件,查看文件中的文件内容
-x 解压文件
-z 调用gzip程序来压缩文件,压缩后的文件名称以.gz结尾
#tar -xzvf test.tar.gz
12、
dd if=/dev/zero of=/zhangp/100_file count=1 bs=100M
dd if=/dev/cdrom /zhangp/of=centos7.iso