欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux 的常用小技巧

程序员文章站 2024-02-21 23:33:46
...

1、统计文件的行数
<pre>
[[email protected] dbgen]# wc -l partsupp.tbl
80000000 partsupp.tbl
[[email protected] dbgen]# wc -l orders.tbl
150000000 orders.tbl
</pre>
wc 还有其他的一些参数:
语法:wc [选项] 文件…

说明:该命令统计给定文件中的字符数、字数、行数。如果没有给出文件名,则从标
准输入读取。wc同时也给出所有指定文件的总统计数。字是由空格字符区分开的最大字符串。
该命令各选项含义如下:

  • c 统计字符数。
  • l 统计行数。
  • w 统计字数。

这些选项可以组合使用。
输出列的顺序和数目不受选项的顺序和数目的影响。
总是按下述顺序显示并且每项最多一列。
行数、字数、字符数、文件名
如果命令行中没有文件名,则输出中不出现文件名。

另外针对命令也可以增加wc -l,例如查看一下当前80端口的连接情况:
netstat -an|grep 80|wc -l

2、用户如果出现资源不够,执行su - user也出错:
su: cannot set user id: Resource temporarily unavailable
需要检查/etc/security/limits.conf
<pre>
vi /etc/security/limits.conf

End of file

  •            soft    nproc           655360
    
  •            hard    nproc           655360
    
  •            soft    nofile          655360
    
  •            hard    nofile          655360
    

</pre>
分布式环境下资源使用的很多,默认设置远远不够

3、简单的针对某个ip进行iptables设置:
iptables -I INPUT -s 121.0.0.34 -j DROP
4、设置密码的安全策略
Debian、Ubuntu 或 Linux Mint 系统上:
<pre>
[email protected]:~# vi /etc/pam.d/common-password
password requisite pam_pwquality.so enforce_for_root retry=3 minlen=8 ucredit=-1 lcredit=-1 dcredit=-1 difok=3
</pre>
它表示密码必须至少包含一个大写字母(ucredit),一个小写字母(lcredit),一个数字(dcredit)
ocredit:标点符号
difok:字符种类
minlen:密码长度

CentOS、Fedora、RHEL 系统上:
<pre>
vi /etc/pam.d/system-auth
password requisite pam_cracklib.so try_first_pass retry=3 type=
</pre>
设置密码过期期限
编辑 /etc/login.defs 文件
<pre>

Password aging controls:

PASS_MAX_DAYS Maximum number of days a password may be used.

PASS_MIN_DAYS Minimum number of days allowed between password changes.

PASS_WARN_AGE Number of days warning given before a password expires.

PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_WARN_AGE 7
</pre>