Linux BASH command

本文档记录了一些常用的Bash命令,包括构建日志显示及记录、格式化转换十六进制和十进制数字、文件中搜索和替换字符串、查看可执行文件结构等,适用于日常的脚本编写和命令行操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 problemMany 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. headtaillsechosedtar -vwcwhich).

 

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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值