网站首页 > linux / 正文
touch
用于创建空白文件
touch 文件名称
mkdir
用于创建空白目录
还可以通过参数 -p创建递归的目录
mkdir -p a/b/c
cp
用于复制文件或目录
cp 源文件 目标文件
有三种情况:
1、如果目标文件是目录,则将源文件复制到该目录中
2、如果目标文件也是普通文件,则询问是否要覆盖
3、如果目标文件不存在,则执行正常的操作
header 1 | header 2
—-|—-
-p | 保留原始文件的属性
-d | 若对象为链接文件,则保留该链接文件属性
-r | 递归持续复制(用于目录)
-i | 若目标文件存在,则询问是否需要覆盖
-a | 相当于-pdr(pdr为上述的参数)
mv
用于剪切文件或将文件重命名
mv 源文件 目标路径或目标文件名
rm
用于删除文件或目录
-f 参数可以执行强制删除
-r 若删除的是一个目录,需要在rm后加上该参数,否则删不掉
file
用于查看文件类型
在 Linux 系统中,由于文本、目录、设备等所有这些一切都统称为文件,而我们又不能单凭后缀就知道具体的文件类型,这时就需要使用 file 命令来查看文件类型了。
file 文件名
ronghe@DESKTOP-SLVD5EM:~/a$ file b
b: directory
dd
用于按照指定大小和数量的数据块来复制或转换文件
dd 命令是一个比较重要而且比较有特色的一个命令,它能够让用户按照指定大小和个数的数据块来复制文件的内容。当然如果愿意的话,还可以在复制过程中转换其中的数据。Linux系统中有一个名为
/dev/zero
的设备文件,每次在课堂上解释它时都充满哲学理论的色彩。因为这个文件不会占用系统存储空间,但却可以提供无穷无尽的数据,因此可以使用它作为 dd命令的输入文件,来生成一个指定大小的文件。
header 1 | header 2
—-|—-
if | 输入的文件名称
of | 输出的文件名称
bs | 设置每个块的大小
count | 设置要复制块的个数
从/dev/zero 设备文件中取出一个大小为 560MB 的数据块,然后
在家目录下保存成名为 560_file 的文件。在理解了这个命令后,以后就能随意创建任意大小的文件了:
ronghe@DESKTOP-SLVD5EM:~$ dd if=/dev/zero of=560_file count=1 bs=560M
1+0 records in
1+0 records out
587202560 bytes (587 MB, 560 MiB) copied, 3.90245 s, 150 MB/s
ronghe@DESKTOP-SLVD5EM:~$
ronghe@DESKTOP-SLVD5EM:~$ ls -al
total 573468
-rw-rw-r-- 1 ronghe ronghe 5 Jun 22 17:13 '!!'
drwxr-xr-x 1 ronghe ronghe 4096 Jun 30 10:31 .
drwxr-xr-x 1 root root 4096 Jun 1 11:07 ..
-rw------- 1 ronghe ronghe 5147 Jun 26 11:58 .bash_history
-rw-r--r-- 1 ronghe ronghe 220 Jun 1 11:07 .bash_logout
-rw-rw-rw- 1 ronghe ronghe 11 Jun 17 14:46 .bash_profile
-rw-r--r-- 1 ronghe ronghe 3771 Jun 1 11:07 .bashrc
drwx------ 1 ronghe ronghe 4096 Jun 22 15:52 .config
drwxr-xr-x 1 ronghe ronghe 4096 Jun 1 11:07 .landscape
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:47 .motd_shown
-rw-r--r-- 1 ronghe ronghe 807 Jun 1 11:07 .profile
-rw------- 1 ronghe ronghe 12 Jun 1 15:06 .python_history
-rw-r--r-- 1 ronghe ronghe 0 Jun 15 11:29 .sudo_as_admin_successful
-rw------- 1 ronghe ronghe 10942 Jun 22 17:13 .viminfo
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:48 123
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 10:12 123.txt
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:51 '2017-06-5 15:30'
-rw-rw-rw- 1 ronghe ronghe 587202560 Jun 30 10:31 560_file
通过ls查询可以看到,在家目录下确实创建了一个560_file
也可以通过dd命令来实现文件类型的转换,不需要像windows中要借助第三方软件
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:48 123
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 10:12 123.txt
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:51 '2017-06-5 15:30'
-rw-rw-rw- 1 ronghe ronghe 587202560 Jun 30 10:31 560_file
drwxrwxrwx 1 ronghe ronghe 4096 Jun 30 10:14 a
-rw-r--r-- 1 root root 97 Jun 22 17:26 example.sh
drwxrwxrwx 1 ronghe ronghe 4096 Jun 22 16:48 linuxprobe
-rw-rw-r-- 1 ronghe ronghe 32 Jun 22 16:57 practice.txt
ronghe@DESKTOP-SLVD5EM:~$ dd if=123.txt of=123.pdf
0+0 records in
0+0 records out
0 bytes copied, 0.0015158 s, 0.0 kB/s
ronghe@DESKTOP-SLVD5EM:~$ ls -al
total 573468
-rw-rw-r-- 1 ronghe ronghe 5 Jun 22 17:13 '!!'
drwxr-xr-x 1 ronghe ronghe 4096 Jun 30 10:35 .
drwxr-xr-x 1 root root 4096 Jun 1 11:07 ..
-rw------- 1 ronghe ronghe 5147 Jun 26 11:58 .bash_history
-rw-r--r-- 1 ronghe ronghe 220 Jun 1 11:07 .bash_logout
-rw-rw-rw- 1 ronghe ronghe 11 Jun 17 14:46 .bash_profile
-rw-r--r-- 1 ronghe ronghe 3771 Jun 1 11:07 .bashrc
drwx------ 1 ronghe ronghe 4096 Jun 22 15:52 .config
drwxr-xr-x 1 ronghe ronghe 4096 Jun 1 11:07 .landscape
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:47 .motd_shown
-rw-r--r-- 1 ronghe ronghe 807 Jun 1 11:07 .profile
-rw------- 1 ronghe ronghe 12 Jun 1 15:06 .python_history
-rw-r--r-- 1 ronghe ronghe 0 Jun 15 11:29 .sudo_as_admin_successful
-rw------- 1 ronghe ronghe 10942 Jun 22 17:13 .viminfo
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 09:48 123
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 10:35 123.pdf
-rw-rw-rw- 1 ronghe ronghe 0 Jun 30 10:12 123.txt
?
Tags:linux保存文件命令
- 上一篇:linux之history命令
- 下一篇:Linux tar打包命令详解
猜你喜欢
- 2024-11-26 linux-文件目录指令
- 2024-11-26 linux文档编辑的命令都有哪些?linux命令详解
- 2024-11-26 Linux 压缩命令
- 2024-11-26 Linux的so文件到底是干嘛的?浅析Linux的动态链接库
- 2024-11-26 Linux的常用命令就是记不住,怎么办?于是推出了这套教程
- 2024-11-26 Linux 误删文件恢复命令及方法
- 2024-11-26 Linux常用的命令学习笔记
- 2024-11-26 linux实例之swapfile文件
- 2024-11-26 10新手学习:Linux文件管理(4)
- 2024-11-26 linux中的route命令使用