Linux下的一些使用经验小结


最近跟Linux下的一些脚本测试打交道比较多,踩了不少坑,也总结了不少经验,在此记录一下,做个备忘。

1.如何创建大量测试数据?(单个大文件)

搜索关键字:http://search.aol.com/aol/search?q=linux+how+to+make+big+file+for+test

参考链接:
解决方案:

推荐使用fallocate命令;其次是dd命令;再次就是seq命令重定向到文件了。

2.如何创建大量测试数据?(大量小文件)

搜索关键字:http://search.aol.com/aol/search?q=Linux+how+to+make+many+small+files

参考链接:
解决方案:

One command to create 26 empty files:

$ touch {a..z}.txt

or 152:

$ touch {{a..z},{A..Z},{0..99}}.txt

A small loop to create 152 files with some contents:

for f in {a..z} {A..Z} {0..99}
do
    echo hello > "$f.txt"
done

You can do numbered files with leading zeros:

for i in {0..100}
do
    echo hello > "File$(printf "%03d" "$i").txt"
done

or, in Bash 4:

for i in {000..100}
do
    echo hello > "File${i}.txt"
done
3.一次创建多个目录

搜索关键字:http://search.aol.com/aol/search?q=linux+create+multiple+directory+at+once

参考链接:
解决方案:
$ mkdir monitor_log big_message error_log exec_log  #一行指定多个即可
4.一行创建多个嵌套子目录

In Bash and other shells that support it, you can do:

$ mkdir ~/Labs/lab4a/folder{1..3}

or

$ mkdir ~/Labs/lab4a/folder{1,2,3}

Use shell expansion:

$ mkdir Labs/lab4a/{folder1,myfolder,foofolder}
5.Bash脚本错误“unary operator expected”

搜索关键字:http://search.aol.com/aol/search?q=unary+operator+expected

参考链接:
解决方案:

It doesn’t give me that error. Nonetheless, if you’re using bash it’s better to use the builtin [[ than the test ([) command.

if [[ $i -ge 2 ]]

即,推荐使用“[[”而不是“[”,因为不知道什么时候错误就出现了。

6.Linux的ps命令aux选项说明
搜索/参考链接:

 

7.Linux下查看目录的大小
搜索/参考链接:

 

8.Bash中变量的连接
搜索/参考链接:

使用’{}’来连接普通字符串和变量。

 

9.Linux下查看大文件的几个小技巧

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注