Generate dummy file in Linux
Answer:
To generate random files of fixed size (e.g. 1GB) in Linux:
dd if=/dev/zero of=test.bin bs=1000000000 count=1
You can adjust the file size by setting the bs parameter (byte size).
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Generate dummy file in Linux
Answer:
To generate random files of fixed size (e.g. 1GB) in Linux:
dd if=/dev/zero of=test.bin bs=1000000000 count=1
You can adjust the file size by setting the bs parameter (byte size).
What is the difference between encoding and charset?
Answer:
Charset defines the set of characters you can use, e.g. Unicode, there is only one universal Unicode Charset.
Encoding defines how the characters are stored, e.g. UTF-8 and UTF-16 are both valid encoding scheme for Unicode.
Disable reply to ping
Answer:
To stop other machine from pinging your machine, you the following command
# sysctl -w net.ipv4.icmp_echo_ignore_all=1
To turn it on again:
# sysctl -w net.ipv4.icmp_echo_ignore_all=0
How to check if a file is locked in Linux?
Answer:
Suppose a file test.txt is being locked by a program, e.g. using the flock system call, how can we know if this file is really being locked?
# lsof test.txt
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
perl 5654 john 3uW REG 8,1 1 983057 test.txt
The W means the file is currently held by an exclusive lock. You can find more information in the link below:
How to perform syntax check for Python program
Answer:
Assume you have a simple Python script hello.py, you want to perform syntax check. You can use the following method
# python -c 'import hello'
Traceback (most recent call last):
File "", line 1, in
File "hello.py", line 1
echo "Hello, World!"
If there is any syntax error, it will prompt out to the screen.