分类 默认分类 下的文章

1.分割 -- split命令

可以指定按行数分割和按字节大小分割两种模式。

(1) 按行数分割

$ split -l 300 large_file.txt new_file_prefix
加上-d,使用数字后缀;加上--verbose,显示分割进度:

$ split -l50000 -d large_file.txt part_ --verbose
(2) 按字节大小分割

$ split -b 10m large_file.log new_file_prefix

2.合并 -- cat命令

$ cat part_* > merge_file.txt

[注] split命令语法:

复制代码
$ split --h
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...;
default size is 1000 lines, and default PREFIX is 'x'.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N generate suffixes of length N (default 2) 后缀名称的长度 (默认为2)

  --additional-suffix=SUFFIX  append an additional SUFFIX to file names

-b, --bytes=SIZE put SIZE bytes per output file 每个输出文件的字节大小
-C, --line-bytes=SIZE put at most SIZE bytes of records per output file 每个输出文件每行的最大字节大小
-d use numeric suffixes starting at 0, not alphabetic 使用数字后缀代替字母后缀

  --numeric-suffixes[=FROM]  same as -d, but allow setting the start value

-e, --elide-empty-files do not generate empty output files with '-n' 不产生空的输出文件

  --filter=COMMAND    write to shell COMMAND; file name is $FILE           写入到shell命令行

-l, --lines=NUMBER put NUMBER lines/records per output file 设定每个输出文件的行数,默认行数是1000行
-n, --number=CHUNKS generate CHUNKS output files; see explanation below 产生chunks文件
-t, --separator=SEP use SEP instead of newline as the record separator; 使用新字符分割

                        '\0' (zero) specifies the NUL character

-u, --unbuffered immediately copy input to output with '-n r/...' 无需缓存

  --verbose           print a diagnostic just before each                  显示分割进度
                        output file is opened
  --help     display this help and exit                                    显示帮助信息
  --version  output version information and exit                           显示版本信息

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

CHUNKS may be:
N split into N files based on size of input
K/N output Kth of N to stdout
l/N split into N files without splitting lines/records
l/K/N output Kth of N to stdout without splitting lines/records
r/N like 'l' but use round robin distribution
r/K/N likewise but only output Kth of N to stdout

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/split
or available locally via: info '(coreutils) split invocation'
复制代码

cat命令语法:

复制代码
$ cat --h
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB

  --help     display this help and exit
  --version  output version information and exit

Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/cat
or available locally via: info '(coreutils) cat invocation'
复制代码

git 操作方法笔记

自动补全
git --version
下载对应版本的文件:
https://raw.githubusercontent.com/git/git/v2.22.0/contrib/completion/git-completion.bash

如果你用的是 Bash shell,可以试试看 Git 提供的自动补全脚本。下载 Git 的源代码,进入 contrib/completion 目录,会看到一个 git-completion.bash 文件。将此文件复制到你自己的用户主目录中(译注:按照下面的示例,还应改名加上点:cp git-completion.bash ~/.git-completion.bash),并把下面一行内容添加到你的 .bashrc 文件中:

source ~/.git-completion.bash

保存账号密码
git config --global credential.helper store

忽略本地文件权限修改
git config core.fileMode false

tag标签
git tag xxxx [-m xxxxx]
git show xxxx
git push origin xxxx
推送本地所有标签到远程仓库
git push origin [--tags]

删除本地仓库中的文件
git rm与git rm --cached

当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用
1 git rm file_path
2 git commit -m 'delete somefile'
3 git push
当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用
git rm --cached file_path
git commit -m 'delete remote somefile'
git push

本地修改不提交到远程仓库

git update-index --assume-unchanged index.jsp
取消本地忽略
git update-index --no-assume-unchanged index.jsp
查看本地仓库哪些文件被加入忽略列表

恢复跟踪

git update-index --no-assume-unchanged   sp_edaijia/protected/controllers/ApiController.php  //恢复跟踪

如果忽略的文件多了,可以使用以下命令查看忽略列表

git ls-files -v | grep '^h\ '

提取文件路径,方法如下

git ls-files -v | grep '^h\ ' | awk '{print $2}'

所有被忽略的文件,取消忽略的方法,如下

git ls-files -v | grep '^h' | awk '{print $2}' |xargs git update-index --no-assume-unchanged  

查找历史代码片段

git log -G 正则 -p
git log -s 文件名

php-fpm添加service服务

nginx通过FastCGI运行PHP比Apache包含PHP环境有明显的优势,最近有消息称,PHP5.4将很有可能把PHP-FPM补丁包含在内核里,nginx服务器平台上运行PHP将更加轻松,下面我们就来看一篇php-fpm平滑启动并配置服务例子。我的php是源码安装的。php-fpm在PHP 5.3.2以后的版本不支持以前的php-fpm (start|restart|stop|reload) ,那么如果将php-fpm配置成服务,并添加平滑启动/重启。
配置php-fpm.conf(vi /usr/local/php54/etc/php-fpm.conf),将pid(;pid = run/php-fpm.pid)前的;去掉。
因为编译安装php的,所以会在php目录生成很多二进制文件,找到init.d.php-fpm,拷贝到init.d下。
cp /usr/local/src/php54/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
设置权限,并添加服务
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
以后可以使用如下命令管理php-fpm了
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload

PHP扩展的安装请先参阅PHP官方说明:
搜索有没有相关的类名或者方法名称进行,或者在下面页面以及右侧相关页面中进行查找
https://www.php.net/manual/zh/refs.compression.php

PHP安装REDIS扩展
下载地址:http://pecl.php.net/package/redis
下载与PHP版本匹配的包
安装步骤:

     tar  -zxvf  redis-2.2.8.tgz
     cd  redis-2.2.8
     /usr/local/php/bin/phpize                      #用phpize生成
    ./configure --with-php-config=/usr/local/php/bin/php-config      #配置
     make 
     make  install 

到此扩展下载安装完成,make install之后会提示扩展文件路径
配置php.ini文件,使得php可以支持redis扩展

   vim  /etc/php.ini
#最后添加这两行
[redis]
extension = /路径/redis.so

重启服务;
测试下phpinfo();现在就可以看到redis扩展支持了;

安装 zip 扩展和以上步骤是一样的,下载地址:
从 PHP 7.4.0 开始,必须在编译 PHP 时用 --with-zip 配置选项来提供 zip 支持。之前的 PHP 版本,需要使用 --enable-zip 选项。从 PHP 7.4.0 起,移除捆绑的 libzip。

从 PHP 7.3.0 开始, 不鼓励使用捆绑的 libzip 进行构建,但通过在配置中添加 --without-libzip 参数仍然可以实现。

新增 --with-libzip=DIR 配置选项以使用系统 libzip 安装。需要 libzip 版本 0.11,推荐使用 0.11.2 或更高版本。
https://pecl.php.net/package/zip

redis批量删除

redis-cli keys ewei_* | xargs redis-cli del

指定IP和端口
redis-cli [-h 192.168.0.8 -p 6380] keys "obj_base_*" |xargs redis-cli [-h 192.168.0.8 -p 6380] del

redis-cli keys "obj_base_*" |xargs redis-cli del