Strings are commonly encoded as hexadecimal (hex) strings for various purposes. Hence, it is also common to convert hex strings to its original strings such as an ASCII string. Hex to ASCII string conversion can be done programmatically in many languages. In command line, we can use xxd to convert hex to ASCII string. This
Read more
Tag: STDOUT
Make Grub2 Boot Older Kernel Version in Ubuntu 20.04
Posted onIn a Linux system, we may have multiple kernels installed. Usually, it is the latest kernel configured to be the default one the system boot loader will use during automatic boot if there is no manual kernel choosing. In many cases, such as there is no driver ready yet for some devices in newer kernels,
Read more
How to Install Hyperledger Fabric 2.0 in Ubuntu 18.04
Posted onHyperledger Fabric is a consortium blockchain system. It’s performance is relatively good and its modular architecture enables it to be usable in many scenarios. Hyperledger Fabric itself has rich documents and samples of test networks. For beginners, deploying a new network for trying and testing still consumes quite some time. In this post, we will
Read more
Grep 2 Lines using `grep` Command in Linux
Posted ongrep is excellent to match patterns from STDOUT/text files in command line or scripts. It’s handy. Sometimes, our problem is more complex than finding a keyword from a file. On a first thought, it may sound impossible using grep for such complex problems. But grep can be quite powerful than we thought. Today, let’s check
Read more
How to enlarge root partition and filesystem size of cloud Linux VM at runtime without rebooting Linux
Posted onIt is common that the root disk space is not enough when running a Virtual Machine in the cloud such as Amazon Web Service (AWS). The cloud storage usually provides tools or facilities to enlarge a virtual disk size. However, to make the Linux recognize and and use the enlarged disks without rebooting the OS,
Read more
How to cat a single file’s content from a tar without unpacking it on Linux?
Posted onHow to cat a single file’s content from a tar without unpacking it on Linux? For example, I know there is a file README.txt in a tar tools.tar.gz . How to cat the content of README.txt out? You can do this by using a combination of tar‘s options and arguments. -O, –to-stdout Extract files to
Read more
How to judge whether its STDERR is redirected to a file in a Bash script on Linux?
Posted onWithin a Bash script, how to judge whether its STDERR is redirected to a file in Bash on Linux? For example, ./script.sh /tmp/log 2>&1 Can script.sh detect that its STDERR is redirected? Knowing the destination file is better. To test whether a script’s STDERR (or STDOUT) is redirected to a file, check by [[ -f
Read more
How to flush STDOUT buffer in Python?
Posted onHow to flush the STDOUT buffer in Python so that the content wrote to STDOUT is shown immediately? Call the flush library function on sys.stdout which is the STDOUT: import sys sys.stdout.flush() From python doc: flush() Flush the write buffers of the stream if applicable. This does nothing for read-only and non-blocking streams. If you
Read more
How to print a line to STDERR and STDOUT in C++?
Posted onIn C++, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In C++, you may print the string and then ‘n’ or std::endl to STDOUT by operating on the std::cout stream: std::cout << your_string << std::endl;
Read more
How to print a line to STDERR and STDOUT in OCaml?
Posted onIn OCaml, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In OCaml, you may print a string with the end line character to STDOUT using the function in the Pervasives module: val print_endline : string
Read more
How to print a line to STDERR and STDOUT in Perl?
Posted onIn Perl, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In Perl, to nicely print a new line to STDOUT, you can use the “say” feature which “Just like print, but implicitly appends a newline”:
Read more
How to print a line to STDERR and STDOUT in Java?
Posted onIn Java, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In Java, you can print string in a new line by ‘System.out.println()’ to STDOUT: System.out.println(“my msg here”); In Java, print a string str to STDERR
Read more
How to print a line to STDERR and STDOUT in C?
Posted onIn C, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In C, to print to STDOUT, you may do this: printf(“%sn”, your_str); For example, $ cat t.c #include <stdio.h> void main() { printf(“%sn”, “hello world!”);
Read more
How to print a line to STDERR and STDOUT in PHP?
Posted onIn PHP, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In PHP, you may print a line to STDOUT using echo by appending the PHP_EOL to the string: echo $your_msg . PHP_EOL; For example, $
Read more
How to print a line to STDERR and STDOUT in Bash?
Posted onIn Bash, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In Bash, you can simply use the echo command: echo “your message here” or echo your message here Examples: $ echo the message here the
Read more
Printing a Line to STDERR and STDOUT in Python
Posted onIn Python, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In Python, to print a string str with a new line to STDOUT: print str In Python to print a line to STDERR: import sys
Read more
How to print a line to STDERR and STDOUT in Go?
Posted onIn Go, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely? And similarly, how to print the line to STDERR? In Go, you can use the ‘Println()’ func from the ‘fmt’ package to print a line to STDOUT: import(“fmt”) fmt.Println(“my msg here”) In Go, os.Stderr
Read more
How to Debug a Bash script?
Posted onHow to debug a Bash script if it has some bugs? Common techniques like printing varibles out for checking apply for bash too. For bash, I also use 2 bash-specific techniques. Use errexit option Run the script with -e option like bash -e your-script.sh or add set -o errexit to the beginning of the script.
Read more
Getting Epoch Timestamp in C
Posted onIn C, how to get the epoch timestamp, the number of seconds passed since the epoch? In C, from man 7 time: UNIX systems represent time in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). A program can determine the calendar time using gettimeofday(2), which returns time (in seconds and microseconds) that have elapsed since
Read more
How to get the epoch timestamp in Go lang?
Posted onIn Go lang, how to get the epoch timestamp, the number of seconds passed since the epoch? In Go, you can use the time.Now() func to get current time and its Unix() func to convert it into an epoch timestamp: import(“time”) func getEpochTime() int64 { return time.Now().Unix() } If you would convert a time string
Read more