YouTip LogoYouTip

Linux Comm Xxd

[![Image 1: Linux Command Manual](#) Linux Command Manual](#) xxd is a command-line tool in Linux used to display files or data in hexadecimal format, similar to a hex viewer. The xxd command can also convert hexadecimal data back into binary files. The xxd command is commonly used for debugging, file content analysis, and data conversion. ### Syntax Format xxd [inputfile ] * **inputfile**: Input file. If not specified, reads from standard input. * **outputfile**: Output file. If not specified, outputs to standard output. **Options Parameter Description:** * `-r`: Revert hexadecimal data back to binary (reverse operation). * `-p`: Output in continuous pure hexadecimal form (without offset address and ASCII). * `-c cols`: How many bytes to output per line, default is 16. * `-g bytes`: How many bytes to display per group, default is 2. * `-s offset`: Start reading from a certain offset position in the file (supports negative numbers to start from end of file). * `-l length`: Only display specified length of bytes. * `-u`: Convert output hexadecimal characters to uppercase. * `-i`: Output in C language array format. * `-b`: Convert output to binary format instead of hexadecimal. ### Common Usage Display file in hexadecimal format: xxd filename This command will display the filename file in hexadecimal format. Convert standard input to hexadecimal: echo "Hello World" | xxd This will convert the string "Hello World" to hexadecimal and output it. Specify bytes per line output: By default, xxd outputs 16 bytes of data per line. Can be modified using -c parameter: xxd -c 8 filename The above command will display 8 bytes of data per line. Convert back to original data: xxd can also convert hexadecimal format back to original binary data, using -r parameter: xxd -r hexfile This command reverts the hexadecimal data in hexfile back to a binary file. Display only hexadecimal (no ASCII): Use -p option to display only pure hexadecimal without corresponding ASCII characters: xxd -p filename Control output range: Use -s parameter to specify starting output from a certain offset in the file, use -l to specify output byte length: xxd -s 0x10 -l 0x20 filename This command starts from offset 0x10 and outputs 0x20 bytes of data. ### Examples **1. Display file content in hexadecimal** xxd filename.txt This command will output the hexadecimal representation of file filename.txt, displaying 16 bytes of data per line by default. Output example: 00000000: 4865 6c6c 6f0a Hello. **2. Specify bytes per line output** xxd -c 8 filename.txt Display 8 bytes per line. Output example: 00000000: 4865 6c6c 6f0a 0000 Hello... **3. Revert hexadecimal back to original file** xxd -r hexfile.txt original.bin This command will revert the hexadecimal data in hexfile.txt back to binary file original.bin. **4. Display from a certain offset position in file** xxd -s 0x10 filename.txt Start displaying hexadecimal content from offset 0x10. **5. Output in pure hexadecimal format (without offset address and ASCII)** xxd -p filename.txt Output pure hexadecimal data, all data arranged continuously. Output example: 48656c6c6f0a **6. Generate array format in C language** xxd -i filename.txt This command will output file content in C language array format. Output example: unsigned char filename_txt[] = { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x0a};unsigned int filename_txt_len = 6; **7. Convert output hexadecimal letters to uppercase** xxd -u filename.txt This command outputs hexadecimal letters in uppercase. Output example: 00000000: 4865 6C6C 6F0A Hello. **8. Display only a certain length of data** xxd -l 16 filename.txt This command only displays the first 16 bytes of data. **9. Output data in binary form** xxd -b filename.txt This command will display file content in binary bits instead of hexadecimal. Output example: 00000000: 01001000 01100101 01101100 01101100 01101111 00001010 Hello. [![Image 2: Linux Command Manual](#) Linux Command Manual](#)
← Docker Rename CommandCpp Data Structures β†’