Useful Bash Command Line Tips and Tricks Examples - Part 5

Useful Bash Command Line Tips and Tricks Examples – Part 5

In this article, we will explore user input: for all those times you want to ask the user to ‘press enter to continue’, or to actually read a string of input and store it into a variable for later processing. We will also look at how to find manual pages for built-in commands which otherwise may not seem to be available.

In this tutorial you will learn:

  • Useful Bash command line tips, tricks and methods
  • How to interact with the Bash command line in an advanced manner
  • How to sharpen your Bash skills overall and become a more proficient Bash user

Read more

Useful Bash command line tips and tricks examples - Part 1

Useful Bash command line tips and tricks examples – Part 1

The Bash command line provides nearly limitless power when it comes to executing nearly anything you want to do. Whether it is processing a set of files, editing a set of documents, handling big data, managing a system or automating a routine, Bash can do it all. This series, of which today we present the first part, is sure to arm you with the tools and methods you need to become a much more proficient Bash user. Even already advanced users will likely pickup something new and exciting. Enjoy!

In this tutorial you will learn:

  • Useful Bash command line tips, tricks and methods
  • How to interact with the Bash command line in an advanced manner
  • How to sharpen your Bash skills overall and become a more proficient Bash user

Read more

How to connect to an FTP server using Python

How to connect to an FTP server using Python

FTP (File Transfer Protocol) needs no presentations: it is among the most used file transfer methods between one or more clients and a server. By design it supports both anonymous access and authentication, but in its most basic form it doesn’t provide data encryption, that’s why it is often secured via TLS.

A lot of FTP client applications are available on Linux, as for example Filezilla (graphical) or lftp (command line). Sometimes, however, we may want to access an FTP server programmatically, perhaps to schedule file transfers. One easy way to do this is by using a programming language like Python. In this tutorial we will learn how to use the ftplib library to interact with an FTP server.

In this tutorial you will learn:

  • How to create an instance of the ftplib.FTP class
  • How to list files on a remote FTP server
  • How to upload files in binary and “lines” mode
  • How to download files in binary and “lines” mode
  • How to create,delete and rename directories and files
  • How to change working directory

Read more

Create a random character text file using Linux shell

Here is a nice trick on how to create a dummy character text file consisting of any chosen or random characters. In the first example we will create and simple file consisting of a single character X with a size of 1000 bytes:

$  < /dev/urandom tr -dc "X" | head -c1000 > file.txt
SAMPLE:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

or we can create a file consisting of an alphabetic and numeric character:

$ < /dev/urandom tr -dc "[:alnum:]" | head -c1000 > file.txt
SAMPLE:
CCjeuAhJNc4yxBfeMbbYX1U1TnSCVS5oiV53MtGoA6s45FAw9H9PyfZJHrA421

Read more

GDB debugging tutorial for beginners

GDB debugging tutorial for beginners

You may already be versed in debugging Bash scripts (see How to Debug Bash Scripts if you are not familiar with debugging Bash yet), yet how to debug C or C++? Let’s explore.

GDB is a long-standing and comprehensive Linux debugging utility, which would take many years to learn if you wanted to know the tool well. However, even for beginners, the tool can be very powerful and useful when it comes to debugging C or C++.

For example, if you’re a QA engineer and would like to debug a C program and binary your team is working on and it crashes, you can use GDB to obtain a backtrace (a stack list of functions called – like a tree – which eventually led to the crash). Or, if you are a C or C++ developer and you just introduced a bug into your code, then you can use GDB to debug variables, code and more! Let’s dive in!

In this tutorial you will learn:

  • How to install and use the GDB utility from the command line in Bash
  • How to do basic GDB debugging using the GDB console and prompt
  • Learn more about the detailed output GDB produces

Read more

pip on Linux

Install pip on Linux

pip is the package manager for the Python coding language. It can be installed on a Linux system and then used on the command line to download and install Python packages and their requisite dependencies.

This gives developers – as well as users who are just executing Python programs but not developing them – an easy way to download software packages written in Python. It’s available for installation on any major Linux distro and operates in much the same way as a distro’s package manager, which you’re probably already familiar with.

In this guide, we’ll show you how to install pip for Python 2 and Python 3 on various Linux distributions. We’ll also show you basic usage commands for pip, such as installing and removing software packages.

In this tutorial you will learn:

  • How to install pip for Python 2 and Python 3 on major Linux distros
  • Basic usage commands for pip

Read more

Checking PHP version on Ubuntu Linux

How to check PHP version on Ubuntu

After installing PHP or an entire LAMP server on Ubuntu Linux, there are a few ways you can check to see what version you’re running at any time. This can help you stay up to date and develop web applications that adhere to newer coding standards and conventions, since PHP is still being developed.

In this guide, we’ll show you multiple ways to check the version of PHP on Ubuntu. Feel free to pick whichever method is most convenient for your situation.

In this tutorial you will learn:

  • How to check PHP version on Ubuntu

Read more

phpinfo page on a Linux system

How to create phpinfo.php page

PHP developers and web server admins can use the phpinfo function to quickly see information about their installation of PHP. This can assist in debugging, seeing what version of PHP is installed, or seeing various configuration options.

On Linux systems, it’s common to make a phpinfo.php page after installing a LAMP server or LEMP server to make sure that PHP is working and to verify settings.

In this tutorial, we’ll guide you through the creation of a phpinfo.php page on your own system, as well as how to access this file afterwards.

In this tutorial you will learn:

  • How to create phpinfo.php page

Read more

Deleting a local and remote Git branch

Git: delete branch

When working with Git, it’s common for projects to contain multiple branches. Over time, these branches may become irrelevant and need deleted. Other times, they change purpose and its necessary to rename the branch.

In this guide, we’ll show you the step by step instructions for deleting Git branches via the command line on a Linux system. We’ll show the process for deleting local branches as well as remote branches in the sections below.

In this tutorial you will learn:

  • How to delete local and remote Git branches

Read more

Renaming Git branch

Git: rename branch

When working with Git, it’s common for projects to contain multiple branches. Sometimes these branches change purpose over time or simply have a naming error, and in such cases it’s necessary to rename the branch.

In this guide, we’ll show you the step by step instructions for renaming Git branches via the command line on a Linux system. We’ll show the process for renaming local branches as well as remote branches and go over what you need to know to ensure a smooth transition.

In this tutorial you will learn:

  • How to rename local and remote Git branches

Read more

How to trace system calls made by a process with strace on Linux

How to trace system calls made by a process with strace on Linux

There are times when it’s useful to inspect what a running application is doing under the hood, and what system calls it is performing during its execution. To accomplish such a task on Linux, we can use the strace utility. In this article we will see how to install it and we will learn its basic usage.

In this tutorial you will learn:

  • How to install strace
  • How to use strace to trace system calls made by a process
  • How to filter specifics system calls
  • How to attach to an already running process
  • How to generate a system call summary

Read more

Bash regexps for beginners with examples

Bash regexps for beginners with examples

Using regular expressions in Bash provides you with plenty of power to parse nearly every conceivable text string (or even full documents), and transform them into nearly any output desirable. If you regularly use Bash, or if you regularly work with lists, textual strings, or documents in Linux, you will find that many jobs can be simplified by learning how to use regular expressions in Bash. Continue reading to learn basic Bash regular expression skills! If you are already familiar with basic regular expressions in Bash or another coding language, see our more advanced bash regular expressions. If not, continue reading to learn basic Bash regular expression skills!

In this tutorial you will learn:

  • How to use regular expressions on the command line in Bash
  • How regular expressions can parse and transform any text string and/or document
  • Basic usage examples of regular expressions in Bash

Read more