再来说说linux中重要的alias命令------从findcpp命令说起
2015-10-10 23:32
507 查看
在软件开发中, 我们经常要到工程中查找"test"这个串所在的位置极相关信息。 当然, 如果您用source insight, 那也可以, 但快不快我就不保证了。 另外, 我发现, 如果在Win7的文件夹中要找这样的“test”, 那将是极为恼火的, 反正我搞不定。
还是用linux命令吧, 比如: find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir test
上面命令中的各个参数还是很容易懂的, 如果不清楚, man find一下, man grep一下, 就什么都知道了。 要善于利用linux自己提供的功能。
当然, 事情还没有完, 上面那一串太复杂了, 我们可以用alias来简化, 把下面语句放在主目录的.bashrc中:
alias findcpp='find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir'
保存.bashrc文件, 然后source ~/.bashrc使之生效(事实上, 以后每次打开shell, 都会自动执行这个命令, 所以上述的alias是可以生效的), 然后就有了:
这是多么美好的结果啊。 用alias, 事半功倍。 alias的本质就是别名。 用alias定义xxx后, 如果要取消, 则用unalias xxx即可。
我喜欢的用法是:
alias findcpp='find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir'
alias findtxt='find -depth -type f -iname "*.txt" | xargs grep --color -nE -ir'
alias findxml='find -depth -type f -iname "*.xml" | xargs grep --color -nE -ir'
alias findcfg='find -depth -type f -iname "*.cfg" | xargs grep --color -nE -ir'
alias findc='find -depth -type f -iname "*.c" | xargs grep --color -nE -ir'
alias findjava='find -depth -type f -iname "*.java" | xargs grep --color -nE -ir'
alias findh='find -depth -type f -iname "*.h" | xargs grep --color -nE -ir'
alias findsh='find -depth -type f -iname "*.sh" | xargs grep --color -nE -ir'
alias findini='find -depth -type f -iname "*.ini" | xargs grep --color -nE -ir'
alias findhtml='find -depth -type f -iname "*.html" | xargs grep --color -nE -ir'
alias findjs='find -depth -type f -iname "*.js" | xargs grep --color -nE -ir'
alias findcss='find -depth -type f -iname "*.css" | xargs grep --color -nE -ir'
alias findphp='find -depth -type f -iname "*.php" | xargs grep --color -nE -ir'
alias findmk='find -depth -type f -iname "*make*" | xargs grep --color -nE -ir'
alias findso='find -depth -type f -iname "*.so" | xargs strings -f | grep --color -nE -ir'
alias finda='find -depth -type f -iname "*.a" | xargs strings -f | grep --color -nE -ir'
alias findfile='find . -depth -type f -iname "*" | xargs md5sum | grep --color -nE -ir' # 实际上, 如果遇到错误信息, 则需要用如下:
alias findfile='find . -depth -type f -iname "*" 2>/dev/null | xargs md5sum 2>/dev/null | grep --color -nE -ir'
alias h='history 100 | grep -i'
alias tailf='tail -f'
还是用linux命令吧, 比如: find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir test
上面命令中的各个参数还是很容易懂的, 如果不清楚, man find一下, man grep一下, 就什么都知道了。 要善于利用linux自己提供的功能。
当然, 事情还没有完, 上面那一串太复杂了, 我们可以用alias来简化, 把下面语句放在主目录的.bashrc中:
alias findcpp='find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir'
保存.bashrc文件, 然后source ~/.bashrc使之生效(事实上, 以后每次打开shell, 都会自动执行这个命令, 所以上述的alias是可以生效的), 然后就有了:
[taoge@localhost ~]$ source ~/.bashrc [taoge@localhost ~]$ cat test.cpp hello world good hello ok [taoge@localhost ~]$ findcpp hello 1:hello 4:hello ok [taoge@localhost ~]$ touch b.cpp [taoge@localhost ~]$ findcpp hello ./test.cpp:1:hello ./test.cpp:4:hello ok [taoge@localhost ~]$
这是多么美好的结果啊。 用alias, 事半功倍。 alias的本质就是别名。 用alias定义xxx后, 如果要取消, 则用unalias xxx即可。
我喜欢的用法是:
alias findcpp='find -depth -type f -iname "*.cpp" | xargs grep --color -nE -ir'
alias findtxt='find -depth -type f -iname "*.txt" | xargs grep --color -nE -ir'
alias findxml='find -depth -type f -iname "*.xml" | xargs grep --color -nE -ir'
alias findcfg='find -depth -type f -iname "*.cfg" | xargs grep --color -nE -ir'
alias findc='find -depth -type f -iname "*.c" | xargs grep --color -nE -ir'
alias findjava='find -depth -type f -iname "*.java" | xargs grep --color -nE -ir'
alias findh='find -depth -type f -iname "*.h" | xargs grep --color -nE -ir'
alias findsh='find -depth -type f -iname "*.sh" | xargs grep --color -nE -ir'
alias findini='find -depth -type f -iname "*.ini" | xargs grep --color -nE -ir'
alias findhtml='find -depth -type f -iname "*.html" | xargs grep --color -nE -ir'
alias findjs='find -depth -type f -iname "*.js" | xargs grep --color -nE -ir'
alias findcss='find -depth -type f -iname "*.css" | xargs grep --color -nE -ir'
alias findphp='find -depth -type f -iname "*.php" | xargs grep --color -nE -ir'
alias findmk='find -depth -type f -iname "*make*" | xargs grep --color -nE -ir'
alias findso='find -depth -type f -iname "*.so" | xargs strings -f | grep --color -nE -ir'
alias finda='find -depth -type f -iname "*.a" | xargs strings -f | grep --color -nE -ir'
alias findfile='find . -depth -type f -iname "*" | xargs md5sum | grep --color -nE -ir' # 实际上, 如果遇到错误信息, 则需要用如下:
alias findfile='find . -depth -type f -iname "*" 2>/dev/null | xargs md5sum 2>/dev/null | grep --color -nE -ir'
alias h='history 100 | grep -i'
alias tailf='tail -f'
相关文章推荐
- Visual EmbedLinux Tools 更新到 0.1.7
- GNU/Linux 与开源文化的那些人和事
- Linux syslog (linux系统日志)
- linux echo设置颜色
- linux echo设置颜色
- linux根目录下各文件夹的作用
- windows8.1+centos7双系统(装完centos后无win8引导)
- linux多命令协作:管道及重定向
- Linux下软件安装-RPM与YUM
- centos开机运行级别更改
- linux主要目录结构
- Linux环境变量与文件查找,转载自实验楼
- 读鸟哥的Linux后对操作系统的初识
- Linux中cp和scp命令的使用方法
- 每天进步一点点——Linux系统时间来处理
- 第 二 十 六 天 :DNS 服 务 简 单 配 置
- debian 源
- Install Caffe on CentOS 6.5
- VMware虚拟机克隆Linux系统后找不到eth0网卡的问题
- Linux 目录结构及文件基本操作,转载自实验楼