我们可以在Linux里面通过多个命令来创建文件:
- touch命令创建文件:
-创建单个文件:
[[email protected]
oldboy]# touch oldboy
[[email protected]
oldboy]# ll
总用量 0
4325378 -rw-r--r-- 1
root root 0 2017-05-27 13:30 oldboy
-创建多个文件:
[[email protected] oldboy]# touch oldboy1 oldboy2
oldboy3 (直接接多个文件名来创建)
[[email protected]
oldboy]# ll
总用量0
4325378
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy
4325381
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy1
4325382
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy2
4325383
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy3
[[email protected] oldboy]# touch oldboy{10..20} (按照指定的格式来快速创建,你可以修改为{1..10000}来试试你服务器的速度)
[[email protected]
oldboy]# ll
总用量0
4325378
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy
4325381
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy1
4325384
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy10
4325385
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy11
4325386
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy12
4325387
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy13
4325388
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy14
4325389
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy15
4325390
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy16
4325391
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy17
4325392
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy18
4325393
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy19
4325382
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy2
4325394
-rw-r--r-- 1 root root 0 2017-05-27 11:19 oldboy20
4325383
-rw-r--r-- 1 root root 0 2017-05-27 11:18 oldboy3
- echo命令创建文件:
[[email protected] oldboy]# echo oldboy
>oldboy.txt (创建带“oldboy"内容的文件)
[[email protected]
oldboy]# ll
总用量4.0K
4325378
-rw-r--r-- 1 root root 7 2017-05-27 13:01 oldboy.txt
[[email protected]
oldboy]# cat oldboy.txt
oldboy
[[email protected] oldboy]# echo >oldboy1.txt (创建空文件)
[[email protected]
oldboy]# ll
总用量8.0K
4325381
-rw-r--r-- 1 root root 1 2017-05-27 13:02 oldboy1.txt
4325378
-rw-r--r-- 1 root root 7 2017-05-27 13:01 oldboy.txt
[[email protected]
oldboy]# cat oldboy1.txt
[[email protected]
oldboy]#
- vim或者vi命令创建文件:
[[email protected] oldboy]# vim oldboy.sh
vim使用方法:
进去vim之后按i, 进入编辑模式;
在里面输入内容之后按Esc退出编辑模式
输入 :wq 保存创建的文件
[[email protected]
oldboy]# ll
总用量4.0K
4325381
-rw-r--r-- 1 root root 30 2017-05-27 13:07 oldboy.sh
[[email protected]
oldboy]# cat oldboy.sh
I
like study Linux very much!
- dd命令创建文件 (dd创建的文件类型是data,可以创建固定大小的文件,可作为分区挂载使用)
[[email protected]
oldboy]# dd if=/dev/zero of=/oldboy/oldboy.txt
bs=10K count=1
记录了1+0的读入
记录了1+0的写出
10240字节(10 kB)已复制,0.000171358 秒,59.8 MB/秒
[[email protected]
oldboy]# ll
总用量16K
4325382
-rw-r--r-- 1 root root 30 2017-05-27
13:11 oldboy.sh
4325378
-rw-r--r-- 1 root root 10K 2017-05-27
13:13 oldboy.txt
[[email protected]
oldboy]#
创建文件夹的方法:
- mkdir 命令创建文件夹:
1. 创建单个文件夹:
[[email protected] oldboy]# mkdir oldboy_folder (创建单个文件夹)
[[email protected]
oldboy]# ll
总用量20K
4325381
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:14 oldboy_folder
[[email protected]
oldboy]# mkdir /home/root/oldgirl_folder (加绝对路径来创建其他路径下面的文件夹 )
[[email protected]
~]# cd /home/root
[[email protected]
root]# ll
总用量4.0K
786451
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:25 oldgirl_folder
[[email protected]
root]#
2. 创建多个文件夹:
[[email protected] oldboy]# mkdir oldboy_folder1
oldboy2 oldboy3 (直接接多个文件名来创建)
[[email protected] oldboy]# ll
总用量32K
4325384
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:15 oldboy2
4325385
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:15 oldboy3
4325381
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:14 oldboy_folder
4325383
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:15 oldboy_folder1
[[email protected] oldboy]# mkdir oldboy{20..25} (按照指定的格式来快速创建多个文件夹)
[[email protected]
oldboy]# ll
总用量60K
4325386
drwxr-xr-x 3 root root 4.0K 2017-05-27 13:17 oldboy10
4325384
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:15 oldboy2
4325389
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy20
4325390
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy21
4325391
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy22
4325392
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy23
4325393
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy24
4325394
drwxr-xr-x 2 root root 4.0K 2017-05-27 13:21 oldboy25
3. 创建多层文件夹:
[[email protected] oldboy]# mkdir
oldboy10/oldboy1010/oldboy101010 -p (一次性创建了3层文件夹;需要使用-p命令,-p命令是先创建父文件夹然后再创建下一级文件)
[[email protected]
oldboy]# tree
.
├──
oldboy10
│??
└── oldboy1010
│?? └── oldboy101010
├──
oldboy2
├──
oldboy3
更多内容请查看老男孩老师的书籍:《跟老男孩学习Linux运维:Web集群实战》或者运维课程。