echo -e "\033[46m Hello World"
echo -e "\033[0m Hello World"
输出结果:

你可以对上面的列子举一反三,把它用到你自己的脚本中去。
例子三:加密文件/目录
下面的例子演示了如何加密一个份文件或者文件夹。目前的这个版本的脚本有一些局限,例如你必须把它和你要加密的文件/目录放到同一个文件夹下面。另外,你可能需要安装“pinentry-gui”。在Fedora下安装“pinentry-gui”的命令是:
[root@midstage ~]# yum install pinentry-gui
在Ubuntu/Debian下安装“pinentry-gui”的命令是:
[root@midstage ~]# apt-get install pinentry-gui
创建一个脚本“Encrypt.sh”,将下面的代码复制进去。你也可以从这里下载这个脚本。
#!/bin/bash
echo "Welcome, I am ready to encrypt a file/folder for you"
echo "currently I have a limitation, Place me to the same folder,
where a file to be encrypted is present"
echo "Enter the Exact File Name with extension"
read file;
gpg -c $file
echo "I have encrypted the file sucessfully..."
echo "Now I will be removing the original file"
rm -rf $file
输出结果:
[root@tecmint ~]# chmod 755 Encrypt.sh
[root@tecmint ~]# ./Encrypt.sh
Welcome, I am ready to encrypt a file/folder for you
currently I have a limitation, Place me to the same folder,
where a file to be encrypted is present
Enter the Exact File Name with extension
package.xml
Enter passphrase
Passphrase _________________________________
Please re-enter this passphrase
Passphrase _________________________________
I have encrypted the file successfully...
Now I will be removing the original file
代码说明:
gpg -c: 这个命令使用aka来加密文件。 在你需要的时候,你需要对加密的文件进行解密。这里我们不给出具体的代码了,你可以自己尝试着写出来。提示:使用命令 gpg -d filename.gpg > filename 可以解密一份文件。
例子四:查看服务器利用率
查看服务器的利用率是管理员的一份重要的日常工作。聪明的管理员是知道如何是这份任务自动化的。下面的这份脚本会抓取服务器的很多信息,快快试试吧!










