Display date-clock with simple bash command and while loop

Here is a simple example on how to display date/watch with simple bash command:

$ while true; do clear; date; sleep 1; done

Extract STDERR and redirect STDOUT to /dev/null with bash

I always keep forgetting this bash syntax redirection. This is because of my short memory and also because I do not use it often. In many cases we need to remove a STDERR from the command output and keep only STDOUT. On the other hand there are times that we want to see STDERR and [...]

Prevent bash redirection to overwrite existing files

Using a bash command “set” we can prevent bash redirection to overwrite existing files. If the file bash.txt exist this command will overwrite it:
ls > bash.txt
To prevent it we can run command:
set -C
to disable run command:
set +o noclobber
Example:
$ ls > bash.txt
$ set -C
$ ls > bash.txt
bash: bash.txt: cannot overwrite existing file
$ [...]

Bash – round floating point numbers with bash script

There is a simple trick how to round floating point numbers within bash script. I’m sure that there are other ways how to round floating point number in bash, if you know other way let me know :

#!/bin/bash
# obtain floating point number
floating_point_number=`echo “2153.6 * 0.98″ | bc`
echo $floating_point_number
# get rounded number
for rounded_number in $(printf %.0f [...]

Basic linux command guide / tutorial with command line examples for linux beginners

This link can be very useful for someone starting with Linux administration. This guide / tutorial covers all basic Linux commands and examples on command line using bash shell ( BASH ). It can also be use as a Linux command reference.
Linux Commands
enjoy your Linux commands training ..

Bash Script to create automatic FTP session and download file

This script automatically opens a FTP session and downloads file to local disk. Here is the scenario:
ftp: myftp.ext
username: myusername
password: mypassword
file to download: myfile.txt
1) Create bash script automatic_ftp_download.sh:
#!/bin/bash
# Script to create automatic FTP session and download file
ftp -n myftp.ext << end
us myusername mypassword
get myfile.txt
bye
end
2) make automatic_ftp_download.sh script executable:
chmod +x automatic_ftp_download.sh
3) run automatic_ftp_download.sh scrip:
./automatic_ftp_download.sh
4) find myfile.txt [...]

Disable ssh root access – Debian / Ubuntu

Open /etc/ssh/sshd_config if find entry similar to this:
PermitRootLogin yes
and change it to:
PermitRootLogin no
then restart your sshd service with:
/etc/init.d/ssh restart