Shopify Free Trial Apply
Shopify 60天试用
Shopify 14天试用

常用Linux命令行收藏

LINUX常用命令收藏:
因为关闭了sendmail以后,删除/var/spool/clientmqueue/底下大量的邮件信息的命令:
find /var/spool/clientmqueue/ -type f -exec rm {} \+
经常需要在centos服务器上的项目文件里做给予文件夹和文件不同权限的操作,如果挨个给,几千个文件绝无可能,于是乎命令行成了最好的方式。
假设之前为了某些权限问题,直接给予了所有文件跟文件夹777的权限,现在想恢复到之前文件夹是755,文件是644的权限,可以通过以下命令行来实现:
    find . -type d -exec chmod 755 {} \;
    find . -type f -exec chmod 644 {} \;
第一个命令是查找所有的文件夹并强制给予755的权限,第二个命令是查找所有的文件并强制给予644的权限。
以下命令可拷贝隐藏文件:
yes | cp -a new/files/* files

192.81.132.6
压缩包含隐藏文件:
zip -r 1.zip .
解压缩 .tgz 文件
gtar xvzf file.TGZ
执行以下命令查看当前占用了88端口的进程是哪个进程netstat -ltnp | grep ':88'tcp 0 0 :::88 :::* LISTEN 3697/httpd
由上边可以看出占用88端口的是3697/httpd,因此执行以下命令杀死这个进程,然后再次重启apache就可以了:
# kill -9 3697
# service httpd restart
WordPress数据库命令行备用:
update  wp_options set option_value=replace( option_value ,'http://www.iwiss.com','https://www.iwiss.com')

update wp_posts set post_content=replace(post_content,'http://yhzxcrystal.eastdesign.net/','http://www.yhzxcrystal.com/')
update wp_posts set guid=replace(guid,'http://eaqlighting.eastdesign.net/','http://cn-eaqlighting.eastdesign.net/')

update wp_posts set post_content=replace(post_content, 'http://oceanmarine.good-ocean.com','https://www.grandoceanmarine.com')
update wp_postmeta set meta_value=replace(meta_value,'http://iirain.eastdesign.net/','http://itiirain.eastdesign.net/')

The 'host' command is a DNS lookup utility. It shouldn't be active as a process like you've described. Is there a cron entry or some script that is executing it? You can tell with the command:

ps auxf | grep -i host | grep -v grep

The column on the far left should be the user executing it.
su - www
crontab -l

You might also check for other processes started by the 'www' user:

ps auxf | grep -i www
grep -i "host" /www/wdlinux/wdcp/task/*.php

zip命令排除子文件夹不要被压缩的命令如下:
zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*
centos OOMing 解决方案:
https://library.linode.com/tro ... rking
每一秒返回一次系统负载:
vmstat 10
查看apache 进程数:
ps -ef|grep httpd|wc -l
按照内存使用量倒序排列:
ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less
Apache 内存被耗光以后处理方法:
netstat -ltnp | grep ':88’

列出所有占用88端口的PID,比如这里列出的PID为3697接着用下列命令杀死这个进程:

kill -9 3697

然后重启httpd 就可以了

service httpd restart

列出当前文件夹目录大小,以G,M,K显示。
du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf"%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"):$1>=2**10? ($1/2**10, "K"): ($1, "")}e'
查询大小超过100m的文件 
find / -type f -size +100000k -ls一:查看cpu

more /proc/cpuinfo | grep “model name”
grep “model name” /proc/cpuinfo

如果觉得需要看的更加舒服

grep “model name” /proc/cpuinfo | cut -f2 -d:

二:查看内存

grep MemTotal /proc/meminfo

grep MemTotal /proc/meminfo | cut -f2 -d:

free -m |grep “Mem” | awk ‘{print $2}’

三:查看cpu是32位还是64位

查看CPU位数(32 or 64)

getconf LONG_BIT

四:查看当前linux的版本

more /etc/redhat-release
cat /etc/redhat-release

五:查看内核版本

uname -r

uname -a

六:查看当前时间,如果不对则设置为北京时间

date
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate us.pool.ntp.org
没有安装ntpdate的可以yum一下:
yum install -y ntpdate

加入定时计划任务,每隔10分钟同步一下时钟
crontab -e
0-59/10 * * * * /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP

上面已经介绍如何同步时间了,

七:查看硬盘和分区

df -h

fdisk -l

也可以查看分区

du -sh

可以看到全部占用的空间

du /etc -sh

可以看到这个目录的大小

du –max-depth=1 -h

查看各个目录占用空间大小

八:查看安装的软件包

查看系统安装的时候装的软件包

cat -n /root/install.log

more /root/install.log | wc -l

查看现在已经安装了那些软件包

rpm -qa

rpm -qa | wc -l

yum list installed | wc -l

不过很奇怪,我通过rpm,和yum这两种方式查询的安装软件包,数量并不一样。没有找到原因。

九:查看键盘布局

cat /etc/sysconfig/keyboard

cat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=

十:查看selinux情况

sestatus

sestatus | cut -f2 -d:

cat /etc/sysconfig/selinux

十一:查看ip,mac地址

在ifcfg-eth0 文件里你可以看到mac,网关等信息。

ifconfig

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d=

ifconfig eth0 |grep “inet addr:” |awk ‘{print $2}’|cut -c 6-

ifconfig   | grep ‘inet addr:’| grep -v ’127.0.0.1′ | cut -d: -f2 | awk ‘{ print $1}’

查看网关

cat /etc/sysconfig/network

查看dns

cat /etc/resolv.conf

十二:查看默认语言

echo $LANG $LANGUAGE

cat /etc/sysconfig/i18n

十三:查看所属时区和是否使用UTC时间

cat /etc/sysconfig/clock

十四:查看主机名

hostname

cat /etc/sysconfig/network

修改主机名就是修改这个文件,同时最好也把host文件也修改。

十五:如何杀死mysql进程

pkill mysqld

十六:查询大小超过100m的文件

find / -type f -size +100000k -ls

十七:开机自启动设置

编辑rc.local文件
#vim /etc/rc.d/rc.local

# du -sh # 查看指定目录的大小

# uptime # 查看系统运行时间、用户数、负载

# cat /proc/loadavg # 查看系统负载

# iptables -L # 查看防火墙设置
# route -n # 查看路由表
# netstat -lntp # 查看所有监听端口
# netstat -antp # 查看所有已经建立的连接
# netstat -s # 查看网络统计信息

# w # 查看活动用户
# id # 查看指定用户信息
# last # 查看用户登录日志
# cut -d: -f1 /etc/passwd # 查看系统所有用户
# cut -d: -f1 /etc/group # 查看系统所有组
# crontab -l # 查看当前用户的计划任务
# chkconfig –list # 列出所有系统服务
# chkconfig –list | grep on # 列出所有启动的系统服务

linux CentOS5.4如何修改主机名

一:使用hostname命令
[root@test ~]# hostname yourname
这样只是临时更改了主机名。
二: 修改linux主机的配置文件/etc/sysconfig/network 和 /etc/hosts
1.修改/etc/sysconfig /network里面的主机名字。
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=yourname                //在这修改hostname
GATEWAY=192.168.1.1
2.修改/etc/hosts里面 的名字
# vi /etc/hosts
127.0.0.1              localhost.localdomain localhost
192.168.1.121          yourname //在这修改hostname
//有时候只有这一 行
127.0.0.1              yourname localhost.localdomain localhost
3. 让更改的名字在不重启机器下生效
# hostname yourname
# su
0
2018-01-30

0 个评论

要回复文章请先登录注册