首页 > 代码库 > Linux常用命令汇总

Linux常用命令汇总

1、获取文件全路径
每次拼凑路径比较麻烦,希望一个命令能给出包含机器名的完整路径:
$ ls | sed "s:^:`pwd`/:" | sed "s/^/$HOSTNAME:/g"

[root@test1 test]# ls | sed "s:^:`pwd`/:" | sed "s/^/$HOSTNAME:/g"
test1:/root/test/t_t_20090301032655ttxt
test1:/root/test/t_t_20090301032655.txt

2、grep高亮显示匹配的关键词

ls|

3、Java程序调用脚本

#!/bin/bash#by system#date:20120709#for javaclasses=/home/httpd/search.example.com/WEB-INF/classesservlet="$classes":/usr/local/tomcat/lib/servlet-api.jarjardir=/home/httpd/search.example.com/WEB-INF/libJPATH="$servlet"for j in `ls /home/httpd/search.example.com/WEB-INF/lib/*.jar`do# echo $jJPATH="$JPATH":"$j"# echo $JPATHdone/usr/local/jdk1.6.0_30/bin/java -classpath $JPATH com.cnfol.search.IndexCreator.IndexCreato

  

4、tar
(1)--exclude

# tar -czvf test.tar.gz . --exclude cpTest.sh --exclude /root/test/test222222cp2222.txt
./
./test222222cp2222.txt
./batch_almfilter_20090301032655.txt
./test.tar.gz
./batch_almfilter_20090301032655ttxt

如有目录xxx, 下面多个文件并有目录tt和ppp,如只想打包文件而不想打包两目录,应用使用如下命令:
tar -czvf mm.tgz xxx/ --exclude xxx/tt --exclude xxx/ppp
注意:exclude后面子目录不要跟斜杠"/",否则exclude无效.

 

Linux常用命令汇总