Johnny's tech blog

« 上一篇: BitVector 下一篇: Genome Terminal启动参数 »
Johnny @ 2010-03-30 08:10

ls -l | grep "^-" | awk '{print "dollar"8}' | xargs tar zcvf xxx.tar.gz

Brief explanation: 
ls -l | grep "^-" is used to find all files under current directory, not include folders;
awk '{print "dollar"8}' is used to grab out the file names from the ls output;
xargs is used to get the output of ls and grep as command line arguments and pass to tar.

If you only want to exlude a few sub folders, you can use "--exclude" of tar command.
Example:
Exclude "attach" and "images" folders under "site" folder:
tar zcvf backup.tar.gz site/* --exclude=site/attach --exclude=site/images

简单解释一下:
ls -l | grep “^-" 用来把当前目录下所有文件列出来,不包括子目录;
awk '{print "dollar"8}' 用来把ls和grep输出的文件名取出来;
xargs 将前面一串的输出,也就是一个文件名的列表组织成一个参数传递给tar命令。

如果只是排除一两个目录,可以用tar命令的--exclude= 选项。
例如排除site目录下的attach和images目录:
tar zcvf backup.tar.gz site/* --exclude=site/attach --exclude=site/images





评论 / 个人网页 / 扔小纸条
*昵称

已经注册过? 请登录

Email
网址
*评论
 


 
网志分类
所有日志 (91)
perl (8)
C/C++编程 (10)
Windows技术 (20)
*nix技术 (13)
乱七八糟的 (31)
Web安全 (1)
软件收藏 (1)
入侵与防御 (2)
Thoughts (1)
未分类 (4)
站内搜索
友情链接
我的歪酷

歪酷博客

订阅 RSS

 

0037704