自用命令收藏
linux 下 crontab 定时命令
linux 下 crontab 定时命令
创建添加定时任务命令:
crontab -e
格式如下:
分 小时 日 月 星期 命令(0 表示周日,*表任意一天)
0-59 0-23 1-31 1-12 0-6 命令
转换文件成 unix 格式:
vi 需要转换的文件,命令模式下输入:set ff=unix 设置文件为 unix,然后执行:wq,保存成 unix 格式
Linux 下创建和删除用户
useradd 所要创建的用户名 passwd 所要创建的用户名 vim /etc/sudoers 添加管理员权限 Allow root to run any commands anywhere root ALL=(ALL) ALL 【用户名】 ALL=(ALL) ALL
关闭 php 错误信息显示
1,打开 PHP.ini,找到 display_errors,将后面的值改为 off,同时设置 error_reporting 为 E_ALL。
display_errors = Off error_reporting = E_ALL
2,或者:
display_errors = Off error_reporting = E_ALL & ~E_NOTICE
3,注意:如果设置 display_errors = Off 不起效的话,请将 log_errors 设置为 Off
linux 下默认编码修改
vim /etc/sysconfig/i18n LANG=zh_CN.UTF-8 SYSFONT=lat0-sun16
或者
vim /etc/locale.conf source /etc/locale.conf //生效
Ubuntu修改系统默认编码
vim /etc/default/locale LANG="zh_CN.UTF-8"
转载至:Ubuntu修改系统默认编码 – 紫穹 – OSCHINA
Linux 下修改 Mysql 的用户(root)的密码
方法 1:在 mysql 系统外,使用 mysqladmin
mysqladmin -u root -p password "新密码" Enter password: 【输入原来的密码】
方法 2:通过登录 mysql 系统
mysql -uroot -p Enter password: 【输入原来的密码】 mysql>use mysql; mysql> update user set password=passworD("新密码") where user='root'; mysql> flush privileges; mysql> exit;
忘记原来的 myql 的 root 的密码
/etc/init.d/mysqld stop 或者 service mysqld stop mysqld_safe --skip-grant-tables & //& 表示在后台运行,不再后台运行的话,就再打开一个终端 mysql mysql> use mysql; mysql> UPDATE user SET password=password("新密码") WHERE user='root'; mysql> flush privileges; mysql> exit;
CentOS 自带 apache 卸载
yum -y remove httpd 或者 yum remove httpd* php* mysql* -y
httpd 依赖全部卸载
linu环境变量设置
临时环境变量(重启后消失):
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
永久环境变量
1.修改 profile 文件:(所有用户)
vim /etc/profile export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
2.修改.bashrc 文件:(单独用户)
vim .bash_profile // (每个用户目录下都有,ls -all) export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 重启系统或者输入命令 source .bash_profile 生效。
linux nano编辑器
nano安装
CentOS 系统:
yum install nano -y
Debian/Ubuntu 系统:
apt-get install nano -y
nano基础使用方法
1,打开方法
nano 文件名或文件绝对路径 例如: nano /root/doubi.txt nano doubi.txt
注意:当你打开一个不存在的文件,那么即为新建文件。
当你打开/新建一个文件后,就可以直接编辑文件了。
2,保存退出
保存快捷键 Ctrl+O
,会提示你要保存的文件名,默认是当前文件名,你可以改成其他文件名,或者直接回车表示覆盖当前文件。
在提示保存文件名的界面下,按下快捷键 Ctrl+C
,即代表取消当前操作,返回编辑界面。
退出快捷键 Ctrl+X
,将退出编辑,如果你已经修改了文件,那么就会提示你是否保存文件内容。
如果编辑时改错内容了,那么可以选择不保存,即输入 N (大小写均可)。
如果要保存文件内容,则输入 Y (大小写均可),这时候就会如上面的保存文件时一样,提示你要保存的文件名,默认是当前文件名,你可以改成其他文件名,或者直接回车表示覆盖当前文件。
转载自:Linux 更适合新手的文本编辑器 nano 真 · 简单使用教程
CentOS7使用firewalld打开关闭防火墙与端口
1:firewalld的基本使用
systemctl start firewalld //启动 systemctl stop firewalld //关闭 systemctl status firewalld //查看状态 systemctl disable firewalld //开机禁用 systemctl enable firewalld //开机启用
2:systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
systemctl start firewalld.service //启动一个服务 systemctl stop firewalld.service //关闭一个服务 systemctl restart firewalld.service //重启一个服务 systemctl status firewalld.service //显示一个服务的状态 systemctl enable firewalld.service //在开机时启用一个服务 systemctl disable firewalld.service //在开机时禁用一个服务 systemctl is-enabled firewalld.service //查看服务是否开机启动 systemctl list-unit-files|grep enabled //查看已启动的服务列表 systemctl --failed //查看启动失败的服务列表
3:配置firewalld-cmd
firewall-cmd --version //查看版本 firewall-cmd --help //查看帮助 firewall-cmd --state //显示状态 firewall-cmd --zone=public --list-ports //查看所有打开的端口 firewall-cmd --reload //更新防火墙规则 firewall-cmd --get-active-zones //查看区域信息 firewall-cmd --get-zone-of-interface=eth0 //查看指定接口所属区域 firewall-cmd --panic-on //拒绝所有包 firewall-cmd --panic-off //取消拒绝状态 firewall-cmd --query-panic //查看是否拒绝
4:开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent //端口开启 //--permanent永久生效,没有此参数重启后失效 firewall-cmd --reload //重新载入 firewall-cmd --zone= public --query-port=80/tcp //查看 firewall-cmd --zone= public --remove-port=80/tcp --permanent //删除
转载自:CentOS7使用firewalld打开关闭防火墙与端口 – 莫小安 – 博客园
linux下解除端口占用
lsof -i:端口 //需要解除的端口 kill -9 pid
转载自:linux下解除端口占用
CentOS7安装iptables防火墙
安装iptable iptable-service
service iptables status //检查iptables状态 yum install -y iptables //安装 yum update iptables //升级 yum install iptables-services //安装iptables-services
禁用/停止自带的firewalld服务
systemctl stop firewalld //停止 systemctl mask firewalld //禁用
设置现有规则
iptables -L -n //查看iptables现有规则 iptables -P INPUT ACCEPT //先允许所有,不然有可能会杯具 iptables -F //清空默认规则 iptables -X //清空自定义规则 iptables -Z //所有计数器归0 iptables -A INPUT -i lo -j ACCEPT //允许来自于lo接口的数据包(本地访问) iptables -A INPUT -p tcp --dport 22 -j ACCEPT //开放22端口 iptables -A INPUT -p tcp --dport 21 -j ACCEPT //开放21端口 iptables -A INPUT -p tcp --dport 80 -j ACCEPT //开放80端口 iptables -A INPUT -p tcp --dport 443 -j ACCEPT //开放443端口 iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT //允许ping iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT //允许接受本机请求之后的返回数据 RELATED,是为FTP设置的 iptables -P INPUT DROP //其他入站一律丢弃 iptables -P OUTPUT ACCEPT //所有出站一律绿灯 iptables -P FORWARD DROP //所有转发一律丢弃 iptables -A INPUT -p tcp -s 信任ip地址 -j ACCEPT //如果要添加内网ip信任(接受其所有TCP请求) iptables -P INPUT DROP //过滤所有非以上规则的请求 iptables -I INPUT -s ***.***.***.*** -j DROP //禁止ip iptables -D INPUT -s ***.***.***.*** -j DROP //解封ip service iptables save //保存 systemctl enable iptables.service //自启iptables服务,相当于以前的chkconfig iptables on systemctl start iptables.service //开启 systemctl status iptables.service //查看状态
screen命令
1:创建screen
screen -S screen1 此时已经创建并且进入screen1中
2:挂起screen
在进入screen的前提下,
先按键 ctrl+a
,再按 d
即可挂起(Detached)
3:查看screen
screen -ls
4:进入挂起(Detached)的screen
screen -r screen1
进入前screen状态为(Detached),进入后screen状态变为(Attached).如果要进入(Attached)状态的screen,会报错There is no screen to be resumed matching screen1
screen -d screen1
强制Detached这个screen,正在使用的人会断开,他断开后screen变为(Detached)状态,你可screen -r screen1
了
5:退出
exit
进入后exit
直接退出,相当于删除
转载自:screen命令 – 来看看博客 – 博客园
screen简单命令
#=================新建================= # screen -S 窗口名字 #创建一个窗口,注意观看终端的最上面标题 # 之后我们想暂时退出做点别的事情,比如出去散散步,那么在screen窗口键入C-a d,Screen会给出detached提示,ctrl+a后马上ctrl+d就会挂起 #=================恢复================= # screen -ls #半个小时之后回来了,找到该screen会话: # screen -r 窗口名字 #=================删除================= # kill -9 窗口名称前的pid # screen -wipe #清除会话为dead状态的窗口
转载至:screen挂起的使用 – 简书
linux下批量去掉文件名后缀多余字符
find . -name '*.mp4?*' -type f|awk '{print $1}'|xargs rm -rf