Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Split on specific characters on Bash Script's for loop

Answer:

If you want to Bash script's for loop to split on non white-space characters, you can change the IFS, e.g.

#!/bin/bash
IFS='-'

list="a-b-c-d-e"

for c in $list; do
    echo $c
done

The above script will split on the character '-'

E.g.

# ./test.sh

a
b
c
d
e

Sending email using raw SMTP commands

Answer:

You can send email(s) by connecting to your SMTP server, and using raw SMTP commands.

E.g. assume your SMTP is localhost, listening port 25, enter the commands in bold

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 smtp.example.com ESMTP Postfix (Ubuntu)
helo localhost
250 smtp.example.com
mail from: john@example.com
250 2.1.0 Ok
rcpt to: mary@example.com
250 2.1.5 Ok
data
354 End data with .
This is a test mail
.

250 2.0.0 Ok: queued as BA2FD1DB96
quit
221 2.0.0 Bye
Connection closed by foreign host.

Convert all text in a file from upper-case to lower-case

Answer:

Just one command needed:

# tr '[:upper:]' '[:lower:]' < input.txt

Removed opened port in ufw

Answer:

If you have opened a port using the ufw command in Ubuntu, but now you want to delete it, you can..

# sudo ufw delete allow 8080/tcp

And then do a reload

# # sudo ufw reload

That's all.

Combine multiple images into a single image with ImageMagick

Answer:

With the powerful ImageMagick program, we can easily handle common graphics tasks using command only.

For example, to combine multiple images into a single image, we need just one command:

# convert file1.jpg file2.jpg file3.jpg +append -quality 90 'output.jpg'

The above command (file1.jpg file2.jpg file3.jpg) into the file output.jpg with quality set to 90.