Linux命令

修改主机名

centos7
1、方法一使用hostnamectl命令
[root@bogon ~]# hostnamectl set-hostname NMServer-7.test.com

2、方法二:修改配置文件 /etc/hostname 保存退出
[root@bogon ~]# vi /etc/hostname

nmserver-7.test.com
:wq
[root@bogon ~]# reboot

centos 6

[hadoop@lxjserver ~]$ vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=lxjserver

同时也修改下
[hadoop@lxjserver ~]$ vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 lxjserver
192.168.1.200 lxjserver
192.168.1.200 localhost
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

find ./ -size -20k -exec ls -lh {} ;

find /var/mail/ -size +50M -exec rm {} \;

查看端口 占用: lsof -i:8000

netstat -pan|grep 177 //查看177端口情况

查看端口 ss -nltp ss -ntlu

cp -av a.txt{,.bak}
‘a.txt’ -> ‘a.txt.bak’

ss -ntlu | egrep “137|138|139|445”

systemctl stop NetworkManager.service	//必关
systemctl disable NetworkManager.service		//禁掉开机启动

[root@nginx ~]# cat /etc/RedHat-release
CentOS release 6.8 (Final)

echo “unset MAILCHECK”>> /etc/profile

当天每10分钟的信息 CPU利用率信息、内存换页信息、网络IO传输信息、进程创建行为和存储设备行为

[root@localhost log]# sar
Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 2017年11月23日 x86_64 (4 CPU)

00时00分01秒 CPU %user %nice %system %iowait %steal %idle
00时10分01秒 all 4.82 0.00 2.31 0.32 0.00 92.55

scp
你可以设置显示每个服务器的CPU统计信息,或者每个处理的CPU统计信息。

mpstat -P ALL

总核数 = 物理CPU个数 X 每颗物理CPU的核数

总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

查看物理CPU个数

cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l

查看每个物理CPU中core的个数(即核数)

cat /proc/cpuinfo| grep “cpu cores”| uniq

查看逻辑CPU的个数

cat /proc/cpuinfo| grep “processor”| wc -l

查看CPU信息(型号)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
赋予最高权限:
995 adduser roottest
996 passwd roottest
997 vim /etc/sudoers
998 usermod -g root roottest
删除用户:

zip -z test.zip test.log #将test.log加入到test.zip中
unzip test.zip #解压test.zip
diff index.jsp newIndex.jsp #比较两个文件不同

检测本机已有应用和端口 netstat
考虑再三,还是放上这条命令。
netstat用途,用于查看已开启的端口

netstat -tln

mkdir -p cms/content/logs #创建多层目录
chown test:test config.properties #更换文件的用户权限
chgrp -v test config.properties #更换文件的所属组
scp test.log root@192.168.220.123:/root/ #将文件拷贝到远程服务器

lsof -i:端口号查看某个端口是否被占用

0 系统停止
1 单用户系统,不需要登陆
2 多用户系统但不支持NFS,命令行模式登陆—NFS(Network File System)即网络文件系统
3 完整多用户模式,命令行模式登陆
4 未用
5 X11图形模式,图形模式登陆
6 重新启动系统

二、复制多行
任务:将第9行至第15行的数据,复制到第16行

方法1:(强烈推荐)
:9,15 copy 16 或 :9,15 co 16
由此可有:
:9,15 move 16 或 :9,15 m 16 将第9行到第15行的文本内容到第16行的后面

yum install dstat
dstat -cdngy

cpu:hiq、siq分别为硬中断和软中断次数。 system:int、csw分别为系统的中断次数(interrupt)和上下文切换(context switch)。
-c cpu是也,显示CPU系统占用,用户占用,空闲,等待,中断,软件中断等信息
-d disk是也,显示磁盘读写数据大小
-n net 显示网络状态
-l load average 显示系统负载情况
-m memory 显示内存使用情况
-g page 显示页面使用情况
-p process 显示进程状态
-s swap 显示交换分区使用情况
-r I/O请求情况
-y syste

useradd -M -s /sbin/nologin user
-M:不创建家目录
-s:指定用户登陆时使用的shell,nologin就是登陆不了

http://www.linuxprobe.com/news

centos 7
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

http://www.linuxidc.com/Linux/2015-05/117473.htm

[root@Nginx vhosts]# netstat -pan | grep 8088
tcp 0 0 :::8088 ::😗 LISTEN 27414/java
[root@Nginx vhosts]# ps -ef | grep 27414

设置允许8087端口:
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8087 -j ACCEPT
/etc/rc.d/init.d/iptables save

du -ah --max-depth=1 这个是我想要的结果 a表示显示目录下所有的文件和文件夹(不含子目录),h表示以人类能看懂的方式,max-depth表示目录的深度。http://www.cnblogs.com/kobe8/p/3825461.html

du -sh *

查看Linux版本
lsb_release -a
uname -a cat /etc/redhat-release
cat /proc/version
cat /etc/issue

查询当前目录的文件并以升序排列:ll -t | tac

iotop

😒/old/new 将光标所在行第一个 old 替换为 new
😒/old/new/g 将光标所在行所有 old 替换为 new
:%s/old/new/gc 全文执行替换,询问是否替换
:3,10s/old/new/gic 将第3行到第10行内容替换,忽略大小写,且每个询问是否替换

[root@vw010001134191 ~]# dstat -tclmdny 1
Terminal width too small, trimming output.
----system---- ----total-cpu-usage---- —load-avg— ------memory-usage----- -dsk/total->
date/time |usr sys idl wai hiq siq| 1m 5m 15m | used buff cach free| read writ>
09-01 14:51:14| 0 0 100 0 0 0|0.07 0.03 0|1067M 347M 3955M 2504M| 11k 29k>
09-01 14:51:15| 0 0 100 0 0 0|0.07 0.03 0|1067M 347M 3955M 2504M| 0 0 >

[root@vw010001134191 ~]# vmstat
procs -----------memory---------- —swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 22516 2567976 355380 4050376 0 0 3 7 1 1 0 0 100 0 0
[root@vw010001134191 ~]# dstat -a
----total-cpu-usage---- -dsk/total- -net/total- —paging-- —system–
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
0 0 100 0 0 0| 11k 29k| 0 0 | 6B 14B| 171 182
0 0 100 0 0 0| 0 0 | 65k 842B| 0 0 | 185 94 ^C

[root@vw010001134191 ~]# mpstat
Linux 2.6.32-431.el6.x86_64 (vw010001134191) 01/09/2017 x86_64 (4 CPU)

02:58:34 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
02:58:34 PM all 0.12 0.00 0.04 0.01 0.00 0.00 0.00 0.00 99.84

[root@vw010001134191 ~]# vmtouch
vmtouch: no files or directories specified

vmtouch v1.1.0 - the Virtual Memory Toucher by Doug Hoyte
Portable file system cache diagnostics and control

Usage: vmtouch [OPTIONS] … FILES OR DIRECTORIES …

Options:
-t touch pages into memory
-e evict pages from memory
-l lock pages in physical memory with mlock(2)
-L lock pages in physical memory with mlockall(2)
-d daemon mode
-m max file size to touch
-p use the specified portion instead of the entire file
-f follow symbolic links
-h also count hardlinked copies
-w wait until all pages are locked (only useful together with -d)
-v verbose
-q quiet

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值