Intro
This page records some bash command.
Build logs show in console and record in file
$ make 2>&1 | tee log.txt
Printf to convert hexadecimal and decimal integer numbers, simple calculator in terminal
$ printf "%d" 0x12974
76148
$ printf "0x%x" 76148
0x12974
$ echo $((3827+99))
3926
$ expr 3827 + 99
3926
size to show executable file structure
$ size ksstudio.exe
text data bss dec hex filename
562505 80896 0 643401 9d149 ksstudio.exe
$ size hdaudio.sys
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section CODE
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .rdata
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .pdata
size: hdaudio.sys: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .idata
text data bss dec hex filename
435078 2928 0 438006 6aef6 hdaudio.sys
Grep and replace strings in files
grep xxxx ./* -rl | xargs sed -i '' 's/xxxx/yyyy/g'
Note: In-place edits with sed on OS X
Grep inside the specific file type
huntercao$ find . -name '*.h' -print0 | xargs -0 grep XXYYZZZ -n
Note: The separator problem, Many Unix utilities are line oriented. These may work with xargs
as long as the lines do not contain ', " or space. Some of the Unix utilities can use NUL as record separator (e.g. Perl (requires -0
and \0
instead of \n
), locate
(requires using -0
), find
(requires using -print0
), grep
(requires -z
or -Z
), sort
(requires using -z
)). Using -0
for xargs deals with the problem, but many Unix utilities cannot use NUL as separator (e.g. head
, tail
, ls
, echo
, sed
, tar -v
, wc
, which
).
Note:
Command line below:
huntercao$find . -name *.h
Get error:
find: xxxx.h: unknown primary or operator
Error reason:
* is expanded by the shell before the command-line is passed to find(1). If there's only 1 item in the directory, then it works. If there's more than one item in the directory, then it fails as the command-line options are no longer correct.
You have to escape the * so that find does the expansion internally.
Find the process and kill it:
huntercao$ ps -ax | grep ***
huntercao$ kill xxx