---
title: "Shell 自动化部署：杂记"
author: "bertLee"
date: "2011-07-22T15:50:57Z"
tags: []
categories: ["编程语言"]
slug: "shell"
draft: false
lastmod: "2011-07-22T16:33:41Z"
id: 1130750
url: "https://bertlee.iteye.com/blog/1130750"
---

本文以 Ubuntu Server 10.04 为例，下面只是简单记录一些东西，以后会整理成文件发布出来。

1\. 使用 tar 工具进行文件压缩与解压缩

```
# 压缩 test 整个目录
tar -zcvf test.tar.gz ./test

# 解压缩 test.tar.gz 到当前目录的 test 文件中
tar -xzvf test.tar.gz -C ./test
```

参考自：[tar - BackupYourSystem](https://help.ubuntu.com/community/BackupYourSystem/TAR) 、[Ubuntu 命令技巧之解压缩](http://wiki.ubuntu.org.cn/UbuntuSkills#.E8.A7.A3.E5.8E.8B.E7.BC.A9_xxx.tar.gz) 、[tar - Shell Scripts](https://help.ubuntu.com/10.04/serverguide/C/backup-shellscripts.html) 、[GNU tar Manual - 3.4.3 Short Options Cross Reference](http://www.gnu.org/software/tar/manual/html_chapter/tar-invocation.html#SEC40)

 

2\. 输出 IP 地址、默认网关及子网掩码

```
ifconfig eth0 | awk '/Bcast/ {for (i = 1; i <= NF; i++) { n = split($i,x,":"); if (n >= 2 ) { print x[2] } } }'
```

参考自：[查看当前IP地址](http://wiki.ubuntu.org.cn/UbuntuSkills#.E6.9F.A5.E7.9C.8B.E5.BD.93.E5.89.8DIP.E5.9C.B0.E5.9D.80) 、[awk manual](http://manpages.ubuntu.com/manpages/hardy/man1/9base-awk.1.html) 、[网络配置](https://help.ubuntu.com/8.04/serverguide/C/network-configuration.html)