linux 实用命令合集

使进程后台运行,并且不接受终端hangup 信号:

nohup python -m test.py > log_name.log 2>&1 &

解释: nohup 是说明这个命令不接收hangup的信号,最后一个& 表示后台运行。其中后面是对输出进行重定向。

wc 命令的使用:

wc 命令常用来进行计数

$ wc --help 
Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
...
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
      --files0-from=F    read input from the files specified by
                           NUL-terminated names in file F;
                           If F is - then read names from standard input
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
      --help     display this help and exit
      --version  output version information and exit

其中: -c 是以字节计数, -m 是以字符计数, -l 是以行计数, -w是以单词计数。

例如:计算一个文件的行数

$ wc -l wmt_enzh_32000k_sub_dev.lang1 
3000 wmt_enzh_32000k_sub_dev.lang1

查看目录中文件的个数:

$ ls | grep "^test" | wc -l 
20

这里是查看当前目录中以test开头的文件或目录的个数。

 

拼接(连接)两个文件的内容:

cat file1 file2 > file_new

这里是把两个文件的内容,依次通过cat 读取出来重定向到了 > 新的文件中。

 

查看安装包位置:

# 获取具体包的名字
$ rmp -qa | grep -i mysql

MySQL-server-advanced-5.6.20-1.rhel5
MySQL-client-advanced-5.6.20-1.rhel5

# 获取具体路径
$ rpm -ql MySQL-server-advanced-5.6.20-1.rhel5

/usr/bin/msql2mysql
/usr/bin/mysql
/usr/bin/mysql_config_editor
/usr/bin/mysql_find_rows
...
/usr/share/man/man1/mysqlshow.1.gz
/usr/share/man/man1/mysqlslap.1.gz

升级python包:

pip install --upgrade python-package-name

python 虚拟环境的使用: 

# 创建虚拟环境
$ virtualenv env_name 

# 激活虚拟环境
$ source env_name/bin/activate 

# 退出虚拟环境
$ deactivate 

软件安装方式 与 平时安装方式相同  

 python源码安装:

下载对应的包,然后:

$ python setup.py install 

比较两个文件的差异:

使用diff, -y 表示已并排方式显示, -W设置宽度

$ diff clean_text_new.py clean_text_new.py.bak -y -W 150

# 全角转半角
full2half_table = [(unichr(i), chr(i - 65248)) for i in range(65281, 6    <
full2half_table.append((unichr(12288), chr(32)))			  <
									  <
									  <
def to_half_width(s):   						  <
    for full, half in full2half_table:  				  <
        s = s.replace(full, half)       				  <
									  <
    return s    							  <
									  <
									  <
record_table = defaultdict(long)						record_table = defaultdict(long)

解释:其中 | 表示当前行不同, < 表示后面的比前面的少一行,> 表示后面的比前面的多了一行

查找文件、文件夹:

find /home/me/test -name *.py 
# 查询 test 目录下 以.py 结尾的文件
# 查询文件夹 加上 -d 

 VIM多行编辑:

  1. CTRL + v 进入块操作模式
  2. 选择所需要的行
  3. 插入:输入大写的I
  4. 输入内容,按下ESC 即可
  5. 如果是删除,则需要在选择之后 dd即可

sh 中引入文件:

# test.sh
source ./bash.sh 

查看可以有多少个进程:

$ ulimit -u
65535

# 设置
$ ulimit -u 4096

查看分配给线程的调用栈大小:

$ ulimit -s 
8192 

一般设置的是8M或者是10M

个数的话可以根据实际可用内存大小进行计算。例如:总共4G内存,内核使用1G, 剩余3G,栈大小为10M, 大约可以有300 个线程。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值