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
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
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 sort a file by n-column
Answer:
Suppose you have a CSV file:
1,c
2,d
3,a
How do you sort by the 2nd column?
Here is the command you need:
# sort -k2 input.txt -t ','
where -t ',' mean the comma separator, and -k2 mean the 2nd column.
How to escape "-" character at the beginning of filename?
Answer:
Assume you have file named -test.txt, if you want to print it out by the cat command:
# cat -test.txt
cat: invalid option -- '.'
Try `cat --help' for more information.
You will experienced the above error, similar errors will happen with commands such as mv, cp etc.
To correctly handle these kind of files that with file name start with the character -, you need to escape with --
e.g.
#cat -- -test.txt
test
Add Margins to a text file
Answer:
To add 4 spaces as the left margin to a text file
# pr -t -o 4 text.txt
Compare difference of two files side by side
Answer:
To compare the difference of two text files side by side, use the diff command with -y option
E.g.
# diff -y 1.txt 2.txt
a a
b b
c c
> d
As you can see, the only difference between two files is the character d.