Practical Linux commands and basic common sense -3

Content:
✔ directory operations
✔ text processing
✔ compression
✔ daily operation and maintenance
✔ System Status Overview

Directory Operations

Create a directory mkdir dir the make
cp copy files Copy
mv move files the Move
RM remove deleted files

例子:
	创建目录和父目录a,b,c,d
	 	mkdir -p a/b/c/d

	拷贝文件夹a到/tmp目录
		cp -rvf a/ /tmp/

	移动文件a到/tmp目录,并重命名为b
		 mv -vf a /tmp/b

	 删除机器上的所有文件
		 rm -rvf /

ls command to be able to see all the contents of the current directory. ls -l to see more information, to determine who you are.
pwd command to see the directory of the current terminal is located. Tell you where you are.
cd If you go to the wrong place, cd command to switch to the directory pair.
find find command by screening a number of conditions, to find a file that has been forgotten.

View files
cat

	最常用的就是cat命令了,注意,如果文件很大的话,cat命令的输出结果会疯狂在终端上输出,可以多次按ctrl+c终止。

you -h file

	查看文件大小

cat file

	查看文件内容

less

	既然cat有这个问题,针对比较大的文件,我们就可以使用less命令打开某个文件。
类似vim,less可以在输入/后进入查找模式,然后按n(N)向下(上)查找。
有许多操作,都和vim类似,你可以类比看下。

tail

查看nginx的滚动日志。
	tail -f access.log
		tail命令可以静态的查看某个文件的最后n行,与之对应的,head命令查看文件头n行。但head没有滚动功能,就像尾巴是往外长的,
	不会反着往里长。
	
		tail -n100 access.log
		head -n100 access.log

grep

grep用来对内容进行过滤,带上--color参数,可以在支持的终端可以打印彩色,参数n则输出具体的行数,用来快速定位。
	比如:查看nginx日志中的POST请求。
	grep -rn --color POST access.log
推荐每次都使用这样的参数。
如果我想要看某个异常前后相关的内容,就可以使用ABC参数。它们是几个单词的缩写,经常被使用。
	A  after  内容后n行
	B  before  内容前n行
	C  count?  内容前后n行
		就像是这样:
			grep -rn --color Exception -A10 -B2   error.log

diff

	diff命令用来比较两个文件是否的差异。当然,在ide中都提供了这个功能,diff只是命令行下的原始折衷。
和patch还是一些平台源码的打补丁方式,你要是不用,就pass吧。

compression

.tar compression or decompression using the tar command
.bz2 operation command with bzip2
.gz with gzip command operations
.zip use the unzip command to extract
.rar use the command to extract unrar

创建压缩文件
	tar cvfz  archive.tar.gz dir/
解压
	tar xvfz. archive.tar.gz

**

Daily operation and maintenance

**
mount

mount命令可以挂在一些外接设备
	mount /dev/sdb1 /xiaodianying

chown

chown 用来改变文件的所属用户和所属组。
chmod 用来改变文件的访问权限。
这两个命令,都和linux的文件权限有关。
示例:
	毁灭性的命令
		chmod 000 -R /
	
	 修改a目录的用户和组为 xjj
		chown -R xjj:xjj a
	
	 给a.sh文件增加执行权限(这个太常用了)
		chmod a+x a.sh

System Status Overview

uname

uname命令可以输出当前的内核信息,让你了解到用的是什么机器。
uname -a

ps

ps命令能够看到进程/线程状态。和top有些内容重叠,常用。
 	找到java进程
		ps -ef|grep java

top

系统状态一览,主要查看。cpu load负载、cpu占用率。使用内存或者cpu最高的一些进程。下面这个命令可以查看某个进程中的线程状态。
	top -H -p pid

free

top也能看内存,但不友好,free是专门用来查看内存的。包括物理内存和虚拟内存swap。

df

df命令用来查看系统中磁盘的使用量,用来查看磁盘是否已经到达上限。参数h可以以友好的方式进行展示。
	df -h

netstat

虽然ss命令可以替代netstat了,但现实中netstat仍然用的更广泛一些。比如,查看当前的所有tcp连接。
	netstat -ant
Published 18 original articles · won praise 16 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_44569012/article/details/100943197