hsy75的个人空间 https://blog.eetop.cn/vivilife [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

[bz][LINUX command 002] 嵌入式常用的命令

已有 2081 次阅读| 2013-6-20 13:24 |个人分类:linux

1 find & grep 实例: 

grep -参数 "匹配目的内容" 要匹配文件目标

举例

1.1 grep 查找某个文件夹下所有文件中的字符

用grep 命令查找一个文件夹下,所有的编译选项含-diretfb的文件,比如makefile

grep -r "-diretfb" ./

fgrep -r directfb ./ > yourmake.log

1.2 grep 查找某个文件内的字符

从文件内容查找匹配指定字符串的行:
$ grep "被查找的字符串" 文件名
从文件内容查找与正则表达式匹配的行:
$ grep –e “正则表达式” 文件名
查找时不区分大小写
$ grep –i "被查找的字符串" 文件名
查找匹配的行数
$ grep -c "被查找的字符串" 文件名
从文件内容查找不匹配指定字符串的行:
$ grep –v "被查找的字符串" 文件名

1.3 grep 和 find 结合使用,可以查找特定文件中含特定字符的文件并打印报错,这个功能比windows的强大的多

1.3.1 从根目录开始查找所有的文件中含有的某个字符串的文件 和find连用
从根目录开始查找所有扩展名为.xml的文本文件,找到的结果用xargs分解,然后从找到的文件中找出包含”username”的行
find / -type f -name "*.xml" | xargs grep "username"

find 的结果往往很大,直接存档到文件再查看 【> find_usename_log.txt 】加到上面的命令后面

更多例子如下:

the following is the often used comand that used to search a project C files for a demand key words "play_open",and all the result include the error result would list in the txt file

find ./ -type f -name "*.c" | xargs grep "player_open" > find_player_open.txt 2>&1

find ./ -type f -name "*.*" | xargs grep "GOODMAN" > find_GOODMAN.txt 2>&1


为了便于理解,有关于xargs的描述: 如下:http://blog.csdn.net/zhangfn2011/article/details/6776925

1.3.2 查找项目中所有的编译后产生的config.log中各种Lib的编译工具gcc的版本是否一致:

find . -type f -name "*config.log" | xargs grep "gcc version"


2 擦写

一个文件,往往用于嵌入式中擦写flash设备

1. 产生一个全0xFF, 0xA5, 0xAA 的文件

tr '\000' '\377' < /dev/zero| dd f=file_0xFF.bin  bs=2k count=1 // 用到的比较多
tr '\000' '\245' < /dev/zero| dd f=file_0xA5.bin  bs=2k count=1
tr '\000' '\252' < /dev/zero| dd f=file_0xAA.bin  bs=2k count=1


3. Find 的组合操作举例

3.0 find ./ -type d -name '.svn*' | xargs rm  -rf
找到并删除 名字里面带 svn的folder...

 命令对找到文件执行多个操作

find -name abc.txt  -exec touch {} \; -exec ls -l {} \; -exec cat {} \;

3.1 Find 命令找两种以上的文件

find .  \( -name "makefile" -o  -name "*.patch" -o  -name "*.txt" \)

3.2 find 和grep连用

hsy75:查找根目录或者当前文件夹下,文件后缀为filetype的文件名为filename的文件

find / | grep "filename\.filetype$"

举例:

要查找根目录下directfb.a的动态库

find / | grep "directfb\.a$"

得到结果:

apps/directfb/DirectFB-1.4.3/src/.libs/libdirectfb.a
apps/usr/lib/libdirectfb.a
/opt/lib/libdirectfb.a
/debug/lib/libdirectfb.a
/usr/lib/libdirectfb.a


3.3 一些从man page里面的复杂的find 的例子,介绍的非常详细

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

#从根目录查找当天变化的文件

find $HOME -mtime 0 

       Search for files in your home directory which have been modified in the last twenty-four hours.  This command works this way because the time since
       each  file  was last modified is divided by 24 hours and any remainder is discarded.  That means that to match -mtime 0, a file will have to have a
       modification in the past which is less than 24 hours ago.

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

   cd /source-dir
       find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
       cpio -pmd0 /dest-dir

       This  command  copies  the  contents  of /source-dir to /dest-dir, but omits files and directories named .snapshot (and anything in them).  It also
       omits files or directories whose name ends in ~, but not their contents.  The construct -prune -o \( ... -print0 \) is quite common.  The idea here
       is  that  the  expression before -prune matches things which are to be pruned.  However, the -prune action itself returns true, so the following -o
       ensures that the right hand side is evaluated only for those directories which didn't get pruned (the contents of the pruned  directories  are  not
       even  visited,  so  their contents are irrelevant).  The expression on the right hand side of the -o is in parentheses only for clarity.  It empha‐
       sises that the -print0 action takes place only for things that didn't have -prune applied to them.  Because the  default  `and'  condition  between
       tests binds more tightly than -o, this is the default anyway, but the parentheses help to show what is going on.

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

       find repo/ -exec test -d {}/.svn -o -d {}/.git -o -d {}/CVS ; \
       -print -prune

       Given the following directory of projects and their associated SCM administrative directories, perform. an efficient search for the projects' roots:

       repo/project1/CVS
       repo/gnu/project2/.svn
       repo/gnu/project3/.svn
       repo/gnu/project3/src/.svn
       repo/project4/.git

       In  this example, -prune prevents unnecessary descent into directories that have already been discovered (for example we do not search project3/src
       because we already found project3/.svn), but ensures sibling directories (project2 and project3) are found.


4. echo 代替键盘输入

echo -e “\n\n\n”  三个回车

从   AC_MGMT 中摘录的echo 代替键盘输入的 片段

 18 useradd $AC_ID -g $GRP_ID -m && \
 19 echo -e "$AC_ID\n$AC_ID\n"|passwd  $AC_ID && \
 20 echo "Create Successfully."
 21 echo "Enabling Samba For $AC_ID..."
 22 echo -e "$AC_ID\n$AC_ID\n$AC_ID\n"|smbpasswd -s -a $AC_ID && \
 23 smbpasswd -e $AC_ID
 24 echo "Samba Account for $AC_ID Done."

hsy75案:echo -e 是shell command 处理经常用到的方法,用来自动输入用户的输入,上文,根据用户输入变量AC_ID自动创立了一个samba的用户

当然,变量AC_ID应该要用户自己输入的


 

5. 利用变量内嵌执行

找到所有ko并copy

cp $(find *.ko) to_dir


6. 暂停运行程序和恢复

CTRL-Z    暂停运行程序
jobs      查看当前任务列表
fg num    前台运行任务列表中 num 任务
bg num    后台运行任务列表中 num 任务


7. 无终端运行程序

a.  nohup  <command>
b.  利用括号() 使进程成为 init(pid=1) 的子进程
    (ping 192.168.0.1 &)
    可用 ps -ef  看到 进程PID 和父进程PPID


8:

将tar 和find 结合,选定目录下指定的文件类型进行打包解压:中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台?)`G&S9p6d,T!A#VB


tar命令用语对文件进行归档以及恢复归档文件,中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台V(H|/|L
"tar xzvf"命令用于释放<恢复>".tar.gz"格式压缩的归档文件;中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台h#~z'a!~G)@ _Ev4])H
"tar xvf"命令用于释放<恢复>".tar"格式压缩的归档文件;
$vOG9^)Bz:V Z51552"tar xjvf"命令用于释放<恢复>".tar.b2z"格式压缩的归档文件;中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台 F4Z'QH \*Im1w

4\XsK*~#q51552tar xzvf +软件包名称 |find . -type f -name "*.cpp "
中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台8_9^7X`N5g


打包 : tar cvf + 打包后文件名 + 需打包文件夹名
tar -cvf target_file.tar target_folder/
或者有选择的压缩
tar cvjf file-cpp.tar.bz2 | find . -type f -name "*.cpp"中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台8L)IK8?6[5X!B&C
或者中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台d'UCe:Y j~ l
find . -type f -name "*.cpp" | xargs tar zcvpf backup.tar.gz
-O/_V\JM51552中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台!VTc[^8C)d1\h ?c
z c&r;ji8N&Lk~5155


9 给文件夹打补丁:

1 进入你需要补丁的文件夹:

wine@ubuntu:~/directfb_4.1/DirectFB-1.4.3$

2 执行补丁程序:

patch -p1 < ../DirectFB-1.4.3.patch 


10 chmod
要求就是:
1、将当前目录中的所有“子目录”的权限设置为755;
2、将当前目录中的所有“文件”的权限设置为644。
解决方法:
chmod 644 -R *
chmod 755 `find -type d`
也可以用:
用find彻底些
find /path -type f -exec chmod 644 {} /;
find /path -type d -exec chmod 755 {} /;


将*.jpg文件名中的09v9改为0919
Zianed@ubuntu:~/public_web_sSmO9OUVY1/files/image$ rename s/09v9/0919/’ *.jpg


ref:中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台5m yW u,`m8a9u}.~wu
1
|2Y(X6t:r)T L51552http://ss64.com/bash/tar.html中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台s8n"^Q l)`F
2 中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台lp2tsp$?x \z
http://topic.csdn.net/u/20071112/18/5630fa3e-d0cf-43ed-bc88-fb048ef1e482.html
o'j"o#Q0U FN515523中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台!^I&Y!Gp;b
http://zh.wikipedia.org/wiki/Xargs中国电子顶级开发网(EETOP)-电子设计论坛、博客、超人气的电子工程师资料分享平台I(j!f OF7C Og
ref:

http://www.eetop.cn/blog/?uid-51552-action-viewspace-itemid-26822


ref:

http://www.linuxso.com/command/


2012-12-21 add a find example for list vary result in search a key words in a project files

2013-04-10 add more good command

 

 


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 1

    好友
  • 2

    获赞
  • 14

    评论
  • 3241

    访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-19 06:13 , Processed in 0.013334 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部