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
|