How to Remove Last N Columns of File in Linux

A great way to remove the last n columns of a file in Linux is to use the combination of the cut and rev commands. The cut command is used to cut/remove sections/columns of text files. The rev command is used the reverse the content of lines in text files. In order to use these

read more

3 ways to get the Nth Line of a File in Linux

The need to get/print a particular line of a file on the Linux shell is a common task. Luckily there are various ways to do this. Below are three great ways to get the nth line of a file in Linux. 1. head / tail Simply using the combination of the head and tail commands

read more

How to Change Branch Name in Git (Local and Remote)

Changing a branch’s name in Git is a common task and fortunately very easy to do. Changing the name of a local branch: git -m newBranchName If you are not on the branch being renamed, you must specify this branch in the command: git -m oldBranchName newBranchName There is no direct way to rename a

read more

Git – How to Push Local Branch to Remote Repo (like GitHub)

Branching is a common task when working with Git. However new branches on your local machine aren’t automatically added to your remote repository. You will need to explicitly push your local branch to your remote repository. You can do this on the command line using:

Remote repositories often have the alias “origin”. So if

read more

Add a Shared Directory (Data Volume) to your Docker Container

Adding a data volume to your Docker container creates a shared directory between the container and your host file system. Data in volumes is readable and writeable to any number of containers. Data in volumes is designed to persist regardless of a containers life cycle, so deleting a container will not delete or change the

read more

Export data from Postgres as CSV

Exporting data from Postgres as a CSV or tab delimited file can be fairly simple using the COPY command. Examples below. Export an entire table as CSV:

Export an entire table as CSV with Header:

Export query as CSV:

Export query as data tab delimited text file:

Export data directly to

read more

Using UNIX Wildcards with AWS S3 (AWS CLI)

Currently AWS CLI doesn’t provide support for UNIX wildcards in a command’s “path” argument. However, it is quite easy to replicate this functionality using the –exclude and –include parameters available on several aws s3 commands. The wildcards available for use are: “*” – Matches everything “?” – Matches any single character “[]” – Matches any

read more

Create a Docker group Linux

When working with Docker in Linux, you may find yourself using sudo before every Docker command. This is because the docker daemon binds to a Unix socket (which by default is owned by the root user) rather than a TCP port. Thus the reason for always needing to use sudo. A good way to avoid

read more

How to Enable the ‘root’ user on Ubuntu

By default, the root user is locked in Ubuntu. To unlock it, simply run the command below, and provide the new password for the root user when prompted.

Now you should be able to log in as the root user using the su command:

If for some reason you want to lock the

read more

Count Unique Elements in Text File with AWK

Counting the distinct/unique elements of text file is a common task.  Below is an example of doing this is AWK, using sample_data_1.txt.

Here is what is happening above: cat sample_data_1.txt – reading the file piping the data to AWK BEGIN{FS=”\t”} – specifying the field separators of the file NR>1 – Only executing the following

read more