Linux命令

pidof
在查看服务器的进程id时非常方便.
语法:pidof [进程名]
功能:通过进程名, 查看进程id
netstat
netstat是一个用来查看网络状态的重要工具.
语法:netstat [选项]
功能:查看网络状态
常用选项:
n 拒绝显示别名,能显示数字的全部转化成数字
l 仅列出有在 Listen (监听) 的服務状态
p 显示建立相关链接的程序名
t (tcp)仅显示tcp相关选项
u (udp)仅显示udp相关选项
a (all)显示所有选项,默认不显示LISTEN相关
rz/sz
把Linux下的文件放到本地和上传到linux
netstat -anup
[hang@VM-4-12-centos udp]$ netstat -anup
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:68 0.0.0.0:* -
udp 0 0 10.0.4.12:123 0.0.0.0:* -
udp 0 0 127.0.0.1:123 0.0.0.0:* -
udp6 0 0 fe80::5054:ff:fe86::123 ::😗 -
udp6 0 0 ::1:123 ::😗 -
[hang@VM-4-12-centos udp]$

可以查看当前的ip
我们是用来查看我们当前网络链接的。在我们后面讲 TCP 的时候,我会给大家专门来讲指令。今天我们就先把它用一用,它可以用来查看你的本地主机当中的服务器的启动情况和未来链接。你服务器的。如果是 TCP 也可以查有人多少人连你的这样的信息。所以我直接用我们n,我们叫做 n u p n 表示的是能显示成数字,就把输出的内容尽量显示成数字。 u 表示的是 u d p, p 代表的类似于 precise 进程的意思。
ps -aL
查看轻量级进程的选项
g++ -v 查看版本
[hang@VM-4-12-centos day20]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: …/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

pidof 进程名
可以查看当前进程的pid
ulimit -a
查看我们的当前的一些资源配置
[hang@VM-4-12-centos day18]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 7908
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 100001
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 7908
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

修改
[hang@VM-4-12-centos day18]$ ulimit -c 10240
[hang@VM-4-12-centos day18]$ ulimit -a
core file size (blocks, -c) 10240
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 7908
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 100001
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 7908
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

ps -ef | grep 文件名
也可以查看pid
ldd 文件名
查看链接的动态库
ldd 文件名

ipcs
查看众多ipc资源
[hang@VM-4-12-centos day14]$ ipcs -m

------ Shared Memory Segments --------
key shmid owner perms bytes nattch status

-m memory 查看我们的共享内存
-s 信号量
pers为权限,bytes为空间大小,nattch为链接这个共享内存空间的进程数目。
ipcrm -m shmid
删除共享内存

jobs
可以显示后台运行的任务
fg
可以将后台运行的任务强制显示到前台
[hang@VM-4-12-centos day13]$ sleep 10000 | sleep 20000 | sleep 30000 &
[1] 25601
[hang@VM-4-12-centos day13]$ bg 1
-bash: bg: job 1 already in background
[hang@VM-4-12-centos day13]$ jobs
[1]+ Running sleep 10000 | sleep 20000 | sleep 30000 &
[hang@VM-4-12-centos day13]$ fg 1
sleep 10000 | sleep 20000 | sleep 30000
^C
[hang@VM-4-12-centos day13]$

vim 批量注释
esc到命令模式,然后ctrl + v ,进入视图模式。然后hjkl移动选中区域,然后输入 I (大写的I),输入//,然后esc。
vim解除注释
esc到命令模式,然后ctrl + v ,进入视图模式。然后hjkl移动选中区域,然后输入 D,然后esc。
ar -rc(replace and create)
打包生成静态库。

readelf -S 二进制文件
读取二进制
unlink
删除文件,和软硬链接相关。
adduser
增加用户
[root@VM-4-14-centos 8]# adduser suh
[root@VM-4-14-centos 8]# passwd suh
Changing password for user suh.

userdel
删除用户
[root@VM-4-14-centos ~]# userdel -r suh

ls
显示当前路径下的文件名
-a 列出目录下的所有文件,包括以 . 开头的隐含文件。(Linux下是有隐藏文件的)
-l 列出文件的详细信息。
-i 输出文件的 i 节点的索引信息。(查看文件的inode 编号)
[root@VM-4-14-centos 8]# ls
file.txt test1 test2
[root@VM-4-14-centos 8]# ls -l
total 4
-rw-r–r-- 1 root root 11 Aug 8 13:48 file.txt
-rw-r–r-- 1 root root 0 Aug 8 13:56 test1
-rw-r–r-- 1 root root 0 Aug 8 13:56 test2
[root@VM-4-14-centos 8]# ls -a
. … file.txt test1 test2
[root@VM-4-14-centos 8]#
[root@VM-4-14-centos 8]# ls -ial
total 12
659317 drwxr-xr-x 2 root root 4096 Aug 8 13:56 .
657075 drwxr-xr-x 5 root root 4096 Aug 8 13:46 …
659318 -rw-r–r-- 1 root root 11 Aug 8 13:48 file.txt
659319 -rw-r–r-- 1 root root 0 Aug 8 13:56 test1
659320 -rw-r–r-- 1 root root 0 Aug 8 13:56 test2

pwd
显示当前我所处的路径
touch
在当前路径下创建一个普通文件
例:touch test.txt
(第一次 前面现实的是文件的最近修改时间即创建时间;重复touch 更新文件的最近修改时间,更新成为最新的时间。)

mkdir
在当前路径下创建一个目录/文件夹
例:mkdir dir
–p : 递归建立多个目录
(mkdir #创造一个目录 mkdir -p # 创建一串目录)

cd
进入一个路径
例:cd dir
cd … : 返回上级目录
cd /home/litao/linux/ : 绝对路径
cd …/day02/ : 相对路径
cd ~ :进入用户家目(当前用户的工作目录)
cd - :返回最近访问目录(跳转到我上次所处的路径中)
. 表示当前路径。
… 表示直接上级路径。

Linux 的整个目录结构,本质上是一个多叉树结构!!!(a.目录(路上节点) b. 文件或者空目录(叶子节点 ))

文件 = 内容数据 + 属性数据(创建的时间,大小,类型…)

Linux 下隐藏文件/目录(文件夹)的方式,可以让文件以 . 开头。
隐藏文件的基本用途:可以用来隐藏一些配置文件。

绝对路径: 从根目录就开始的定位。
相对路径: 不从根目录开始,而是以当前路径为参考点,这样的定位文件的方式。
绝对路径在日常操作中极少使用,一般是在比较正式的场合,比如在配置文件中…
相对路径在日常中使用较多。

普通用户: / home / XXX 就叫做XXX这个用户的家目录(工作目录)
root用户 : / root

rmdir(rm)
删除 (默认只能删除空目录)
-f 即使文件属性为只读(即写保护),亦直接删除
-i 删除前逐一询问确认
-r 删除目录及其下所有文件
-rf 文件/目录 #删除文件/目录
-rf *.c # * 是一种通配结构
-rf * # -r : 递归 -f :强制

切记 : 禁止 " rm -rf / " . # /是根目录 ,相当于删库。禁止使用!!!

man
man [选项] 命令
访问Linux手册的命令
-k 根据关键字搜索联机帮助
num 只在第num章节找
-a 将所有章节的都显示出来,比如 man printf 它缺省从第一章开始搜索,知道就停止,用a选 项,当按
下q退出,他会继续往后面搜索,直到所有章节都搜素完毕。
解释一下面手册分为8章
1 是普通的命令
2 是系统调用,如open,write之类的(通过这个,至少可以很方便的查到调用这个函数,需要加什么头文
件)
3 是库函数,如printf,fread4是特殊文件,也就是/dev下的各种设备文件
5 是指文件的格式,比如passwd, 就会说明这个文件中各个字段的含义
6 是给游戏留的,由各个游戏自己定义
7 是附件还有一些变量,比如向environ这种全局变量在这里就有说明
8 是系统管理用的命令,这些命令只能由root使用,如ifconfig

cp
复制文件或者是目录。如果是目录,就是 -rf
cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中。若同时指定多个文件或目录,而最后的目的地并非一个已存在的目录,则会出现错误信息
-f 或 --force 强行复制文件或目录, 不论目的文件或目录是否已经存在
-i 或 --interactive 覆盖文件之前先询问用户
-r递归处理,将指定目录下的文件与子目录一并处理。若源文件或目录的形态,不属于目录或符号链接,则一律视为普通文件处理
-R 或 --recursive递归处理,将指定目录下的文件及子目录一并处理

mv
是Linux系统下常用的命令,经常用来备份文件或者目录。也可以将文件改名。(转储特定的文件或者目录到其他的路径下,对一个文件或目录进行重命名)
. 视mv命令中第二个参数类型的不同(是目标文件还是目标目录),mv命令将文件重命名或将其移至一个新的目录中。
2. 当第二个参数类型是文件时,mv命令完成文件重命名,此时,源文件只能有一个(也可以是源目录名),它将所给的源文件或目录重命名为给定的目标文件名。
3. 当第二个参数是已存在的目录名称时,源文件或目录参数可以有多个,mv命令将各参数指定的源文件均移至目标目录中。
-f :force 强制的意思,如果目标文件已经存在,不会询问而直接覆盖
-i :若目标文件 (destination) 已经存在,就会询问是否覆盖。

cat
查看目标文件内容
如果输入tac,则是倒着查看。
-n 对输出的所有行编号。

echo
echo “hello suh” 打印内容到显示器。
echo “hello suh”>file.txt 此处有两个作用:1.创建没有的文件;2.本来应该显示到显示器的内容,被写入到了文件中。

nano 为Linux 的一个记事本

yum install -y nano
yum install -y tree
yum install -y man-pages

输出重定向
1.如果目标文件不存在,就创建该文件。否则直接进行访问。
2.访问
输出重定向 >
从文件开始,覆盖试的写入
追加重定向 >>
从文件的结尾,追加式的写入。

输入重定向
<
[root@VM-4-14-centos 8]# cat < file.txt
hello nano
[root@VM-4-14-centos 8]# cat file.txt
hello nano
[root@VM-4-14-centos 8]# cat
aaa
aaa
bbb
bbb
^C
[root@VM-4-14-centos 8]# cat < file.txt
hello nano

通过cat 理解重定向。cat 可以通过文件名,文件,显示器 读取输入。(原来本该从文件名中读取的内容,变成了其他)

Linux 下一切皆文件。

more
查看代码。
-n 对输出的所有行编号
q 退出more

less
与more 的用法相似,但less更加重要。
less 的用法比起 more 更加的有弹性。在 more 的时候,我们并没有办法向前面翻, 只能往后面看。但若使用了 less 时,就可以使用 [pageup][pagedown] 等按键的功能来往前往后翻看文件,更容易用
来查看一个文件的内容!
-i 忽略搜索时的大小写
-N 显示每行的行号
/字符串:向下搜索“字符串”的功能
?字符串:向上搜索“字符串”的功能
n:重复前一个搜索(与 / 或 ? 有关)
N:反向重复前一个搜索(与 / 或 ? 有关)
j : 回到最前面
q:quit
head / tail
-n<行数> 显示行数
-wc 统计文本行的个数
tail -f 循坏读取

管道文件 | (内存级的文件,没有在磁盘)
[root@VM-4-14-centos 8]# head -1010 file.txt | tail -11

这两者是等价的
后者是通过创建临时文件的方案,来提取中间部分。
前者是利用管道。利用管道可以批量化,流水化的处理数据。

时间
[root@VM-4-14-centos 8]# date +%Y:%m:%d-%H:%M:%S
2022:08:08-17:38:51
[root@VM-4-14-centos 8]# date +%s
1659951557
[root@VM-4-14-centos 8]# date +%Y:%m:%d-%H:%M:%S -d @0
1970:01:01-08:00:00
[root@VM-4-14-centos 8]# date +%Y:%m:%d-%H:%M:%S -d @1659951557
2022:08:08-17:39:17

%X : 相当于 %H:%M:%S
%F : 相当于 %Y-%m-%d

时间戳
时间->时间戳:date +%s
时间戳->时间:date -d@1508749502
Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp)是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒

cal
cal命令可以用来显示公历(阳历)日历。
3 显示系统前一个月,当前月,下一个月的月历
-j 显示在当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)
-y 显示当前年份的日历

如何看待Linux 下的各种命令???其实这些命令本质就是可执行程序(工具,命令,指令)。

alias
给命令起别名
[root@VM-4-14-centos 8]# alias suhang=‘ls’
[root@VM-4-14-centos 8]# suhang
file.txt temp.txt test1 test2 test.txt

find
起始路径 -name 文件名
[root@VM-4-14-centos 8]# tree ~
/root
└── 2022
└── 8
├── 4
│ ├── 5
│ │ ├── file.txt
│ │ ├── hello.c
│ │ ├── test
│ │ └── test2
│ ├── file
│ └── test
├── 5
│ ├── file.txt
│ ├── hello.c
│ ├── test
│ └── test2
└── 8
├── file.txt
├── temp.txt
├── test1
├── test2
└── test.txt

6 directories, 15 files
[root@VM-4-14-centos 8]# find ~ -name hello.c
/root/2022/8/4/5/hello.c
/root/2022/8/5/hello.c

which
在系统路径中查找特定的指令所在的路径。
[root@VM-4-14-centos 8]# which ls
alias ls=‘ls --color=auto’
/usr/bin/ls

whereis
在系统路径中查找所有含 — 的文件

[root@VM-4-14-centos 8]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

grep
行文本过滤工具
i :忽略大小写的不同,所以大小写视为相同
-n :顺便输出行号
-v :反向选择,亦即显示出没有”搜寻字符串“内容的那一行
-E选项可以用来扩展选项为正则表达式;

xargs
将管道的输出结果作为命令行参数交给后面的程序。
[root@VM-4-14-centos 8]# ls -al
total 16
drwxr-xr-x 2 root root 4096 Aug 8 17:31 .
drwxr-xr-x 5 root root 4096 Aug 8 13:46 …
-rw-r–r-- 1 root root 11 Aug 8 13:48 file.txt
-rw-r–r-- 1 root root 11 Aug 8 17:31 temp.txt
-rw-r–r-- 1 root root 0 Aug 8 13:56 test1
-rw-r–r-- 1 root root 0 Aug 8 13:56 test2
-rw-r–r-- 1 root root 0 Aug 8 14:35 test.txt

[root@VM-4-14-centos 8]# echo “-al” | xargs ls
total 16
drwxr-xr-x 2 root root 4096 Aug 8 17:31 .
drwxr-xr-x 5 root root 4096 Aug 8 13:46 …
-rw-r–r-- 1 root root 11 Aug 8 13:48 file.txt
-rw-r–r-- 1 root root 11 Aug 8 17:31 temp.txt
-rw-r–r-- 1 root root 0 Aug 8 13:56 test1
-rw-r–r-- 1 root root 0 Aug 8 13:56 test2
-rw-r–r-- 1 root root 0 Aug 8 14:35 test.txt

将我们的文件时间更新

yum install -y unzip zip
yum install -y epel-release
打包和压缩
zip/unzip
zip -r name.zip 你的目录。
unzip name.zip #当前路径下
unzip name.zip -d 指定的路径下。
tar
-f :使用档名,请留意,在 f 之后要立即接档名喔!不要再加参数!
-C : 解压到指定目录
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?
-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩
-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程
-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfifile 里面的文件!

[root@VM-4-14-centos 8]# tar -czvf test.tgz test.txt
test.txt
[root@VM-4-14-centos 8]# tar -czf test.tgz test.txt

[root@VM-4-14-centos 8]# tar -xzvf test.tgz
test.txt
[root@VM-4-14-centos 8]# tree
.
├── file.txt
├── file.zip
├── my
│ └── file.txt
├── temp.txt
├── test1
├── test2
├── test.tgz
└── test.txt

1 directory, 8 files
[root@VM-4-14-centos 8]# tar -xzvf test.tgz -C ./my
test.txt
[root@VM-4-14-centos 8]# tree
.
├── file.txt
├── file.zip
├── my
│ ├── file.txt
│ └── test.txt
├── temp.txt
├── test1
├── test2
├── test.tgz
└── test.txt

1 directory, 9 files

面试问题:请问如何在liunx下查看当前linux的体系结构,以及内核版本??
[root@VM-4-14-centos 8]# uname -a
Linux VM-4-14-centos 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

体系结构在内核版本之后 就是x64
内核版本
[root@VM-4-14-centos 8]# uname -r
3.10.0-1160.11.1.el7.x86_64

[Tab]按键—具有『命令补全』和『档案补齐』的功能
[Ctrl]-c按键—让当前的程序『停掉』
[Ctrl]-d按键—通常代表着:『键盘输入结束(End Of File, EOF 戒 End OfInput)』的意思;另外,他也可以用来取代exit
Ctrl + r 进入历史搜索。

top
linux查看cpu占用的命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值