背景:过滤从前端textarea里传过来的字符串里有空行。
如:
1212
2121

1222
测试了一下发现写入文件是:
#cat input.txt
1212
2121

1222
出现多了两个竖线的原因是上面这个空行:
grep -Erin "1212|2121||1222"

那么,想去掉这个串里的空的行,怎么办?



来自:https://zhidao.baidu.com/question/808190628151611092.html

想要的结果是,而不是多一个||,如下:
grep -Erin "1212|2121||1222"
想要:
grep -Erin "1212|2121|1222"





PHP实现ASCII码与字符串相互转换的方法,主要想看换行里是\n还是\r\n,当然也可以在PHP写入文件后sz下来用FlexHEX编辑器看:
31 32 31 32 0A 32 31 32 31 0A 0A 31 32 32 32  <===1212
2121

1222

上面的0A就是10,也就是\n,如下:
php > echo ord(1);
49
php > echo ord(2);
50
php > echo ord(\n);
PHP Fatal error:  Undefined constant 'n' in php shell code on line 1
php > echo ord("\n");
10
用PHP看:

php /tmp/ascii.php
<xmp>&#49;&#50;&#49;&#50;&#10;&#50;&#49;&#50;&#49;&#10;&#10;&#49;&#50;&#50;&#50;</xmp>1212
2121

1222

所以,结论是这个\r其实是没有必要的,下面这一行就行,当然平台可能是\r\n于是得加上:
//$leftContents = preg_replace('/[\r\n]+/', "\n", $leftContents);
$leftContents = preg_replace('/[\n]+/', "\n", $leftContents);    

正则的意思是无论是\r\n\r\n还是\n\n都能被替换为一个斜杠n ,\n:
php > $contents = preg_replace('/\n\n/', "\r\n\r\n", $contents);  
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

一个Window的\r\n和一个unix的\n,这个正则一样能替换,反之一样:
php > $contents = preg_replace('/\n\n/', "\r\n\n", $contents);    
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

反之亦然:
php > $contents=file_get_contents("/tmp/input.txt");
php > echo $contents;
1212
2121

1222
php > $contents = preg_replace('/\n\n/', "\n\r\n", $contents);  
php > echo $contents;
1212
2121

1222
php > $str = preg_replace('/[\r\n]+/', "\n", $contents);
php > echo $str;
1212
2121
1222

对于这个+号,查了一下正则:
man awk
/Regular Expressions

. 任意字符
问家兴:(问加星)
?   0或1次
+  1次或多次    #man awk  Regular Expressions , r+         matches one or more r's.
*   0次或N次

也就是一次或多次,对于\r\n就像[a-z0-9]一个道理,\r和\n分别表示一个字符,可一块,总之一次或多次,于是:
\r\n\r\n  ,\n\n,\r\n\n,\n\r\n都能匹配,长时间不写PHP快忘光了,嗨。

同时,网上还有法二先用换行去转成数组,再用数组里去掉空元素array_filter:
// 该函数把输入数组中的每个键值传给回调函数。如果回调函数返回true,则把输入数组中的当前键值返回结果数组中。数组键名保持不变。若无回调函数,则将TRUE的值返回,即可以使用它来过滤空元素
$arr = array(0, 1, 4, '',null, '0', 23);
$arr = array_filter($arr);// array(1=>1, 2=>4, '6'=>23) 下标不改变,使用array_values(),改变下标
1.去除空行



来自:https://www.cnblogs.com/chenqionghe/p/4293852.html


freebsd-update -r 11.2-RELEASE upgrade
/usr/sbin/freebsd-update install
中间有几次NTP的配置文件确认。
/usr/sbin/freebsd-update install
reboot


FreeBSD 11.2-RELEASE-p4 (GENERIC) #0: Thu Sep 27 08:16:24 UTC 2018
Welcome to jackxiang's Compute Service !

参考:https://blog.csdn.net/joyous/article/details/81990019


升级遇到的问题,出现openssl的动态链接库版本对不上。
最后一次构建FreeBSD镜像::
1)无法再次升级,原因是相关SSHD和Mysqld的动态链接libssl会有问题。

2)FreeBSD升级到11.3还会出sockstat -4l会报错。

3)即使到FreeBSD12.0后Mysql编译好的启动可能也有问题,由于旧的库可能还是涉及到libssl还是有问题。

最终,无法升级,做了一些域名应用快捷方面的优化以及完善了PHP扩展,得出这个版本是一个最后的ISO版本FreeBSD11.2。

pkg info -r security/openssl
openssl-1.0.2l,1:
        libarchive-3.3.1,1
        mysql80-client-8.0.0_3
        bind-tools-9.11.1P3
pkg auto remove
pkg upgrade -y
rm -rf /var/db/freebsd-update/files  #记得删掉。


一些其它命令:
> pkg-add -r openssh-portable
> cd /usr/ports / security / openssh&& make install clean


> portupgrade security / openssh-portable
> makeworld / buildworld过程的一部分
> freebsd-upgrade
cat a.txt
jack 1
tianjin 2
old5 3




sh read.sh
jack 1
tianjin 2
old5 3


加上模拟输出:
insert into t set name='xxx', id=N;

sh read.sh  
insert into t set name='jack',id=1;
insert into t set name='tianjin',id=2;
insert into t set name='old5',id=3;

行内有空格换行的原因:
如果输入文本每行中没有空格,则line在输入文本中按换行符分隔符循环取值.
如果输入文本中包括空格或制表符,则不是换行读取,line在输入文本中按空格分隔符或制表符或换行符特环取值.
可以通过把IFS设置为换行符来达到逐行读取的功能.
demo:
假设现需要读取如下的文件rollback_config.txt:
ROLLBACK_SERVICES:upserv  checkserv
ROLLBACK_VERSION:v1.1
使用   for line in `cat rollback_config.txt`; do echo "${line}"; done  读取的结果会是:
ROLLBACK_SERVICES:upserv
checkserv
ROLLBACK_VERSION:v1.1
显然不是我们想要的。

解决方法:
IFS_old=$IFS
IFS=$'\n'
for line in  `cat  rollback_config`;do
echo "$line"
done;
IFS=$IFS_old
这样一来就可以了!



IFS的默认值为:空白(包括:空格,制表符,换行符).

---------------------

本文来自 潼潼水势向江东 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/zhongjling/article/details/52859055?utm_source=copy

二)用AWK就很方便处理,如下,注意下单引号是三个单引号,中间那个被转义,才输出一个单引号     '\''  :

insert into t set name='jack',id=1;
insert into t set name='tianjin',id=2;
insert into t set name='old5',id=3;
对于变量可以把整个变量用花括号括起来,也可括一部分,如:
整个:{$name}
把$放外面:${name}
-----------------------------------------------------------------------------------
php 使用phpize 安装扩展readline , 安装后可以进入命令行交互模式:


Shell也一样:
1.CURL批量:

输出(注意那个双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配,里面单引号原样输出,这点得记住!):
/usr/bin/curl -I 'baidu.com'
/usr/bin/curl -I '360.cn'
/usr/bin/curl -I 'souhu.com'
/usr/bin/curl -I 'sina.com.cn'

for i in $(cat url.txt);do echo /usr/bin/curl -I "''$i'''";done;  #双引号里加一个单引号引起来,输出单引号,还是那个双引号为匹配
/usr/bin/curl -I ''baidu.com'''
/usr/bin/curl -I ''360.cn'''
/usr/bin/curl -I ''souhu.com'''
/usr/bin/curl -I ''sina.com.cn'''

Curl命令实战:

;done;    
curl: (6) Couldn't resolve host ''baidu.com''
curl: (6) Couldn't resolve host ''360.cn''
curl: (6) Couldn't resolve host ''souhu.com''
curl: (6) Couldn't resolve host ''sina.com.cn''

2.Nc批量:

nc -w 1 -z -v 10.71.182.175 80
nc -w 1 -z -v 192.168.111.43 80

for i in $(cat ip.txt);do  nc -w 1 -z -v $i 80;done;  
Connection to 10.71.182.175 80 port [tcp/http] succeeded!
Connection to 192.168.111.43 80 port [tcp/http] succeeded!
strings
ldd
autoconf
yum groupinstall "Development Tools"
sudo fstat -p 42477 | grep my.cnf 打开后关掉了,无法找到。
cat /usr/local/etc/rc.d/mysql-server |grep my.cnf
#                       ${mysql_confdir}/my.cnf if it exists.
if [ -f "${mysql_confdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_confdir}/my.cnf"}
elif [ -f "${mysql_dbdir}/my.cnf" ]; then
: ${mysql_optfile="${mysql_dbdir}/my.cnf"}

sh  -x /usr/local/etc/rc.d/mysql-server  start //于是直接-x找my.cnf
+ : /usr/local/etc/mysql
+ [ -f /usr/local/etc/mysql/my.cnf ]
+ [ -f /var/db/mysql/my.cnf ]
ls /etc/mysql/my.cnf /etc/my.cnf /usr/local/mysql/my.cnf /usr/local/etc/my.cnf /usr/local/etc/mysql/my.cnf /var/db/mysql/my.cnf


ps -eo pid,ppid,pgrp,session,comm --forest|less      # Linux上使用,Macbook: brew install pstree ,用pstree

ps -eo pid,ppid,pgrp,session,comm|grep -E '(Google\ Chrome|chrome)'

一)基础命令:删目录前看是否有进程打开了目录里的文件之lsof命令。
lsof -c abc 显示abc进程现在打开的文件
lsof -p  列出进程号为1234的进程所打开的文件
lsof -c java  #实践成功
lsof  -p  51640  #实践成功
lsof -g gid 显示归属gid的进程情况
lsof -g 0|grep zcms-0103
lsof  app-2020-08-05.log    #lsof abc.txt 显示开启文件abc.txt的进程
lsof  -d 4 #lsof -d 4 显示使用fd为4的进程,每个进程PID里都是从0,1,2,3,4开始的,出来的有4的所有进程列表。
lsof abc.txt 显示开启文件abc.txt的进程
来自:https://blog.csdn.net/weixin_34019929/article/details/92364579

二)常用想删目录时查看进程是否打开并在访问:
lsof +d /usr/local/ 显示目录下被进程开启的文件
lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长

lsof +d /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103

lsof +D /data/www/zcms3x/zcms-0103
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oosplash  49169 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103
soffice.b 49188 root  cwd    DIR 253,17     4096 5245406 /data/www/zcms3x/zcms-0103


kubectl exec stress-pod -- ps -o "rss,vsz,comm"|grep -v VSZ
2576 6256 stress-ng
3628 6900 stress-ng-cpu
  64 6256 stress-ng-vm
135m 262m stress-ng-vm
   4 1504 ps

rss: 物理
vsz: 虚拟
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)

背景:在多进程时,用那个叫物理内存、虚拟内存的,怎么看?https://blog.csdn.net/i_am_jojo/article/details/7862362

ps -eo pid,ppid,gid,sid,tty,cmd --forest|less


  -e     Select all processes.  Identical to -A.
  -o format
              User-defined format.  format is a single argument in the form of a blank-separated or comma-separated
              list, which offers a way to specify individual output columns.  The recognized keywords are described
              in the STANDARD FORMAT SPECIFIERS section below.  Headers may be renamed (ps -o pid,ruser=RealUser -o
              comm=Command) as desired.  If all column headers are empty (ps -o pid= -o comm=) then the header line
              will not be output.  Column width will increase as needed for wide headers; this may be used to widen
              up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).  Explicit width control (ps opid,
              wchan:42,cmd) is offered too.  The behavior of ps -o pid=X,comm=Y varies with personality; output may
              be one column named "X,comm=Y" or two columns named "X" and "Y".  Use multiple -o options when in
              doubt.  Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are
              macros that may be used to choose the default UNIX or BSD columns.

       -C cmdlist
              Select by command name.  This selects the processes whose executable name is given in cmdlist.
       --forest
              ASCII art process tree.

#ps -eo 'pid,ppid,gid,sid,tty,cmd' |grep Easy
26721 62388     0 62388 pts/4    EasySwoole
26722 26721     0 62388 pts/4    EasySwoole
26744 26722     0 62388 pts/4    EasySwoole.Crontab
31311 26722     0 62388 pts/4    EasySwoole.Worker.0
31312 26722     0 62388 pts/4    EasySwoole.Worker.1
31313 26722     0 62388 pts/4    EasySwoole.Worker.2
31314 26722     0 62388 pts/4    EasySwoole.Worker.3
31315 26722     0 62388 pts/4    EasySwoole.Worker.4
31316 26722     0 62388 pts/4    EasySwoole.Worker.5
31317 26722     0 62388 pts/4    EasySwoole.Worker.6
31318 26722     0 62388 pts/4    EasySwoole.Worker.7
31319 26722     0 62388 pts/4    EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4    EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4    EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4    EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4    EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4    EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4    EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4    EasySwoole.TaskWorker.15

对Crontab进行查看:
lsof -nPp 26744|grep swoole.log
php     26744 root   11u      REG              253,0  39874179 100744037 /data/logs/php/swoole.lo

#lsof -nPp 26721 |grep LISTEN
php     26721 root    3u     IPv4             763966       0t0       TCP *:8080 (LISTEN)
php     26721 root   10u     IPv4             762762       0t0       TCP 127.0.0.1:9000 (LISTEN)


26721 62388     0 62388 pts/4         \_ EasySwoole
26722 26721     0 62388 pts/4             \_ EasySwoole
26742 26722     0 62388 pts/4                 \_ HotReload
26743 26722     0 62388 pts/4                 \_ KafkaAddFormId
26744 26722     0 62388 pts/4                 \_ EasySwoole.Crontab
31311 26722     0 62388 pts/4                 \_ EasySwoole.Worker.0
31312 26722     0 62388 pts/4                 \_ EasySwoole.Worker.1
31313 26722     0 62388 pts/4                 \_ EasySwoole.Worker.2
31314 26722     0 62388 pts/4                 \_ EasySwoole.Worker.3
31315 26722     0 62388 pts/4                 \_ EasySwoole.Worker.4
31316 26722     0 62388 pts/4                 \_ EasySwoole.Worker.5
31317 26722     0 62388 pts/4                 \_ EasySwoole.Worker.6
31318 26722     0 62388 pts/4                 \_ EasySwoole.Worker.7
31319 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.8
31320 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.9
31321 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.10
31322 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.11
31323 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.12
31324 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.13
31325 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.14
31326 26722     0 62388 pts/4                 \_ EasySwoole.TaskWorker.15

ps --headers -eo pid,ppid,GID,tty,sid,vsz,rss,cmd -C EasySwoole


To see every process with a user-defined format:
          ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm

Print only the process IDs of syslogd:
          ps -C syslogd -o pid=

相查看树,能看到进程的继承关系:
ps -eo 'pid,ppid,vsz,rss,cmd' --forest
3078  1214  48620  3032  \_ sshd: xiangdong [priv]
3084  3078  48752  1680      \_ sshd: xiangdong@pts/0,pts/1,pts/2
3085  3084 108352  1788          \_ -bash
3644  3085 189592  2940          |   \_ sudo su -
3645  3644 163756  1964          |       \_ su -
3646  3645 108476  1908          |           \_ -bash
5416  3646 108412  1200          |               \_ ps -eo pid,ppid,vsz,rss,cmd --forest
5417  3646 105460   816          |               \_ less

1481     1  55604  1460 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1484  1481  76816 22864  \_ nginx: worker process                                          
1485  1481  76816 22936  \_ nginx: worker process                                          
1486  1481  76816 22936  \_ nginx: worker process                                          
1487  1481  76816 22936  \_ nginx: worker process  


cat pod-test.yml    



PHP连接未释放之lsof -d 5|grep 2654实现反debug程序PID里的fd对应的tcp连接句柄:
原文,以下是学习到的点:php curl连接未释放,strace结果:poll([{fd=5, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 1000) = 0 (Timeout)
https://www.jianshu.com/p/8a247cae629a
Nc服务端:
[root@golang_server_10_10_0_44:/usr/local/src/go-sftp]
#nc -l 1234
GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: 10.10.0.44:1234
Accept: */*

Client连接端:
[root@swoole_server_10_10_0_45:~]
#ps -ef|grep curl
root      9055  9012  0 03:57 pts/1    00:00:00 curl 10.10.0.44:1234
#curl 10.10.0.44:1234
#ls /proc/9055/fd
0  1  2  3

[root@swoole_server_10_10_0_45:~]
#lsof  -d 3|grep 9055
curl       9055      root    3u     IPv4           23202662      0t0       TCP wx.levoo.com:41490->localhost:search-agent (ESTABLISHED)

#strace -f -p 9055
strace: Process 9055 attached
restart_syscall(<... resuming interrupted poll ...>) = 0
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000


设置超时后呢?
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 1000)  = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 987)   = 0 (Timeout)会提示:
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received


#curl 10.10.0.44:1234 --connect-timeout 10 -m 20
curl: (28) Operation timed out after 20001 milliseconds with 0 out of -1 bytes received



man lsof
       -d s     specifies a list of file descriptors (FDs) to exclude from or include in the output listing.  The file descriptors are  specified  in
                the comma-separated set s - e.g., ``cwd,1,3'', ``^6,^2''.  (There should be no spaces in the set.)
lsof  -nPp 57700|grep cwd
nginx   57700 root  cwd    DIR             253,16     4096   47185921 /data/www
lsof  -nPp 33441|grep cwd
java    33441 root  cwd    DIR              104,3     4096  2757893 /data/xxxxrsync
ls /proc/33441/cwd/  #/data/xxxxrsync的目录的东西
函数说明:chdir()用户将当前的工作目录改变成以参数路径所指的目录。


连接超时时间用 --connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定。

一直Poll的解决办法:php curl调用时设置超时
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
libcurl中同一时候封装了select以及poll这两种I/O机制。
代码中使用宏HAVE_POLL_FINE对这两者进行分离。假设定义了这个宏,则使用poll,否则使用select。
这两者的使用代码都位于函数curl_poll()中,而此函数定义在文件lib/select.c中。我看默认是poll的模式。

Curl不设置超时,对nc -l 1234进行访问会一直不退出的,一直 poll的,刚才实践的确如此,一般都要加上超时参数,如:curl 10.10.0.44:1234 --connect-timeout 10 -m 20
来自:https://blog.csdn.net/weixin_30340745/article/details/98854529
执行一下命令安装以后就可以locate XXX了

yum install mlocate

sudo updatedb

locate  *.doc

实践如下:
零)用unset来撤销数组,可用unset array_name[i]来删除里面的元素:
declare -A DATABASES

# mail
DATABASES['10.70.62.5-3306']='postfix_mail'
用unset来撤销数组,可用unset array_name[i]来删除里面的元素
#cat  arrayunset.sh  

#sh  arrayunset.sh
echo bai manage postfix_mail



一)${#array_name[@]} 或者 ${#array_name[*]}都可以用来求数组的长度
#cat ping3times.sh  






#sh  arrayloop.sh
jerry
alice
david
wendy


二)${array_name[@]} 或者 ${array_name[*]} 都可以全部显示数组中的元素


#sh arraylist.sh
jerry
alice
david
wendy
jerry alice david wendy


来自:https://blog.csdn.net/Jerry_1126/article/details/52027539
在linux下搞软件开发的朋友, 几乎没有不知道strings命令的。我们先用man strings来看看:

strings - print the strings of printable characters in files.  

意思是, 打印文件中可打印的字符。  我来补充一下吧, 这个文件可以是文本文件(test.c), 可执行文件(test),  动态链接库(test.o), 静态链接库(test.a)


脱离代码地长篇大论而不去实际验证, 不是我的风格。 还是搞点代码下菜吧(代码存在test.c中):

cat test.c



我们来看看strings test.c的结果:
strings test.c


可以看到, 确实打印出了test.c中的很多字符。
下面, 我们对可执行文件用strings试试, 如下:
gcc test.c
strings a.out
/lib64/ld-linux-x86-64.so.2
__gmon_start__
libc.so.6
printf
__libc_start_main
GLIBC_2.2.5
fff.
fffff.
l$ L
t$(L
|$0H
oh, my dear, c isd

可以看到, 打印出了a.out中很多字符。
实际上, 如果有目标文件、静态库或动态库,, 也是可以用strings命令进行打印操作的。 我们来看看:
xxx.h文件:

xxx.c文件:
cat  xxx.c


然后, 我们来看看怎么制作静态、动态库吧(在后续博文中会继续详细介绍):
gcc -shared -fPIC -c xxx.c  #-fPI得加上,否则会报relocation R_X86_64_32 against `.rodata'
gcc -shared -fPIC -o libxxx.so xxx.o

问题:
gcc -shared -fPIC -o libxxx.so xxx.o
/usr/bin/ld: xxx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
解决办法:
gcc默认没加-fPIC参数,得手工加上即可。
strings xxx.o
rainy days

strings libxxx.a


strings libxxx.so

trings命令很简单, 看起来好像没什么, 但实际有很多用途。 下面, 我来举一个例子。  在大型的软件开发中, 假设有100个.c/.cpp文件, 这个.cpp文件最终生成10个.so库, 那么怎样才能快速知道某个.c/.cpp文件编译到那个.so库中去了呢? 当然, 你可能要说, 看makefile不就知道了。 对, 看makefile肯定可以, 但如下方法更好, 直接用命令:
      strings -f "*.so" | grep "xxxxxx"

      如果还不明白, 那就就以上面的小程序为例为说明, 不过, 此处我们考虑所有的文件, 如下:

strings -f * | grep "my dear"
a.out: oh, my dear, c isd
test.c:         printf("oh, my dear, c isd\n", c);

可以看到, 源文件test.c和可执行文件中皆有"my dear"串, 一下子就找到了对应的文件,清楚了吧。如果某.c/.cpp文件编译进了.so库, 那么,strings -f * | grep "my dear"必定可以找到对应的.so文件, 其中"my dear"为该.c/.cpp文件中的某个日志串(比如以printf为打印)。

来自:https://blog.csdn.net/stpeace/article/details/46641069
背景: 系统启动的grub.cfg 不一样,有的在/boot/efi/EFI/centos/grub.cfg ,有的在 /etc/grub2.cfg

某天挂载了一个新硬盘后,我的centos7系统第二天就出现了崩溃现象,报错如题“failed to start crash recovery kernel arming”.

意思大致为“内存崩溃捕获机制未能成功启动”,一搜才知道这是因为一个叫做kdump的服务无法启动导致的。

那么什么是kdump呢?

kdump 是一种先进的基于 kexec 的内核崩溃转储机制。当系统崩溃时,kdump 使用 kexec 启动到第二个内核。第二个内核通常叫做捕获内核,以很小内存启动以捕获转储镜像。第一个内核保留了内存的一部分给第二内核启动用。由于 kdump 利用 kexec 启动捕获内核,绕过了 BIOS,所以第一个内核的内存得以保留。这是内核崩溃转储的本质。详细的在:http://www.ibm.com/developerworks/cn/linux/l-cn-kdump1/index.html#major3

那接下来查找失败的原因:

看到一个博文中说与启动文件配置有关

查看/etc/grub.conf 文件,发现crashkernel=auto,

系统对crashkernel=auto的定义为:

如果系统的内存 <= 8 GB 对kdump kernel不会保留任何内容;也就是说,crashkernel=auto 等

于关掉了机器上的kdump功能;

如果系统的内存> 8 GB但是<= 16 GB,crashkernel=auto会保留256M,等同于crashkernel=256M;

如果系统内存> 16GB, crashkernel=auto会保留512M, 等同于crashkernel=512M

安装虚拟机时,给虚拟机设置的内存为1G,所以说系统关掉了kdump。

接下来就是改写配置,但是没能在系统中找到博文中所说的/etc/grub.conf这个文件,后来想到从Centos 7之后启动就采用grub2 了,所以vi /etc/grub2.cfg把其中的crashkernel=auto改成crashkernel=256M重启就成功了。

来自:https://www.jianshu.com/p/c9e741c24d2b
在mac下开发的时候,经常会发现有些文件的属性后面,有个@符号



如上图所示。为什么呢?


在mac os 下 HFS+的文件系统里,有时候有些文件会附加上mac的专有属性,@属性就表示文件或文件夹是来自互联网下载
去掉方法:
xattr -l 文件名:查看attr
xattr -d 属性名:删除attr


来自:https://blog.csdn.net/mysteryhaohao/article/details/51900188
mac下发现不能用记事本打开文本文件,ls -la 发现格式后面有个@:
https://blog.csdn.net/wk3368/article/details/29597535
背景:想通过一些命令直接界面目录,想通过目录运行Linux一样的一些命令,MINGW32有这个功能,结合它,通过SourceTree的命令行模式再打开目录,本来SourceTree有一个浏览器,但它有时响应有些慢,出现灰色不能点,于是从命令行模式进去后再通过explorer . 打开目录更快捷一些,这个explorer的PATH路径要写好了,就不用输入一堆路径了(c:\Windows\winsxs\x86_microsoft-windows-explorer_31bf3856ad364e35_6.1.7601.17514_none_53bc10fdd7fe87ca),只有这样写到PATH变量之后才方便打开目录。2) 关于实践证明这个MINGW32的环境变量就是从Windows里继承过去的,修改了Windows系统的环境PATH后时还无法生效,要重启,我是等了会才生效的。
分别讲述:一、从运行输入命令打开(C语言写或BAT编写都成)。  二、从终端打开。  三、用快捷键打开。

法一)从Windows的运行里启动,前提是放入到PATH命令里:
(1)从运行到Windows的目录窗口:
像上面一样写入PATH,再写一个BAT脚本,chtdoc.bat 内容如下:
D:\Program Files\curl_wget_tail\chtdoc.bat


D:\Program Files\curl_wget_tail\cops.bat

使用时,直接Ctrl+R打开命令行窗口,然后输入:chtdoc,就能打开Windows的目录窗口,其它目录也一样的方式进行切换。
Windows下的CMD查看PATH变量值:


法二)从命令行里到Windows的窗口:
D:\Program Files\curl_wget_tail #里面放BAT文件和一些常用的软件,加快Windows下目录切换速度之用。
如:D:\Program Files\curl_wget_tail\cansible.bat


像:D:\script 可放一些SecureCRT的脚本软件,加快在Linux下的Cd目录速度。
Win7中打开cmd窗口的方式:在当前路径下,按住shift键,鼠标右键:
explorer.exe .  #explorer  . 也成。
在MINGW32下面的PATH如何设置?
设置MinGW环境变量
依次鼠标点击桌面“我的电脑”->选择左侧的“高级系统设置”,选择“高级”->“环境变量”,然后再Path里增加;C:\MinGW\bin声明。点击确定。
小提示:设置完成后,Windows似乎不会自动更新环境变量,除非重启机子,那么我们可以通过在下面的命令行中,胡乱设置一下PATH(比如SET PATH=C:\),然后退出命令行,那么系统环境变量就会被强制刷新。From: http://www.360doc.com/content/17/1203/15/8728596_709509894.shtml

在此处打开命令窗口后,将explorer的目录加入PATH,直接用exporer . ,就能到Windows的GUI界面,后面可以用一些编辑器打开文件。
为何要加入到环境变量里?
实践如下:



起于当explorer.exe没有设置PATH的一个使用情况如下:
sourcetree里的命令行模式MINGW32命令行Git Bash Here用explorer打开当前目录:
/c/Windows/winsxs/x86_microsoft-windows-explorer_31bf3856ad364e35_6.1.7601.17514_none_53bc10fdd7fe87ca/explorer.exe .
$ echo $PATH
/c/Users/admin/bin:/mingw32/bin:/usr/local/bin:/usr/bin:/bin:/mingw32/bin:/usr/bin:/c/Users/admin/bin:/d/Program Files/Microsoft Visual Studio/Common/Tools/WinNT:/d/Program Files/Microsoft Visual Studio/Common/MSDev98/Bin:/d/Program Files/Microsoft Visual Studio/Common/Tools:/d/Program Files/Microsoft Visual Studio/VC98/bin:/c/Users/admin/AppData/Local/Programs/Fiddler:/d/Program Files/Nmap:/d/Program Files/Microsoft VS Code/bin:/d/Program Files/curl_wget_tail:/c/Windows/winsxs/x86_microsoft-windows-explorer_31bf3856ad364e35_6.1.7601.17514_none_53bc10fdd7fe87ca:/d/Program Files/Microsoft Visual Studio/Common/Tools/WinNT:/d/Program Files/Microsoft Visual Studio/Common/MSDev98/Bin:/d/Program Files/Microsoft Visual Studio/Common/Tools:/d/Program Files/Microsoft Visual Studio/VC98/bin:/c/Users/admin/AppData/Local/Programs/Fiddler:/d/Program Files/Nmap:/d/Program Files/Microsoft VS Code/bin:/d/Program Files/curl_wget_tail:/c/Windows/winsxs/x86_microsoft-windows-explorer_31bf3856ad364e35_6.1.7601.17514_none_53bc10fdd7fe87ca:/usr/bin/vendor_perl:/usr/bin/core_perl


用程序调用操作系统的方法:
打开指定文目录、应用程序、文档:
1、打开C盘:
system("explorer.exe C:");
或者:
system("explorer.exe C:\\");

打开某个文件夹:E:\workspace\2014-12-07-VS2013
system("explorer.exe E:\\workspace\\2014-12-07-VS2013"); //打开指定文件夹
所以这里涉及到了转义字符:  \"  代表了   "

打开包含空格路径的应用程序,要添加双引号的转义字符。命令如下:

    //打开应用程序(路径中包含空格)
    system("\"D:\\Sublime Text 3\\sublime_text.exe\"");
    system("pause");
注:如果路径里没有空格,是不需要添加双引号的。

打开word文档:

    //打开word文档
    system("E:\\沉淀时光\\2014电子科技大学硕士招生简章.doc");
    system("pause");
打开ie浏览器:

    //打开浏览器
    system("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" ");
打开指定网站:

    //打开指定网站
    system("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"  www.google.com");
打开指定程序后关闭:

复制代码
#include<stdlib.h>

void main(){    
    //打开指定程序后,运行,回车,程序会关闭
    system("start calc");
    system("pause");
    system("taskkill /f /im calc.exe"); //关闭进程
}
复制代码
注:第07行代码中,/f表示force, /im表示进程名称。

运行上面的程序后,计算器会打开,此时在弹出的cmd窗口中回车,计算器会关闭。注:少了第05行的单词start和第06行的pause,都不能实现这个功能。

法三)用快捷键打开:
在目录上点右键->属性->快捷方式->快捷键。这种打开像:E:\download (用:ctrl+alt+d),
和SecureCRT的目录:D:\Program Files\SecureCRT7.3\ssh_tmp\Sessions(用:ctrl+alt+s)。
不宜配置太多占用了也记不住,其它的用上面二里的BAT命令行就行,如:cwww,cops,cshell,cansible等。

参考:https://www.cnblogs.com/smyhvae/p/4148458.html
背景:之前是一个写Markdown的编辑器Typora在升级后无法启动,后来是vs code也升级后无法启动,于是觉得奇怪了,网上专门搜了一下visual studio code win7 无法启动,查到一篇文章,https://blog.csdn.net/caijunfen/article/details/80393298 ,按里面方法在Cmd下运行netsh winsock reset命令后, vs code 好了,连Typora也好了,后来才想起原来是公司非要装一个360杀毒软件,在我运行netsh winsock reset时,提示是否允许,我估计可能是它给关了所导致。

执行 netsh winsock reset 重置命令

------------------不熟悉操作系统的同学可以按下面的教程来----------------

window + R 键 调出运行,输入 cmd ,按回车。
命令提示符出来之后,点左上角的图标然后选择编辑->选择粘贴这个进去 netsh winsock reset
粘贴之后按回车
最后会提示成功地重置Winsock目录。一般不用重启,直接双击你的Visual Code,应该就可以打开了。
C:\Users\admin>netsh winsock reset
'netsh' 不是内部或外部命令,也不是可运行的程序
或批处理文件。



成功地重置 Winsock 目录。
您必须重新启动计算机才能完成重置。



第二、查了一下,使用netsh winsock reset命令修复网络连接错误:
简单来说netsh winsock reset命令含义是重置 Winsock 目录。如果一台机器上的Winsock协议配置有问题的话将会导致网络连接等问题,就需要用netsh winsock reset命令来重置Winsock目录借以恢复网络。

winsock是windows网络编程接口,从Windows XP SP2开始内置了一条命令使用netsh能够对该接口进行修复。

netsh是一个能够通过命令行操作几乎所有网络相关设置的接口。比如设置IP,DNS,网卡,无线网络等。
netsh winsock reset:
先进入netsh
然后进入winsock这个部件
对winsock这个部件执行reset命令。
效果就是重置Winsock。对于一些WinSock被破坏导致的问题有奇效。在netsh出现之前,对于WinSock问题的修复是非常繁琐的。

来自:https://blog.csdn.net/yanjiaye520/article/details/5452304
如何用tar压缩文件夹到指定目录:
tar -zxvf /usr/local/jmeter.tar.gz -C /usr/local/  && rm -rf /usr/local/jmeter.tar.gz && chmod -R 755 /usr/local/jmeter

压缩:
tar -cvzf /test/tmp/abc.tar.gz /test/tcp/abc

实例,将魔方MYSIM数据库给压缩到根目录下:
tar -cvzf /mofang.08.21.tar.gz mofang/

解压
tar -cvxf abc.tar.gz  -C /test/tmp
背景:Windows的C盘越来越大,60G都占满了,刚开始才10来G,逐步越占越多,而自带的那个工具根本无法看到占比,而这个Folder-size能把列表列出来并讲算出占比,方便分析哪个目录占得多,点进去后也有占比,方便分析删除目录之用,根据百分比,直接由60G干掉了16G剩余空间出来。

应用程序可以在几分钟内扫描整个硬盘驱动器,由于它优化扫描算法和树的大小详细列出。逐行扫描让你继续从扫描中断的问题。除了扫描整个硬盘驱动器文件夹大小也可以扫描一个文件夹,以节省时间。
DownLoad:http://enkj.jb51.net:81/201409/tools/FolderSize(jb51.net).rar
网站下载:http://www.mindgems.com/products/Folder-Size/Folder-Size-Tutorials.htm?postinstall=1

尽管windows也有查看的方法,但不直观,得一个一个的看,如下:
文件夹不像文件那样,不能在显示详细信息的时候显示出它的大小来,下面介绍两种查看方法,进行对比,看看哪个方法更快更方便~
https://jingyan.baidu.com/article/4853e1e5725b651909f726d2.html

下载:
F12打开开发者工具,选择Network,请求一个网站,就会显示请求的列表,在任何一列上右击,选择”Remote Address”,就能显示所有请求的IP地址:
在时间线下面,有一个Name Status Type 上面点右键,选上remote Addresss就显示出来了。
来自:https://blog.csdn.net/btlas/article/details/52383166


查看单个请求的IP地址,这个不如前面直接打开所有得了,如下:
请求一个网站,就会显示请求的列表,点击在右边就能看到IP地址
分页: 17/339 第一页 上页 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 下页 最后页 [ 显示模式: 摘要 | 列表 ]