Only show filenames in grep command
Answer:
Sometimes you want the grep command only return the filenames that matched a pattern, you can try the following:
# grep -r -l "foo" .
The key is the -l option.
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Only show filenames in grep command
Answer:
Sometimes you want the grep command only return the filenames that matched a pattern, you can try the following:
# grep -r -l "foo" .
The key is the -l option.
Emulate telnet using nc
Answer:
Telnet is a very useful tool for connecting to remote server, such as SMTP. However, you can replace the command telnet by nc, with the exact functionality.
Example: Connect to the local SMTP server.
# nc localhost 25
What is the SMTP submission port 587?
Answer:
A lot of ISPs will block the port 25 for preventing users from sending spam emails. To send email if you use such ISPs, you need to use port 587.
Port 587 is the official port for sending email on mail submission agents (MSAs), as defined in RFC 2476
Block website access in Linux
Answer:
The simple way to block access to web site is to change the hosts file.
1. Open the hosts file
# sudo vi /etc/hosts
2. Change the content, such as...
0.0.0.0 microsoft.com
0.0.0.0 oracle.com
3. Save the file.
Pass hash as reference in Perl
Answer:
In the previous post, we talked about how to Pass hash as list in Perl, now we discuss another way: To pass a hash as a reference in Perl function.
sub foo {
my ($h) = @_;
print $h->{"1"};
}
foo ( {"1" => "One", "2" => "Two"} );
One will be printed out.