


Detailed explanation of the dd command in Linux
Detailed explanation of the dd command in Linux: 1. dd copies a file using blocks of the specified size, and performs specified conversions while copying; 2. [if=filename] enter the file name, the default is standard Input; 3. [of=file name] output file name, the default is standard output.
##Related learning recommendations: linux video tutorial
Detailed explanation of the dd command in Linux:
1. Explanation of the dd command
dd: Copy a block with a specified size file, and perform specified conversions while copying. Note: If the place where the number is specified ends with the following characters, the corresponding number will be multiplied: b=512; c=1; k=1024; w=2 Parameter comments: 1. if=filename: input filename, the default is standard input. That is, specify the source file. < if=input file >2, of=file name: output file name, the default is standard output. That is, specify the destination file. < of=output file >ibs=bytes:一次读入bytes个字节,即指定一个块大小为bytes个字节。 obs=bytes:一次输出bytes个字节,即指定一个块大小为bytes个字节。
ascii:转换ebcdic为ascii ebcdic:转换ascii为ebcdic ibm:转换ascii为alternate ebcdic block:把每一行转换为长度为cbs,不足部分用空格填充 unblock:使每一行的长度都为cbs,不足部分用空格填充 lcase:把大写字符转换为小写字符 ucase:把小写字符转换为大写字符 swab:交换输入的每对字节 noerror:出错时不停止 notrunc:不截短输出文件 sync:将每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐。
2. dd application example
1. Back up the entire local /dev/hdb disk to /dev/hdd#dd if=/dev/hdb of=/dev/hdd
#dd if=/dev/hdb of=/root/image
#dd if=/root/image of=/dev/hdb
#dd if=/dev/hdb | gzip > /root/image.gz
#gzip -dc /root/image.gz | dd of=/dev/hdb
#dd if=/dev/hda of=/root/image count=1 bs=512
#dd if=/root/image of=/dev/had
#dd if=/dev/fd0 of=disk.img count=1 bs=1440k (即块大小为1.44M)
#dd if=/dev/mem of=/root/mem.bin bs=1024 (指定块大小为1k)
#dd if=/dev/cdrom(hdc) of=/root/cd.iso
#dd if=/dev/zero of=/swapfile bs=1024 count=262144
#mkswap /swapfile
#swapon /swapfile
/swapfile swap swap default 0 0
#dd if=/dev/urandom of=/dev/hda1
#dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file #dd if=/root/1Gb.file bs=64k | dd of=/dev/null
#dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file #dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file #dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file #dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
#dd if=/dev/sda of=/dev/sda 或dd if=/dev/hda of=/dev/hda
#dd if=/dev/hda bs=16065b | netcat < targethost-IP > 1234
#netcat -l -p 1234 | dd of=/dev/hdc bs=16065b
#netcat -l -p 1234 | bzip2 > partition.img #netcat -l -p 1234 | gzip > partition.img
#echo A | dd of=bigfile seek=$i bs=1 count=1 conv=notrunc
# mkdir –p /u01/asmdisks
[root@book u01]# cd asmdisks [root@book asmdisks]# dd if=/dev/zero of=asm_disk1 bs=1024k count=400 [root@book asmdisks]# dd if=/dev/zero of=asm_disk2 bs=1024k count=400 [root@book asmdisks]# dd if=/dev/zero of=asm_disk3 bs=1024k count=400 [root@book asmdisks]# dd if=/dev/zero of=asm_disk4 bs=1024k count=400 [root@book asmdisks]# dd if=/dev/zero of=asm_disk5 bs=1024k count=400 [root@book asmdisks]# dd if=/dev/zero of=asm_disk6 bs=1024k count=400
[root@book asmdisks]# chmod 777 asm_disk* [root@book asmdisks]# losetup /dev/loop1 asm_disk1 [root@book asmdisks]# losetup /dev/loop2 asm_disk2 [root@book asmdisks]# losetup /dev/loop3 asm_disk3 [root@book asmdisks]# losetup /dev/loop4 asm_disk4 [root@book asmdisks]# losetup /dev/loop5 asm_disk5 [root@book asmdisks]# losetup /dev/loop6 asm_disk6
三、/dev/null和/dev/zero的区别
/dev/null,外号叫无底洞,你可以向它输出任何数据,它通吃,并且不会撑着!
/dev/zero,是一个输入设备,你可你用它来初始化文件。该设备无穷尽地提供0,可以使用任何你需要的数目——设备提供的要多的多。他可以用于向设备或文件写入字符串0。
/dev/null------它是空设备,也称为位桶(bit bucket)。任何写入它的输出都会被抛弃。如果不想让消息以标准输出显示或写入文件,那么可以将消息重定向到位桶。
#if=/dev/zero of=./test.txt bs=1k count=1 #ls –l total 4 -rw-r--r-- 1 oracle dba 1024 Jul 15 16:56 test.txt #find / -name access_log 2>/dev/null
3.1 使用/dev/null
把/dev/null看作"黑洞", 它等价于一个只写文件,所有写入它的内容都会永远丢失.,而尝试从它那儿读取内容则什么也读不到。然而, /dev/null对命令行和脚本都非常的有用
禁止标准输出
#cat $filename >/dev/null
文件内容丢失,而不会输出到标准输出.
禁止标准错误
#rm $badname 2>/dev/null
这样错误信息[标准错误]就被丢到太平洋去了
禁止标准输出和标准错误的输出
#cat $filename 2>/dev/null >/dev/null
因此,上面的代码根本不会输出任何信息。当只想测试命令的退出码而不想有任何输出时非常有用。
#cat $filename &>/dev/null
这样其实也可以, 由 Baris Cicek 指出
自动清空日志文件的内容
Deleting contents of a file, but preserving the file itself, with all attendant permissions (from Example 2-1 and Example 2-
3):
#cat /dev/null > /var/log/messages # : > /var/log/messages 有同样的效果, 但不会产生新的进程.(因为:是内建的) #cat /dev/null > /var/log/wtmp
特别适合处理这些由商业Web站点发送的讨厌的"cookies"
隐藏cookie而不再使用
#if [ -f ~/.netscape/cookies ] # 如果存在则删除. #then #rm -f ~/.netscape/cookies #fi #ln -s /dev/null ~/.netscape/cookies
现在所有的cookies都会丢入黑洞而不会保存在磁盘上了.
3.2 使用/dev/zero
像/dev/null一样, /dev/zero也是一个伪文件, 但它实际上产生连续不断的null的流(二进制的零流,而不是ASCII型的)。 写入它的输出会丢失不见, 而从/dev/zero读出一连串的null也比较困难, 虽然这也能通过od或一个十六进制编辑器来做到。 /dev/zero主要的用处是用来创建一个指定长度用于初始化的空文件,就像临时交换文件
用/dev/zero创建一个交换临时文件
The above is the detailed content of Detailed explanation of the dd command in Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Linux beginners should master basic operations such as file management, user management and network configuration. 1) File management: Use mkdir, touch, ls, rm, mv, and CP commands. 2) User management: Use useradd, passwd, userdel, and usermod commands. 3) Network configuration: Use ifconfig, echo, and ufw commands. These operations are the basis of Linux system management, and mastering them can effectively manage the system.

In Debian systems, the log files of the Tigervnc server are usually stored in the .vnc folder in the user's home directory. If you run Tigervnc as a specific user, the log file name is usually similar to xf:1.log, where xf:1 represents the username. To view these logs, you can use the following command: cat~/.vnc/xf:1.log Or, you can open the log file using a text editor: nano~/.vnc/xf:1.log Please note that accessing and viewing log files may require root permissions, depending on the security settings of the system.

DebianSniffer is a network sniffer tool used to capture and analyze network packet timestamps: displays the time for packet capture, usually in seconds. Source IP address (SourceIP): The network address of the device that sent the packet. Destination IP address (DestinationIP): The network address of the device receiving the data packet. SourcePort: The port number used by the device sending the packet. Destinatio

The readdir function in the Debian system is a system call used to read directory contents and is often used in C programming. This article will explain how to integrate readdir with other tools to enhance its functionality. Method 1: Combining C language program and pipeline First, write a C program to call the readdir function and output the result: #include#include#include#includeintmain(intargc,char*argv[]){DIR*dir;structdirent*entry;if(argc!=2){

This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

This article introduces several methods to check the OpenSSL configuration of the Debian system to help you quickly grasp the security status of the system. 1. Confirm the OpenSSL version First, verify whether OpenSSL has been installed and version information. Enter the following command in the terminal: If opensslversion is not installed, the system will prompt an error. 2. View the configuration file. The main configuration file of OpenSSL is usually located in /etc/ssl/openssl.cnf. You can use a text editor (such as nano) to view: sudonano/etc/ssl/openssl.cnf This file contains important configuration information such as key, certificate path, and encryption algorithm. 3. Utilize OPE

To improve the performance of PostgreSQL database in Debian systems, it is necessary to comprehensively consider hardware, configuration, indexing, query and other aspects. The following strategies can effectively optimize database performance: 1. Hardware resource optimization memory expansion: Adequate memory is crucial to cache data and indexes. High-speed storage: Using SSD SSD drives can significantly improve I/O performance. Multi-core processor: Make full use of multi-core processors to implement parallel query processing. 2. Database parameter tuning shared_buffers: According to the system memory size setting, it is recommended to set it to 25%-40% of system memory. work_mem: Controls the memory of sorting and hashing operations, usually set to 64MB to 256M

Install PostgreSQL database on Debian system, you can refer to the following two methods: Method 1: Use APT Package Manager to quickly install this method directly using Debian's APT Package Manager for installation. The steps are simple and quick: Update the package list: Run the following command to update the system package list: sudoaptupdate Install PostgreSQL: Use the following command to install PostgreSQL database: sudoaptinstallpostgresql Start and enable the service: After the installation is completed, start and enable the PostgreSQL service: sudosystemctl
