Author Archives: admin

How to Install Plex Media Server on Ubuntu 18.04

In the following write-up, we will try to get ourselves acknowledged how to get the Plex media server installed on Ubuntu 18.4 and create a Media library.

What is Plex?

Plex is considered the server used for streaming different kinds of media like video, music, and photo slideshow. The part about Plex that makes it the most unique is that you can stream through it from anywhere and everywhere you want to.

Point to remember

One thing that should be noted is that to be able to install different servers on Ubuntu. You should be logged in as a user.

Let’s get started with the installing procedure of the Plex Media Server.

One can easily manage the Plex media server on Ubuntu by using the official repository by Plex. This procedure does not need you to be technically efficient and help you limit 20 minutes by installing and configuring the Plex media server.

The steps mentioned below will help you with the process of installing Plex media server in Ubuntu,

  • the first step will be to import the repository’s GPG key and use the below-mentioned command,
$ curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
  • Secondly, you will have to add your system software repository list with Plex APT repository:
$ Echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
  • when you are done with enabling the blacks repository, you are now ready to install the Plex media server in the latest version,
$ sudo apt install apt-transport-HTTPS

$ sudo apt update

$ sudo apt install plexmediaserver
  • Verification of the proper functioning of flex service can be done by the command below,
$ sudo systemctl status plexmediaserver

You will receive a output mirroring exactly the below mentioned,

  • plexmediaserver.service – Plex Media Server for Linux

Loaded: loaded (/lib/systemd/system/plexmediaserver.service; enabled; vendor preset: enabled)

Active: active (running) since Mon 2018-06-25 10:42:28 PDT; 35min ago

Process: 2544 ExecStartPre=/bin/sh -c /usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" (code=exited, status=0/SUCCESS)

Main PID: 2556 (sh)

         Tasks: 56 (limit: 2321)

CGroup: /system.slice/plexmediaserver.service

Plex Media Server Configuration

Follow the steps below to configure the Plex media server,

  • the first step in configuring the Plex media server is creating directories, which will further help store media files.
sudo mkdir -p /opt/plexmedia/{movies,series}

The location of the media files does not matter but remember to provide the proper ownership.

sudo chown -R plex: /opt/plexmedia
  • Finally, we reached the server configuration step where, on typing the browser search bar with, http://YOUR_SERVER_IP:32400/web, aired, and aired in a screen popup with a Plex media sign up.

Methods describing how to sign in on Plex Media Server

Keep the steps below in mind to sign-in on the Plex media server,

The first step to bring in use the Plex media server is to get yourself an account created.

Account creation is no big deal. You will have to fill in the information on Google, Facebook, or email about yourself and if you are a fan of premium, then get yourself a Plex Pass.

Plan.

When undergone, the procedure of signing up an informative page will pop-up regarding the working of Plex.

From here, to move ahead, you will have to press the button flashing “Got it.”

  • Secondly, you will be given an option to decide the media’s access to your server when outside the home (server’s home box). After putting a check on it, you will go for the “Next” button. In this procedure, you will also find yourself naming your Plex server.

The check procedure follows with you to the creation of a Media library. You will have to press down on, “Add Library” button, and voila!

You can have your selected movies and library type mentioned. This step is again followed by pressing on the “Next” button.

  • Another step involved making a media folder path directed, which will lead you to the media files easily. We had the path directed as,

/opt/plex media/granule/movies.

  • To increase the number of libraries, you have to click the “Add” button simultaneously and then the “Add Library” one.
  • Following a click on the “Next” button, and after a click on the button displayed as “Done,” and you will reach the Plex Web dashboard.
  • Once you are done setting up everything, you can now feel free to explore Plex media and the different options.

Conclusion

This write-up provided above helped you understand the Plex media server’s installing procedure when it comes to Ubuntu 18.4 machine. Also, you got yourself some tricks and tips on serving your own Media Library.

How to Install Nvidia Drivers on Ubuntu 20.04

In this article, you will learn how to install the NVIDIA drivers on Ubuntu 20.04.

If you have an Ubuntu machine with an NVIDIA GPU, you can take between the open-source driver Nouveau and NVIDIA’s exclusive drivers. By default, Ubuntu applies Nouveau drivers frequently much slower than the exclusive drivers and lacks support for the most advanced hardware and software technology.

Installing NVIDIA drivers on Ubuntu is a simple task that can be completed in less than a minute. Ubuntu involves a tool that can recognize the graphics card model and install the relevant NVIDIA drivers. Alternatively, you can download and install the drivers from the NVIDIA site also.

Installing the NVIDIA Drivers Using a GUI

This is the most relaxed and the suggested way to install NVIDIA drivers on Ubuntu Desktop systems.

  1. In the Activities screen, seek “driver” and click on the “Additional Drivers” icon.
  2. The “Software & Updates” window will start to see all available drivers for your graphic card.
  3. Depending on the installed card, you will be offered a list of one or more NVIDIA drivers.
  4. Choose the NVIDIA diver you need to install and then click on the “Apply Changes” button.
  5. The installation process may take a few minutes, so be patient.
  6. Once the drivers and installed, then you will need to reboot your machine.

The new NVIDIA driver will be activated after the system is boot up. If you need to view or change the driver set, begin the Nvidia-settings utility:

$ sudo Nvidia-settings

Later, if you need to update or modify the driver, repeat the same steps.

Installing the NVIDIA Drivers Using the Command-Line

If you favor the command-line interface, you can use the ubuntu-drivers tool.

Open your terminal (Ctrl+Alt+T), and run the subsequent command to get data about your graphic card and open drivers:

$ ubuntu-drivers devices

The output following shows that this system has “GeForce GTX 1650,” and the suggested driver is “Nvidia-driver-440”. You may see various outcomes depending on your system.

Output:

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F95sv00001028sd0000097Dbc03sc02i00
vendor   : NVIDIA Corporation
model    : TU117M [GeForce GTX 1650 Ti Mobile]
driver   : nvidia-driver-440 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

Usually, it is best to install the suggested driver. To do so, use the apt package manager:

$ sudo apt install Nvidia-driver-440

Once the installation is finished, reboot your system:

$ sudo reboot

When the system is back, you can view the status of the graphic card using the Nvidia-smi monitoring tool:

 $ Nvidia-smi

The command will represent the version of the used driver and other data about the NVIDIA card:

Output:

Wed Nov 11 22:45:21 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 165...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   41C    P3    14W /  N/A |      4MiB /  3914MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2323      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

Installing the Latest NVIDIA Drivers

Most users should stick with the firm NVIDIA drivers that are available in the default Ubuntu repositories. If you want to live on the edge, you can install the latest drivers from the NVIDIA site or the “Graphics Drivers” PPA.

We will use the PPA method as it is more comfortable to install and update the drivers.

Add the PPA repository using the following command:

$ sudo add-apt-repository ppa:micahflee/ppa

Use the ubuntu-drivers tool to view the available drivers:

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F95sv00001028sd0000097Dbc03sc02i00
vendor   : NVIDIA Corporation
model    : TU117M [GeForce GTX 1650 Ti Mobile]
driver   : nvidia-driver-440-server - distro non-free
driver   : nvidia-driver-450-server - third-party non-free
driver   : nvidia-driver-455 - third-party non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

Install the desired driver:

$ sudo apt install nvidia-driver-455

Reboot the system to activate the new driver.

Conclusion

In this article, you have learned how to install NVIDIA Driver on Ubuntu 20.04. If you want more information about NVIDIA drivers, then you can contact us now.

How to Install Eclipse IDE on Ubuntu 18.04

Eclipse is the most commonly used Java built-in programming environment (IDE). It is easy to use via plugins. Its versions are available for development in other programming languages platforms like C++, JavaScript, and PHP.

The Eclipse installation kit (version 3.8.1) included in the Ubuntu repository is out of date. The best way to update the new Eclipse IDE on Ubuntu 18.04 is to use the snappy packaging system.

Install the Eclipse

The new stable edition of Eclipse is Eclipse 2019-03, is available now:

To install Eclipse on your Ubuntu system, follow the following steps:

Java Install

Since Eclipse is an IDE based on Java, you will need the Java Runtime Environment (JRE) to be installed to run it.

Run the commands below to install the Java opensource update.

sudo apt update
Sudo apt configuration default-JRE

Java JRE has to be mounted.

Download and install the Eclipse Snap kit to your machine by typing:

sudo snap install --classic Eclipse

When you install Eclipse successfully, you should see the following output:

eclipse 2019-03 from Snapcrafters installed

Eclipse Manually Install

The steps below should be helpful for those who want to install Eclipse manually. You’ll be using the regular Eclipse installer to install the app.

Firstly, to download the installer, go to the page below.

https://www.eclipse.org/downloads/downloads/downloads/

Or you can use the download and extract commands below.

Run the following commands to remove the downloaded file from your Home Directory Downloads folder.

tar xfz ~/Downloads/eclipse-inst-linux64.tar.gz

~/Downloads/eclipse-installer/eclipse-inst

~/Downloads/eclipse-installer/eclipse-install installer

You will start the installation wizard with the second instruction.

Pick the tools and language that you want to create.

Eclipse Begins

You can now open Eclipse on your Ubuntu device by clicking on the Eclipse icon (Activities -> Eclipse):

A window like this will appear when you start Eclipse for the first time, asking you to pick a Workspace directory:

The default directory ought to be all right. To proceed, press Launch.

Conclusion:

On your Ubuntu 18.04 computer, now you have learned how to install Eclipse. You can start working on your project in Java now.

How to Increment and Decrement Variable in Bash (Counter)

One of the most popular arithmetic operations when addressing Bash scripts is incrementing and decrementing variables. This is most regularly used in loops as a counter, but it can happen elsewhere in the script.

Incrementing and Decrementing centers on adding or subtracting a value (usually 1), respectively, from the value of a numeric variable. The arithmetic augmentation can be performed using the double parentheses ((…)) and $((…)) or with the built-in let command.

In bash, there are various ways to increment/decrement a variable. In this article, some are explained.

Using + and – Operators

The most easy way to increment/decrement a variable is by using the + and – operators.

i=$((i+1))

((i=i+1))

let "i=i+1"
i=$((i-1))

((i=i-1))

let "i=i-1"

This method enables you to increment/decrement the variable by any value you want.

Here is an example of incrementing a variable within an until loop:

i=0

until [ $i -gt 3 ]

do

  echo i: $i

  ((i=i+1))

done

Output:

i: 0

i: 1

i: 2

i: 3

The += and -= Operators

In addition to the basic operators explained above, bash also provides the assignment operators += and -=. These operators are used to increment/decrement the left operand’s value with the value specified after the operator.

((i+=1))

let "i+=1"
((i-=1))

let "i-=1"

Copy

In the example below, we will show how to decrement the I variable’s value by 5.

i=20

while [ $i -ge 5 ]

do

  echo Number: $i

  let "i-=5" 

done

Output:

Number: 20

Number: 15

Number: 10

Number: 5

Using the ++ and — Operators

The ++ and — operators increment and decrement, respectively, its operand by 1 and return the value.

((i++))

((++i))

let "i++"

let "++i"
((i--))

((--i))

let "i--"

let "--i"

The operators can be used before or after the operand. They are also known as:

  • prefix increment: ++i
  • prefix decrement: –i
  • postfix increment: i++
  • postfix decrement: i–

The prefix operators first increment/decrement the operators by one and then return the new value to the operator. On the other hand, the postfix operators return the operators` value before incrementing/decremented the operator’s value.

If you only want to increment/decrement the variable, then there is no difference if you use the prefix or postfix operator. It only makes a difference if the operators’ result is accepted in some other operation or assigned to another variable.

The example below will show how the ++ operator works when is used before and after its operant:

x=5

y=$((x++))

echo x: $x

echo y: $y

Output

x: 6

y: 5
x=5

y=$((++x))

echo x: $x

echo y: $y
Copy

x: 6

y: 6

The example below shows us how to use the postfix incrementor in a bash script:

#!/bin/bash

i=0

while true; do

  if [[ "$i" -gt 3 ]]; then

    exit 1

  fi

  echo i: $i

  ((i++))

done

The downside of using these operators is that the variable can only be incremented or decremented by one only.

Conclusion                      

In bash, incrementing and decrementing variables can be performed in many different ways. So whatever method you use, the result is the same. If you have any query related to this, please write us.

How to Find the Length of a List in Python

Lists are one of the most commonly used data types in Python and store collections of the same kind.

In this article, we will see how to find the length of a list.

len() Function

If you want to find the length of the given object, then in Python, there is a built-in function len(), giving you the length of the given object (object means a list, tuple, string, dictionary, etc.)

The syntax of the len() function is as follows:

len(list)

The function allows only one argument. The declared value is an integer that is the number of elements in the list.

Here is an example:

capitals = ['Tokyo', 'Sofia', 'India', 'Budapest', 'America']

list_len = len(capitals)

print("The list has {0} elements.".format(list_len))
Output:

The list has 5 elements.

Using Loop

The another way to find the length of a list is to use them for a loop. This works by fixing up a counter and looping through all the elements of the list. On each repetition, the current value of the counter variable is incremented by one.

With the help of the following code, the snippet will get an idea of finding the length of an object using the loop.

capitals = ['Japan', 'America', 'India', 'Budapest', 'Italy']

counter = 0

for capital in capitals:

  counter = counter + 1

print("The list has {0} elements.".format(counter))
output:

The list has 5 elements.

As we cannot trust this method, it favors using the len() function in Python.

Conclusion

In this article, we have seen finding the length of a list in Python list and using the len() function only. If you have any queries related to this len(), then feel free to connect us.

How to Delete Lines in Vim / Vi

Vim comes out as an outstanding tool that helps to configure files and editing text mostly under Linux. One quirk of Vim that many cannot acknowledge is its capability to delete or erase complete lines in a text or file. Nothing complex about Vim but learning it is definitely useful.

Like every other work, deleting a line in Vim too has various methods. Vim, the widely known editor for text in Linux, can undo one or many patterns in a single command.

This tutorial will help you get knowledge on deleting lines by range or pattern by various options provided by Vim.

Various ways to delete a line in Vim

How to delete a single line?

  • Press on the Esc key and rapidly move along different files.
  • Move the cursor towards your line of choice for deleting.
  • If you want to delete a line, you need to press one of the following commands,
DD
D

Deleting a single word

  • Pressing Esc helps you enter the mode of command.
  • Next step involves the pointer being placed at the start of the very word.
  • Press down on the key that instant.

Steps for deleting multiple rows?

  • Start by pressing the Esc key.
  • Next step involves moving pointer to the line that’s needed to get deleted.
  • One use of one of the below mentioned commands the line will get deleted
[#]d d {# stands for no. of lines}
D-d-d

Method for deleting series’ of lines

  • Start by using the Esc key to enter a normal mode in Vim.
  • The following command will be brought to use with the beginning of the line’s range to the end of the line’s spectrum.

Example for reference is, deleting lines 3, 4, 5, and 6 by using the command: 2,6d.

Methodology for – delete all rows.

  • Firstly you press the Esc key.
  • Finally clear out everything inside the file by command, %d.
  • Once this command is executed, Vim will pop up, “No lines in buffer”.

Deleting the line present at the end of the file

Firstly the person needs to be moved to the line that needs deletion.
Entering command mode is followed by pressing of the Esc key.
The last step is to getting deleted every line except the ones you want to keep. The command needed: $d.

Deleting the line present at the beginning of the file

The first thing is to position the cursor properly on the line that needs deletion.
I am following with pressing the escape key.
Finally using the command delete the line at the beginning of the file.

Steps for deleting template-based lines

Vim allows you to get the lines with the coincidence of patterns. Many ways are available for deleting template-based lines. There are several ways to delete rows based on a template.

Deleting line laced with the specific word

  • Bring to use the Esc key and enter yourself into the mode of normality in the text.
  • You can delete the line with a specific word using, r / word/.

Getting lines lacking specific words deleted

  • Esc key will help you enter in command mode.
  • Use a particular command, r!/word/. To delete like lacking a specific word.

The process to delete the empty lines.

  • Blank lines can be deleted using the Esc key and switching to the normal mode.
  • Following above, enter the mentioned command will do the trick - r/^$/d

When does vim delete every line?

You get to delete a Vim/V line using: 1,$d. When you decide to delete all lines in vi go for: 1, here $ is symbolic of the line which is next in the command. Once a line starts with:g/^$/d it has the potential to delete all empty lines. ^$ present is the resemblance of the empty lines present. The command: g/^s/\*$/d, is capable of deleting every empty line present.

Conclusion

Once you have gone through the above article and have come to acknowledge the analysis well, you will have yourself many choices as to how you can delete a line or word on Vim.
Once you are well aware of Vim’s different commands, you will come to realise how time-efficient Vim will turn out to be.

How to Convert String into Integer in Python

Objects can be any kind of data type in Python, i.e. integer and string. Sometimes, you will need to convert one data form to another while writing Python code. For example, it needs to be transformed into an integer to perform a math operation on a number represented as a string. Here’s how to convert a string in Python to an integer.

int() function in Python

The built-in function int() returns an integer decimal object from a given number or String. It takes the form below:
int(a, base=10)

Two arguments are accepted by the function:

  • a – The number or String to be transformed to an integer.
  • base – Reflects the first argument’s numeral scheme. It can have a value between 0 and 2–36. It is optional to render this statement. The default base is always 10 if no base is defined (decimal integer). Integers are usually expressed in hexadecimal format i.e., base 16, decimal has base 10, octal has base 8, and binary has base 2.

If the given string cannot be interpreted as an integer, the ValueError exception is executed by the function.

Converting a String to Integer in Python

A ‘string’ is a list of characters declared in Python using a single (‘), double (“), or triple quotes (“””). If you use quotes to declare a variable that contains only numbers, its data type is set to String. Consider the instance below:

no_of_day = "23"
type(no_of_day)

The type() function tells us that the String object is the no_of_day variable.

<type 'str' > type

Let’s try on the variable to do a math operation:

print(day+5)

After that, Python throws an exception, i.e., TypeError, because it is unable to perform a string and integer addition calculation:

Traceback (last call last):
'' file, line 1, in
TypeError: can't concatenate items with 'str' and 'int.'

To convert a string representation of a decimal integer to an int, transfer a string that returns a decimal integer: to the int() function.

no_of_day = "23" days
no_of_day_int = int(no_of_day)
type(no_of_day_int)
<type 'int' >

The total operation will be done successfully if you try to do the math now:

print(no_of_day_int+5)
28

Remember, the commas you need to delete before passing the number to the int() function if the number contains commas, marking off thousands, millions, etc.:

total = "1,000,000"int(total.replace(",", ""))
1000000

When you execute the conversion between string to an integer, just make sure that you are using a correct base representing integers in various number systems. The number 54731 is expressed as D5CE in the hexadecimal method, for instance. You need to use Base 16 to convert it to a decimal integer:
If you move the D5CE String without setting the base to the int() function, the ValueError exception will be:

int ("D5CE", 16)
54731
Traceback (last call last):
'' file, line 1, in
ValueError: invalid literal with base 10 for int(): 'D5CF'

Conclusion:
In Python, using the int() function, you can convert a string to an integer.

How to Check whether a Directory or File Exists in Bash

Numerous scenarios will arise where you may need to perform an action based on whether a file exists or not.

While using the test command in Bash, you should determine whether a file exists and determine its file type.

A test command can take one of three possible syntax:

Test expression.

[ EXPRESSION ]

[[ EXPRESSION ]]

If you want a script to be portable, you should use the available command on all POSIX shells. The latest version of the test command, [[ (double brackets), is supported on most modern systems using the Bash, Zsh, and Ksh as a default shell.

Check if the file exists.

When checking a specific file, the most commonly used FILE operations include -e and -f. The first one will verify any file’s existence regardless of what type of file it is, while the second one will only return true for those files that are regular files (not a directory or a device).

The most efficient method of determining whether a file exists uses the test command and the if statement. Suppose you see any of the following, the /etc/resolv.conf file exists:

FILE=/etc/resolv.conf

if test -f "$FILE"; then

echo "$FILE exists."

fi
FILE=/etc/resolv.conf

if [ -f "$FILE" ]; then

echo "$FILE exists."

fi
FILE=/etc/resolv.conf

if [[ -f "$FILE" ]]; then

echo "$FILE exists."

fi

If you want to deliver a different action based on whether the file exists or not, simply use the if/then construct:

FILE=/etc/resolv.conf.

if [ "$FILE" ]; then

echo "$FILE exists."

else.

echo "$FILE does not exist."

fi

You can also operate a printer without the need for an if statement. The command following the && operator is only executed if the test command’s exit code is valid.

test -f /etc/resolv.conf && echo "$FILE exists."
[ -f /etc/resolv.conf ] && echo "$FILE exists."
[[ -f /etc/resolv.conf ]] && echo "$FILE exists."

When performing a series of commands using the && operator, make sure the semicolon does not separate them.

[ -f /etc/resolv.conf ] && { echo "$FILE exist."; cp "$FILE" /tmp/; }

What is said after the || operator is only valid as long as the test command’s exit status is false.

[ -f /etc/resolv.conf ] && echo "$FILE exist." || echo "$FILE does not exist."

Verify that Directory Exists.

The -d test tools you to quickly determine whether a file is a directory.

To check whether Docker’s /etc. The directory is present, use:

FILE=/etc/docker

if [ -d "$FILE" ]; then

echo "$FILE is a directory."

fi

[ -d /etc/docker ] && echo "$FILE is a directory."

Also, you can use the double brackets [[ instead of the single brackets [.

Check if the file already exists.

Moreover, the test expression can be negated using the word not. ! logical not operator:

FILE=/etc/docker

if not ( -f "$FILE" ]; then

echo "$FILE does not exist."

fi

Similar to above:

[ ! -f /etc/docker ] && echo "$FILE does not exist."

Check for multiple files.

Instead of using complex nested if/else statements, you can write a little more simply by using logic like this:

if [ -f /etc/resolv.conf -a -f /etc/hosts ]; then
echo "Both files exist."

fi

if [[ -f /etc/resolv.conf && -f /etc/hosts ]]; then

echo "Both files exist."

fi

Without using the IF statement:

[ -f /etc/resolv.conf -a -f /etc/hosts ] && echo "Both files exist."

[[ -f /etc/resolv.conf && -f /etc/hosts ]] && echo "Both files exist."

File test operators.

The test command includes some of the following file operators, which indicate whether a file is of a particular type.

  • -b FILE - True if that FILE exists and is also a special block file.
  • -c FILE - True if that FILE exists and is also a special character file.
  • -d source - True if source exists and is also a directory.
  • -e FILE - True if that FILE exists and is also a file, regardless of the type of (node, socket, directory, etc.).
  • -f FILE - True if that FILE exists and is also a regular file (not a device or directory).
  • -G FILE - True if that FILE exists and has the same group as the user is running that command.
  • -h FILE - True if that FILE exists and is also a symbolic link.
  • -g FILE - True if that FILE exists and also has set-group-id (sgid) flag set.
  • -k FILE – True if that FILE exists and also has a sticky bit flag set.
  • -L FILE – True if that FILE exists and is also a symbolic link.
  • -O FILE – True if that FILE exists and is also owned by the user running a command.
  • -p FILE – True if that FILE exists and is also a pipe.
  • -r FILE – True if that FILE exists and is also readable.
  • -S FILE – True if that FILE is also a socket.
  • -s FILE – True if that FILE exists and also has nonzero size.
  • -u FILE – True if that FILE exists, and also set-user-id (suid) flag is set.
  • -w FILE – True if that FILE exists and is also writable.
  • -x FILE – True if that FILE exists and is also executable.

How to Check Python Version

Python is one of the most successful programming languages in the world. It is used to develop websites, write scripts, machine learning, analyze data, and many more.

This article explains how to check what Python version is installed on your operating system working the command line. This can be beneficial when installing applications that require a particular version of python.

We will also explain to you how to programmatically determine what Python version is installed on the system where the Python script is running. For example, when writing Python scripts, you will require determining whether the script supports python’s version on the user’s machine.

Python Versioning

Python uses semantic versioning. Production-ready releases are versioned in the following scheme:

MAJOR.MINOR.MICRO

For example, in Python 3.6.8, 3 is a major version, 6 is a minor version, and 8 is a micro version.

  •  MAJOR – a python, has two major versions that are not fully cooperative: Python 2 and Python 3. For example, 3.5.7, 3.7.2, and 3.8.0 are all part of the Python 3 major version.
  • Minor: These announcements are bringing new features and roles. For example, 3.6.6, 3.6.7, and 3.6.8 are all part of the Python 3.6 minor version.
  • Micro: The new micro versions include various bug fixes and enhancements.

Development announcements have additional qualifiers. For more information, read the Python “Development Cycle” documentation.

Checking Python Version

Python is pre-installed on most maximum Linux distributions and macOS. On Windows, you have to download and install it if you want.

To get which version of python is fixed on your system, run the Python –version or Python -V command:

$ python --version

The order will print the default Python version, in this case, that is 2.5.15. The version installed on your system maybe another.

Output:

Python 2.7.15+

The default version of python will be applied by all scripts that have /usr/bin/python set as an interpreter in the script’s shebang line.

Some Linux distributions have various versions of python installed at the same time. The Python 3 binary is frequently named python3, and the Python 2 binary is called python or python2, but that may not always be the case.

You can check if you have Python 3 installed by typing:

$ python3 --version
Output:

Python 3.6.8

Python 2 support ended in 2020. Python 3 is the today and future of the programming language.

At the time of writing this article, the newest major release of python is version 3.8.x. The possibilities are that you can own an older version of Python 3 installed on your system.

If you want to install the most advanced python version, the method depends on your running system.

Programmatically Checking Python Version

Python 2 and Python 3 are different. The code written in Python 2.x may not work in Python 3.x, so you have to write two other codes.

The sys module that is open in all Python versions gives system-specific parameters and functions. sys.version_info enables you to discover the Python version installed on the system. It reflects a tuple that contains the five version numbers: major, minor, micro, release level, and serial.

Let’ say you have a script that needs at least Python version 3.5, and you want to tell whether the system meets requirements. You can do that by merely monitoring the major and minor versions:

import sys

if not (sys.version_info.major == 3 and sys.version_info.minor >= 5):

   print("This script requires Python 3.5 or higher!")

   print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))

   sys.exit(1)

If you run the script using Python version less than 3.5, it will produce the following output:

Output:

Python 3.5 or higher is required to run this script. 

You are using Python 2.5.

To write Python code that runs below both Python 3 and 2, use the future module. It enables you to run Python 3.x-compatible code below Python 2.

Conclusion: 

Using the python --version, it is very easy to find what version of python is installed on your system.

How to Change user password in Linux

This write-up is being provided to guide you through the procedure of changing your own user password in the application named Linux.

One interesting thing is that you can even forcefully make users change the password used for a login in Linux and that will be discussed here.

The procedural steps that are being provided here in this guide can also be used in other applications like Ubuntu, Debian, and CentOS.

Putting in the required changes in your already existing Password

If you wish to change the login details specifically the user password for your user login you will have to provide the command mentioned below with no other tit- bits following,

 $ passwd

Changing password for linuxize.

(Current) UNIX password:

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

Once you put in the command $ password, a screen with the text mentioned above will pop up asking you the below-mentioned questions,

  • What is your current password?
  • What is the new password? Entering new password
  • Mention the new password again

Following the procedure above you will be easily able to bring the required changes in your user password.

Always remember that while filling the answers to the above questions you will not find them being showcased on the screen and front and that is totally normal.

Finally, when you try logging in to your system you will find that your new password has been generated and you can login using the freshly brewed user password.

How to facilitate change in password of another user?

It is not a factor to be surprised with as it has been already acquainted with you that access is granted to only the user who is rooted to the account or a user who has a sudo connection to the account will be provided the required privilege for making changes in the refreshed password for the account. The process that will be mentioned below is being mentioned keeping in mind that you are someone with the privilege of being connected to the account being handled as a sudo user.

When you are designing a change in a password for a different account you will have to type in the password command and entailing it should be the username of the account needing password changes. If we consider a password change in the account named lineux then the command followed will be,

$ sudo password lineux

Next step will be you coaxed into filling in a new password and confirming it:

Output

Enter new UNIX password:

Retype new UNIX password:

Once you are at the end of the procedure you will be faced with a command exactly like below,

Output

$ Password: password updated successfully

How can a user be pressured to change password at next login?

It has been set by default in many applications that the password set by a user for login details does not ever expire. Now a user can be pressurized to change the password when logging in for another time by undergoing a few commands while on the portal for Linux. The command that is provided for expiration of the old password is entailed by the name of the user:

$ sudo password --expire linuxize

Once you squeeze in the command mentioned above you will find the already existing password turning out to be immediately expired.

This procedure of immediate expiration of user’s earlier or old password will put pressure on the user to finally have the user password changed because of a message that will pop up when they log in again:

$ ssh linuxize@192.168.121.209
OUTPUT

WARNING: Your password has expired.

You must change your password now and login again!

Changing password for linuxize.

(Current) UNIX password:

Enter new UNIX password:

Retype new UNIX password:

password: password updated successfully

Connection to 192.168.121.209 closed.

You will see the connection being closed once the newly made and refreshed password is set by the user.

Conclusion

The write-up that was provided above was to help people with being able to bring out the required changes in their user password in a specific application named Linux.

The guidance that you got in the above right upper was how can you bring out the specific changes in the password and how can someone set an expiry limit to their password.