How to Check Linux OS version Command Line

While having a great Latin America coffee from Ecuador I came to realize that I did not remember how to check Linux OS version using the command line.

Below are some examples for finding your Linux OS version. Open your command line:

/etc/os-release file

Type the following command using cat in Debian based distros:

cat /etc/os-release

I got the below result in my terminal:

Check Linux OS version Command Debian

/proc/version file

Using cat /proc/version worked for me for both Debian and Red Hat distros. Simply run:

cat /proc/version

And you should get the below result:

Linux version 4.4.0-198-generic (buildd@lgw01-amd64-051) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) )

Other commands to find Linux OS version

Try running in your terminal the below commands and experiment to see what output you get. If your Linux distro does not support it you should get a “command not found” error.

cat /etc/issue
hostnamectl
uname -a
lsb_release -a (mainly for Debian distros)

Basic Linux Commands for Newbies

The other day one of my friends who is a Windows user asked me to basic Linux commands because he wanted to improve his IT skills. I helped him out and also decided to put together a brief list of basic Linux commands for newbies while having fantastic Latin America coffee at home.

Basic Linux Files and Navigation Commands

CommandDescription
lsList of files/directories in current directory
ls -lFormatted listing
ls -laFormatted listing including hidden files
cd <dir>Change directory to <dir>(<dir> is directory name)
cdGo to your home directory
pwdShow current path
mkdirMake a directory e.g. mkdir holadir
rmRemove a file e.g. rm myfile
rm -rDelete a directory e.g. rm -r mydirectory
cpCopy files e.g. cp myfile yourfile
mvRename files e.g. mv myfile yourfile
Files and Navigation Linux Commands

Networking Basic Linux

CommandDescription
pingPing a host
whoisGet whois for a domain
digGet DNS for a domain
wgetDownload a file
wget -r <url>Recursively download files from url
curl <url>Output webpages from url
ssh user@hostConnect to host as user
ssh -p <port> user@hostConnect to host as user using a port
ssh -D user@hostConnect and use bind port
Basic Networking Linux Commands
Continue reading “Basic Linux Commands for Newbies”

List Installed Packages in Red Hat, CentOS and Fedora

I usually work on Debian based Linux distros, but the other day while sorting some NYC street photos I took a friend contacted me asking me how to list installed packages in Red Hat, CentOS and Fedora.

  1. Using RPM Package Manager
  2. Using YUM Package Manager
  3. Using YUM-Utils

Using RPM Package Manager

The RPM package manager is an open source, low level package manager which runs on Red Hat based Linux distros. You can list installed Packages in Red Hat very easy with rpm.

The following command will print a list of all installed packages on your Linux box, the flag -q means query and the flag -a means to list all installed packages:

rpm -qa

Using YUM Package Manager

YUM stands for Yellowdog Updater Modified is an interactive, front-end rpm based package manager.

Using the command below will list all installed packages on your Linux box. One cool thing about this Linux package manager is that it lists the repository from which a package was installed:

yum list installed

Using YUM-Utils

Yum-utils is an assortment of tools and programs for managing yum repositories in your Linux box. Using this tool you can install debug packages, source packages and you can view extended information from repositories. You might need to install it using yum:

yum update && yum install yum-utils

Once you have Yum-Utils installed run the following command in your Linux terminal to list all installed packages:

repoquery -a --installed

Run Docker without sudo Linux

To run Docker without sudo in Linux is quite simple. Using your terminal in Linux and a couple simple commands shown below. You don’t need to be an expert Linux guru software developer to go thru these steps.

If you don’t want to preface the docker command with sudo, create a Linux group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

Create the docker group:

sudo groupadd docker

Add your user to the docker group:

sudo usermod -aG docker $USER

Log out and log back to activate the group membership in Linux or you can run:

newgrp docker

Now, verify you can run docker without sudo:

docker ps
docker run hello-world

That is all! Super simple, anybody can do it. Now go brew better coffee at home. Contact me using the comments below or shoot me an email using my contact page.

What are SEO stop words summary

Stop words SEO are words such as ‘at’, ‘any’, ‘before’, ‘which’. While having putting together some New York City pictures for my NYC Moments website I took the other day I found myself learning more about SEO. I put together a little list of stop words in SEO. Using them in your permalink is therefore a waste of valuable space.

List of SEO stop words

a
about
above
after
again
against
all
am
an
and
any
are
as
at
be
because
been
before
being
below
between
both
but
by
could
did
do
does
doing
down
during
each
few
for
from
further
had
has
have
having
he
he'd
he'll
he's
her
here
here's
hers
herself
him
himself
his
how
how's
i
i'd
i'll
i'm
i've
if
in
into
is
it
it's
its
itself
let's
me
more
most
my
myself
nor
of
on
once
only
or
other
ought
our
ours
ourselves
out
over
own
same
she
she'd
she'll
she's
should
so
some
such
than
that
that's
the
their
theirs
them
themselves
then
there
there's
these
they
they'd
they'll
they're
they've
this
those
through
to
too
under
until
up
very
was
we
we'd
we'll
we're
we've
were
what
what's
when
when's
where
where's
which
while
who
who's
whom
why
why's
with
would
you
you'd
you'll
you're
you've
your
yours
yourself
yourselves

Removing stop words from your permalink will give you more space for keywords.

If you like this small post and feeling generous get one of my T-Shirts and coffee mugs designs below. Thanks!

Docker error: Cannot start service …: network 0927c not found

I have never seen this Docker error: Cannot start service while using docker-compose in the short time I have been using Docker.

While having amazing Latin America coffee from Honduras I decided to jump back into my personal Flask project. This project is mainly to keep track of your blood pressure by taking daily readings and keeping a record. This record can then be shared with your doctor by email, PDF printout or by giving your doctor access to your profile.

Using Docker with docker-compose I got this “Docker error: Cannot start service…..”

Docker error: Cannot start service …: network 5f9226bdb324e31fa4e4bff6777b18b329dc7e6c55e7a2dca5c72601ff10927c not found

Doing a little research I found out that I did not properly stopped my running containers. I lost track of this project and then did not remember what was the last thing I did. This is not good! Always keep track of your projects specially with learning something new. I use Trello to keep a bit more organized and know what was the last thing I did.

To fix the above error I simply ran this two commands in my working project directory:

docker-compose down
docker-compose up -d <or without the -d>

It was all fixed and I got to go for a walk in NYC! Happy learning!

Using rsync over SSH to backup or transfer files

In this tutorial we will cover the steps needed to copy files with rsync over SSH in Debian or Ubuntu platform. While having amazing Catuai coffee from Honduras I learned the following.

Rsync is a great tool that allows you to transfer and synchronize data between servers. The command can be used over SSH which encrypts the connection. It also provides large amount of options which can be used such as archive mode, backup mode, data compression during the transfer etc.

If rsync is not included in your distro you can easily install it using (Debian/Ubuntu way):

sudo apt install rsync

In order to make sure that you will be able to transfer files from/to the remote server using rsync over SSH you can first try to establish an SSH connection:

ssh user1@<yourServerIP or name>

The recommended way to connect to your server is by using keys. To generate keys run in the terminal:

ssh-keygen -f ~/.ssh/id_rsa

and then:

cat ~/.ssh/id_rsa.pub

Copy this key to your clipboard and login to your destination server. Place this SSH key into your ~/.ssh/authorized_keys file. If your SSH folder does not exist, create it manually:

mkdir ~/.ssh 
chmod 0700 ~/.ssh 
touch ~/.ssh/authorized_keys 
chmod 0644 ~/.ssh/authorized_keys

Rsync files over

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt <yourServerIP or name>:/root/

If you are using a different user, for example “username” then you would have to append it in front of destination server. Make sure to have your public key in that user’s ~/.ssh/authorized_keys file:

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt username@<yourServerIP or name>:/

The newer versions of rsync are configured to use SSH as default remote shell so you can omit the -e ssh option.

For simpler rsync file transfers you can do any of the following:

For example, to transfer a single file /opt/myfile.zip from the local system to the /var/www/ directory on the remote Linux system with IP 163.90.162.123 you would run:

rsync -a /opt/myfile.zip <yourUser>@163.90.162.123:/var/www/

Replace <yourUser> with your actual username for your remote Linux server. The -a option stands for archive mode which will syncs directories recursively, transfer special and block devices, preserve symbolic links, modification times, group, ownership, and permissions. Very cool!

To transfer files from the remote Linux server to your local machine just do the opposite:

rsync -a <yourUser>@163.90.162.123:/var/www/ /opt/myfile.zip 

Contact me if you have any questions. Thanks!

Common HTTP response status codes to Understand

Hola! While having a great cup of Caturra coffee from Panama I decided to put together the most common HTTP response status codes in a simple list.

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:

  1. Informational responses (100199),
  2. Successful responses (200299),
  3. Redirects (300399),
  4. Client errors (400499),
  5. and Server errors (500599).

I’m not going to list all examples, but I will list the most common HTTP response status below:

Successful HTTP responses

200 OK

The request has succeeded. The meaning of the success depends on the HTTP method:

  • GET: The resource has been fetched and is transmitted in the message body.
  • HEAD: The entity headers are in the message body.
  • PUT or POST: The resource describing the result of the action is transmitted in the message body.
  • TRACE: The message body contains the request message as received by the server

Redirection message

301 Moved Permanently

The URL of the requested resource has been changed permanently. The new URL is given in the response.

307 Temporary Redirect

The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request. This has the same semantics as the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: If a POST was used in the first request, a POST must be used in the second request.

308 Permanent Redirect

This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: If a POST was used in the first request, a POST must be used in the second request.

Client Error HTTP Responses

400 Bad Request

The server could not understand the request due to invalid syntax.

401 Unauthorized

Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”. That is, the client must authenticate itself to get the requested response.

403 Forbidden

The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401, the client’s identity is known to the server.

404 Not Found

The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurrence on the web.

408 Request Timeout

This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message.

Server error HTTP responses

500 Internal Server Error

The server has encountered a situation it doesn’t know how to handle.

502 Bad Gateway

This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.

503 Service Unavailable

The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached.

505 HTTP Version not supported

The HTTP version used in the request is not supported by the server.

Could not set the file size of ./ibtmp1. Probably out of disk space

While having my daily specialty coffee from Latin America I got this error for one of my docker containers running MySQL. ERROR: ‘Could not set the file size of ./ibtmp1’. Suddenly the container failed to start and I could not understand why!

I reviewed the logs for my container:

docker logs <my_container_name>
2020-07-31T15:45:10.209380Z 0 [ERROR] InnoDB: Could not set the file size of './ibtmp1'. Probably out of disk space
2020-07-31T15:45:10.209437Z 0 [ERROR] InnoDB: Unable to create the shared innodb_temporary
2020-07-31T15:45:10.209486Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2020-07-31T15:45:10.725388Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2020-07-31T15:45:10.725530Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-07-31T15:45:10.725673Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-07-31T15:45:10.725770Z 0 [ERROR] Failed to initialize builtin plugins.
2020-07-31T15:45:10.725816Z 0 [ERROR] Aborting

2020-07-31T15:45:10.725871Z 0 [Note] Binlog end
2020-07-31T15:45:10.725996Z 0 [Note] Shutting down plugin 'CSV'
2020-07-31T15:45:10.727174Z 0 [Note] mysqld: Shutdown complete

Something strange ‘Could not set the file size of ‘./ibtmp1′. Probably out of disk space’

My computer disk space was fine with more than 20GB free space. But, then after a walk around my hood in NYC Moments I discovered this error was referring to my virtual space hard disk created by the docker engine which is used in the background. This was not my local computer’s hard disk space.

This solution worked for me:

docker-compose down

docker system prune

docker-compose up

I ran those three commands. This will prune all containers that not in used and might also reset your current containers. In my case I had to re-create MySQL database and tables. I need to make this better. Hope this solution for ‘Could not set the file size of ./ibtmp1’ error works for you. Remember to check out some cool coffee mugs and T-Shirt designs on my sister website

How to mount EXT Linux partition on MacOS

The other day while having a great cup of Latin America coffee from El Salvador I found a way to mount my EXT Linux partition I have on an external backup WD drive. I didn’t know that MacOS could not mount it natively even when both Linux and MacOS come from the same mother UNIX.

Homebrew came to the rescue! First, make sure you have it installed. Then run these couple of commands in order to install the package ext4fuse. Open your terminal and run these two commands:

brew cask install osxfuse
brew install ext4fuse

Plug in the hard disk drive or storage device whose partition you want to mount and in the terminal run:

diskutil list
diskutil list command results

This will give you a list of storage devices attached to your computer. Lets say your device is disk2S1. Then you run:

sudo ext4fuse /dev/disk2s1 ~/tmp/MY_EXT_PARTITION -o allow_other

MY_EXT_PARTITION is only a sample name. You can name it anything you want. You need sudo privileges to run this command.

Now, you can use Finder to navigate to your /tmp directory and find the mounted partition. Or in the terminal do:

open ~/tmp/

Remember, this methods will give you READ ONLY rights to the mounted ext partitions. You cannot make changes to it. Can you view the files and copy them to your MacOS and then make any changes. Homebrew is very handy and help me mount my EXT Linux partition I have laying around many external hard drives.

Hope this little tutorial was helpful. Contact me if you have any questions or need help.