杂记 (7) —— shell, gdb, vim, gcc, mingw32

13 篇文章 0 订阅

diff的结果显示解释

a - add
c - change
d - delete 

如:
$ diff file1 file2

1c1
< 时间:0.29000000
---
> 时间:0.42000000

代表第一行不同

1,2d0
< 时间:0.29000000
< after sorted : 

代表第一个文件比第二个文件多第一行时间:0.29000000和第二行after sorted :

0a1
> hello

代表第一个文件比第二个文件少第一行hello。

查看磁盘空间

edemon@ubuntu1:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            491M     0  491M   0% /dev
tmpfs           101M  5.2M   95M   6% /run
/dev/sda5        20G  6.3G   13G  34% /
tmpfs           501M  156K  501M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           501M     0  501M   0% /sys/fs/cgroup
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           101M   56K  100M   1% /run/user/1000
/dev/sr0        1.2G  1.2G     0 100% /media/edemon/Ubuntu 15.04 i386

查看CentOS上mysql的版本

$ rpm -qi mysql-server
Name        : mysql-server                 Relocations: (not relocatable)
Version     : 5.1.73                            Vendor: CentOS
Release     : 7.el6                         Build Date: Wed 11 May 2016 02:05:53 PM CST
Install Date: Wed 07 Dec 2016 08:44:50 AM CST      Build Host: worker1.bsys.centos.org
Group       : Applications/Databases        Source RPM: mysql-5.1.73-7.el6.src.rpm
Size        : 25688915                         License: GPLv2 with exceptions
Signature   : RSA/SHA1, Thu 12 May 2016 06:46:25 PM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.mysql.com
Summary     : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.

产看文件系统类型

root@ubuntu1:/etc/init.d# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            491M     0  491M   0% /dev
tmpfs           101M  5.2M   95M   6% /run
/dev/sda5        20G  6.7G   12G  36% /
tmpfs           501M  156K  501M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           501M     0  501M   0% /sys/fs/cgroup
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           101M   48K  100M   1% /run/user/1000
/dev/sr0        1.2G  1.2G     0 100% /media/edemon/Ubuntu 15.04 i386

root@ubuntu1:/etc/init.d# file -s /dev/sda5
/dev/sda5: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=acbb6d51-cbc0-40cc-8341-d4b0a4471b44 (large files)

Can’t connect to local MySQL server through socket

抱着折腾的心思,我关闭了mysql服务端。

root@ubuntu1:~# mysqladmin -u root -p shutdown
Enter password:

然后尝试重新开启,出现下列错误:

root@ubuntu1:~# mysqld_safe &
[1] 6366
root@ubuntu1:~# 161211 10:20:13 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
161211 10:20:13 mysqld_safe Logging to '/var/log/mysql/error.log'.
161211 10:20:13 mysqld_safe A mysqld process already exists

根据最后一句话的提示,我杀死mysqld进程。但是随后新的mysqld又出现了。查阅后,我将/etc/init.d/mysql删除了(准确的说是误删,mv写成了rm,word天 -_-||)
神奇的是我又能正常登陆mysql了。这正常吗。。。
我重新来了一次,发现是这样的:
mysqld确实正常启动了:

root@ubuntu1:/etc/init.d# mysqld_safe &
[1] 7276
root@ubuntu1:/etc/init.d# 161211 11:09:28 mysqld_safe Can't log to error log and syslog at the same time.  Remove all --log-error configuration options for --syslog to take effect.
161211 11:09:28 mysqld_safe Logging to '/var/log/mysql/error.log'.
161211 11:09:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
161211 11:09:30 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

登陆时出现问题:

edemon@ubuntu1:~$ mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我查找sock文件,它并不存在。
重启mysql:

edemon@ubuntu1:~$ service mysql restart

OK:

root@ubuntu1:/home/edemon# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3

不过我在CentOS上使用同样的指令时他不认识mysql,我搜索了一下mysqld,然后重启mysql服务,最后正常了。/etc/rc.d/init.d/mysqld restart

bc进行浮点运算

man在线手册中有这样的话:

NUMBERS
 45        The most basic element in bc is the number.  Numbers are arbitrary precision numbers.  This precision is both in the integer part and the
 46        fractional part.  All numbers are represented internally in decimal and all computation is done  in  decimal.   (This  version  truncates
 47        results  from  divide  and multiply operations.)  There are two attributes of numbers, the length and the scale.  The length is the total
 48        number of significant decimal digits in a number and the scale is the total number of decimal digits after the decimal point.  For  exam‐
 49        ple:
 50            .000001 has a length of 6 and scale of 6.
 51            1935.000 has a length of 7 and a scale of 3.

所以我们可以通过改变scale来控制输出浮点数的精度。
比如:

edemon@ubuntu1:~$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
2/4
0
scale=2
2/4
.50

查看cpu、处理器等硬件信息

cat /proc/cpuinfo

gdb临时改变变量的值

假设改变浮点数value1的值:

(gdb) set var value1=1

负数的增长

-1在计算机中的表示:
32整数 —— 11111111111111111111111111111111
仅从负数的角度来看,负数在计算机中的表示也有一定的规律:

(gdb) set var $eax=-1
(gdb) p/t $eax
$3 = 11111111111111111111111111111111
(gdb) set var $eax=-2
(gdb) p/t $eax
$4 = 11111111111111111111111111111110
(gdb) set var $eax=-3
(gdb) p/t $eax
$5 = 11111111111111111111111111111101
(gdb) set var $eax=-4
(gdb) p/t $eax
$6 = 11111111111111111111111111111100
(gdb) set var $eax=-5
(gdb) p/t $eax
$7 = 11111111111111111111111111111011
(gdb) set var $eax=-6
(gdb) p/t $eax
$8 = 11111111111111111111111111111010

Binary file (standard input) matches

grep提取特定信息出错,加上选项-a即可。
read_command |grep -a condition
专用于处理二进制文件的情况:
Process a binary file as if it were text; this is equivalent to the --binary-files=text option

查gdb调试运行到哪一行

(gdb) bt查看堆栈信息,同时也能查看行数信息。

vim字体设置

ctrl \+ 0 常规字体
ctrl \+ shft \+ + 字体加大
ctrl \+ -字体变小

at计划任务

linux at命令可以用于在特定的时间执行设定的任务,如:

at 14:40
at> ls -l > text
at> <EOT>
job 8 at 2017-01-18 14:40

查看at任务列表:atq;删除at任务: atrm Job_number

run level

Linux默认的运行级别是

[root@CentOS Desktop]# runlevel
N 5

查看各个运行级别的含义:

[root@CentOS Desktop]# cat /etc/inittab
...
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 

init 0可关机。

crontab

crontab的安装:yum install -y vixie-cron
crontab -e编辑crontab文件,不存在则自动创建。
crontab前5列是时间和日期。

  9 # .---------------- minute (0 - 59)
 10 # |  .------------- hour (0 - 23)
 11 # |  |  .---------- day of month (1 - 31)
 12 # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
 13 # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
 14 # |  |  |  |  |
 15 # *  *  *  *  * user-name command to be executed

开启crond服务:

[root@CentOS Desktop]# /etc/rc.d/init.d/crond restart
Starting crond:                                            [  OK  ]
[root@CentOS Desktop]# ps -ef |grep crond
root      3636     1 15 15:41 ?        00:00:01 crond
root      3639  2872  0 15:41 pts/0    00:00:00 grep crond

在crontab文件中编辑任务:vim /etc/crontab 末尾增加任务:19 16 * * * date > /home/edemon/workspace/text
最后查看结果:

[edemon@CentOS workspace]$ cat text
Wed Jan 18 16:19:01 CST 2017

使用crontab -e来制定任务却一直未能成功,迷惑啊。

查看gcc的搜索路径

先看看gcc帮助:

shell> gcc --help
Usage: gcc [options] file...
Options:
  -pass-exit-codes         Exit with highest error code from a phase
  --help                   Display this information
  --target-help            Display target specific command line options
  --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
                           Display specific types of command line options
  (Use '-v --help' to display command line options of sub-processes)
  --version                Display compiler version information
  -dumpspecs               Display all of the built in spec strings
  -dumpversion             Display the version of the compiler
  -dumpmachine             Display the compiler's target processor
  -print-search-dirs       Display the directories in the compiler's search path
  -print-libgcc-file-name  Display the name of the compiler's companion library
  -print-file-name=<lib>   Display the full path to library <lib>
  -print-prog-name=<prog>  Display the full path to compiler component <prog>
  -print-multiarch         Display the target's normalized GNU triplet, used as
                           a component in the library path
  -print-multi-directory   Display the root directory for versions of libgcc
  -print-multi-lib         Display the mapping between command line options and
                           multiple library search directories
  -print-multi-os-directory Display the relative path to OS libraries
  -print-sysroot           Display the target libraries directory
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor
  -Wl,<options>            Pass comma-separated <options> on to the linker
  -Xassembler <arg>        Pass <arg> on to the assembler
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  -Xlinker <arg>           Pass <arg> on to the linker
  -save-temps              Do not delete intermediate files
  -save-temps=<arg>        Do not delete intermediate files
  -no-canonical-prefixes   Do not canonicalize paths when building relative
                           prefixes to other gcc components
  -pipe                    Use pipes rather than intermediate files
  -time                    Time the execution of each subprocess
  -specs=<file>            Override built-in specs with the contents of <file>
  -std=<standard>          Assume that the input sources are for <standard>
  --sysroot=<directory>    Use <directory> as the root directory for headers
                           and libraries
  -B <directory>           Add <directory> to the compiler's search paths
  -v                       Display the programs invoked by the compiler
  -###                     Like -v but options quoted and commands not executed
  -E                       Preprocess only; do not compile, assemble or link
  -S                       Compile only; do not assemble or link
  -c                       Compile and assemble, but do not link
  -o <file>                Place the output into <file>
  -pie                     Create a position independent executable
  -shared                  Create a shared library
  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension

Options starting with -g, -f, -m, -O, -W, or --param are automatically
 passed on to the various sub-processes invoked by gcc.  In order to pass
 other options on to these processes the -W<letter> options must be used.

For bug reporting instructions, please see:
<file:///usr/share/doc/gcc-4.9/README.Bugs>.

根据提示查找搜索:

shell> gcc -print-search-dirs
install: /usr/lib/gcc/i686-linux-gnu/4.9/
programs: =/usr/lib/gcc/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/bin/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/bin/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/bin/
libraries: =/usr/lib/gcc/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/lib/i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/lib/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../i686-linux-gnu/4.9/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../lib/:/lib/i686-linux-gnu/4.9/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i686-linux-gnu/4.9/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/lib/:/usr/lib/gcc/i686-linux-gnu/4.9/../../../:/lib/:/usr/lib/

#for c:
shell> `gcc  -print-prog-name=cc1` -v
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.9/include-fixed
 /usr/include
End of search list.

#for c++
shell> `gcc  -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.9/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.9
 /usr/include/i386-linux-gnu/c++/4.9
 /usr/include/c++/4.9/backward
 /usr/lib/gcc/i686-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.9/include-fixed
 /usr/include
End of search list.
^C

mingw32头文件和库文件

查找mingw32的搜索路径是一样的:

shell> i686-w64-mingw32-gcc --help
Usage: i686-w64-mingw32-gcc [options] file...
Options:
  -pass-exit-codes         Exit with highest error code from a phase
  --help                   Display this information
  --target-help            Display target specific command line options
  --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
                           Display specific types of command line options
  (Use '-v --help' to display command line options of sub-processes)
  --version                Display compiler version information
  -dumpspecs               Display all of the built in spec strings
  -dumpversion             Display the version of the compiler
  -dumpmachine             Display the compiler's target processor
  -print-search-dirs       Display the directories in the compiler's search path
  -print-libgcc-file-name  Display the name of the compiler's companion library
  -print-file-name=<lib>   Display the full path to library <lib>
  -print-prog-name=<prog>  Display the full path to compiler component <prog>
  -print-multiarch         Display the target's normalized GNU triplet, used as
                           a component in the library path
  -print-multi-directory   Display the root directory for versions of libgcc
  -print-multi-lib         Display the mapping between command line options and
                           multiple library search directories
  -print-multi-os-directory Display the relative path to OS libraries
  -print-sysroot           Display the target libraries directory
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor
  -Wl,<options>            Pass comma-separated <options> on to the linker
  -Xassembler <arg>        Pass <arg> on to the assembler
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  -Xlinker <arg>           Pass <arg> on to the linker
  -save-temps              Do not delete intermediate files
  -save-temps=<arg>        Do not delete intermediate files
  -no-canonical-prefixes   Do not canonicalize paths when building relative
                           prefixes to other gcc components
  -pipe                    Use pipes rather than intermediate files
  -time                    Time the execution of each subprocess
  -specs=<file>            Override built-in specs with the contents of <file>
  -std=<standard>          Assume that the input sources are for <standard>
  --sysroot=<directory>    Use <directory> as the root directory for headers
                           and libraries
  -B <directory>           Add <directory> to the compiler's search paths
  -v                       Display the programs invoked by the compiler
  -###                     Like -v but options quoted and commands not executed
  -E                       Preprocess only; do not compile, assemble or link
  -S                       Compile only; do not assemble or link
  -c                       Compile and assemble, but do not link
  -o <file>                Place the output into <file>
  -pie                     Create a position independent executable
  -shared                  Create a shared library
  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           'none' means revert to the default behavior of
                           guessing the language based on the file's extension

Options starting with -g, -f, -m, -O, -W, or --param are automatically
 passed on to the various sub-processes invoked by i686-w64-mingw32-gcc.  In order to pass
 other options on to these processes the -W<letter> options must be used.

For bug reporting instructions, please see:
<http://gcc.gnu.org/bugs.html>.

查找c的头文件搜索路径:

shell> `i686-w64-mingw32-gcc -print-prog-name=cc1` -v
ignoring nonexistent directory "/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/include-fixed
 /usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/include
End of search list.
^C

查看库文件搜索目录:

[edemon@CentOS ~]$  i686-w64-mingw32-gcc   -print-search-dirs 
install: /usr/lib/gcc/i686-w64-mingw32/4.9.2/
programs: =/usr/libexec/gcc/i686-w64-mingw32/4.9.2/:/usr/libexec/gcc/i686-w64-mingw32/4.9.2/:/usr/libexec/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/i686-w64-mingw32/4.9.2/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/
libraries: =/usr/lib/gcc/i686-w64-mingw32/4.9.2/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/lib/i686-w64-mingw32/4.9.2/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/lib/../lib/:/usr/i686-w64-mingw32/sys-root/mingw/lib/i686-w64-mingw32/4.9.2/:/usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/:/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/lib/:/usr/i686-w64-mingw32/sys-root/mingw/lib/

优先搜索多个头文件库

i686-w64-mingw32-gcc sdl_back.c -lSDL -I/usr/include/ -I/usr/include/i386-linux-gnu/gnu/

mingw32在linux平台生成windows可执行文件

下面提到的win.c仅仅是一个简单的hello程序:

#include <stdio.h>
int main(){
    printf("hello\n");
    return 0;
}

然后使用mingw32生成汇编文件和win可执行文件:

root@ubuntu1:/home/edemon/workspace# i686-w64-mingw32-gcc -S -o win.s win.c 
root@ubuntu1:/home/edemon/workspace# i686-w64-mingw32-gcc -o win.exe win.c 
root@ubuntu1:/home/edemon/workspace# file win.exe
win.exe: PE32 executable (console) Intel 80386, for MS Windows
root@ubuntu1:/home/edemon/workspace# file win.s
win.s: assembler source, ASCII text
root@ubuntu1:/home/edemon/workspace# cat win.s
    .file   "win.c"
    .def    ___main;    .scl    2;  .type   32; .endef
    .section .rdata,"dr"
LC0:
    .ascii "hello\0"
    .text
    .globl  _main
    .def    _main;  .scl    2;  .type   32; .endef
_main:
    pushl   %ebp
    movl    %esp, %ebp
    andl    $-16, %esp
    subl    $16, %esp
    call    ___main
    movl    $LC0, (%esp)
    call    _puts
    movl    $0, %eax
    leave
    ret
    .ident  "GCC: (GNU) 4.9.2"
    .def    _puts;  .scl    2;  .type   32; .endef
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值