ll命令
alias ll="ls -l"
linux如何查看端口被哪个进程占用?
1、lsof -i:端口号
2、netstat -tunlp|grep 端口号
3、sudo netstat -lpn4 查看所有用户程序使用的端口
只显示文件夹
ls -ld */
显示本目录中的文件和文件夹个数:
ls|wc -w
Grep 排除多个条件
grep -v 'aaaa\|bbbb\|cccc'
批量替换文件中的内容,子文件夹同样有效
sed -i "s/22222/11111/g" `find . -name "*.txt"`
删除 当前目录中 30 天前的文件
find . -mtime +30 -name "*.*" -exec rm -rf {} \;
从apache日志中统计来源IP访问数量, 并保存到 1.txt 文件中
gawk '{print $1}' down.zwcad.com-access_20130325.log |sort|uniq -c|sort -n -r > ~/1.txt
删除.svn目录
find . -type d -name ".svn"|xargs rm -rf
把当前目录下的所有子目录(非文件)的权限改成 755.
find . -type d -exec chmod 755 {} \;
把当前目录下的所有文件(非目录)的权限改成 644
find . -type f -exec chmod 644 {} \;
批量改变编码:
yum install enca
enca -L zh_CN -x utf-8 *
应用到子目录
find -type f -name "*.html" -exec enca -L zh_CN -x utf-8 {} \;
统计当前文件夹下文件的个数
ls -l |grep "^-"|wc -l
统计当前文件夹下目录的个数
ls -l |grep "^d"|wc -l
统计当前文件夹下文件的个数,包括子文件夹里的
ls -lR|grep "^-"|wc -l
统计文件夹下目录的个数,包括子文件夹里的
ls -lR|grep "^d"|wc -l
Selinux 设置
临时修改SELINUX级别:
setenforce 0 #设置为 permissive 级别。 setenforce 1 :设置为 enforcing 级别
getenforce #查看当前级别
HTTP 设置有效目录
setsebool -P httpd_enable_homedirs true
chcon -R -t httpd_sys_content_t /home/testuser/public_html
或者
semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
#列出列表
semanage fcontext --list|grep httpd
开启代理
setsebool -P httpd_can_network_connect 1
HTTP设置images读写目录
chcon -R -t httpd_sys_script_rw_t images
semanage 安装
yum install policycoreutils-python
SSH 改变端口 to 2292
semanage port -a -t ssh_port_t -p tcp 2292
查看seliunx开启的端口号
semanage port -l | grep ssh
删除端口号
semanage port -d -t ssh_port_t -p tcp 2292 #不可以删除系统默认的22
Mysql 改变存储路径为 /home/data
semanage fcontext -a -t mysqld_db_t "/home/data(/.*)?"
#httpd conf文件为 httpd_config_t
restorecon -Rv /home/data
check SELinux
sestatus
查看HTTP状态
getsebool -a | grep httpd
To allow Apache to connect to remote database through SELinux
setsebool httpd_can_network_connect_db 1 #临时
setsebool -P httpd_can_network_connect_db 1 #永久
改变文件或目录权限:
chcon -R -u system_u -t httpd_sys_content_t /srv/vhosts
挂载硬盘
mount -o context=system_u:object_r:var_t:s0 /dev/xvdf /www
vi etc/fstab
# 在最后一行添加代码:
/dev/xvdf /www ext4 defaults 0 0
查看挂载盘的文件格式
# file -sL /dev/xvd*
Linux SSH 特殊配置
SELINUX for SSH port to 2292
semanage port -a -t ssh_port_t -p tcp 2292
/etc/ssh/sshd_config 配置
PermitRootLogin no #禁止Root远程登入
DenyUsers ison #指定不允许ison远程登入,但能本地登入,其他用户不受影响
AllowUsers ison admin #只允许 ison 和 admin 远程登入,其他用户只能本地登入