How to Run a Shell Command from Python and Get The Output?

In Python, often you may want to execute linux command and get the output of the command as string variable. Naive way to do that is to execeute the linux command, save the output in file and parse the file. >>> import os >>> cmd = “wc -l myTextFile > outfile” >>> os.system(cmd) A better [...]

How To Set PATH variable on Bash Shell?

How Set PATH Variable on BASH Shell: Hint export command

Have a new executable file/program? Want to execute it just by typing the name of the program instead of full path where the program is located?  The best solution is to add the path to new executable to your list of all search paths. The idea is that every time one types a command the [...]

How To Check If a File or Directory Exists Using Shell Script?

One of the common tasks in shell scripting in Linux/Mac OS, checking if a file or directory exists already and to create the file/directory if it does not exists. Here is how to check if a file or directory exists in Linux shell script. The basic syntax to check if a file exists is and [...]

How to Find Where Linux/Mac OS X Commands Are Physically Located?

If you are a beginner it is a good thing to learn about the director/file structures of Linux/Mac OS. It is even better to start learning where the actually commands are located in your machine. You may roughly know that the commands are in some “bin” directory, but not the exact location. The command “type” [...]

Understanding Variables in Shell Scripting

A number of beautiful and powerful programming languages, like Python, Ruby, and Perl are available for scripting needs. Even then you may find the old school unix shell scripting very useful tool to learn and use. For sure, shell scripts looks crazy and hard to read/understand. Once you get a hang of it, you might [...]

How to Get a Specific Line or Lines From a Big File? Hint: Use One Liner AWK

awk

If you are working with a huge text file with millions of lines and want to know the content of a specific line, there are a few tricks you can play to get the line you want.  The naive approach of reading the file line by line (say in python) and keeping a count on [...]

Two Most Useful Commands, If You Live On The Linux/MacOS Terminal

Do you use the linux/Mac OS X terminal a lot? If yes, you must have a few most useful commands. The commands that help you move around terminal fast and gives you the super power to look up your history real fast will be handy on every day use. Calling them as the “Most Useful [...]

Tips to Get Started with Screen, the Terminal Multiplexer

Screen

The more you feel comfortable with terminal, the higher the number of terminals that will be open. For sure you will many things to keep a tab, one for your email, one for the code, one for executing the code, and so on. And one might easily get annoyed, rightly so, recreating your multiple sessions [...]

Ten Linux Commands on “tar” and “gzip” You Need to Know

Admit it. Almost every time you deal with a tar” file or “gzip” file, you wonder what was the command that I used last time to “——”. You can fill the blanks with “Creating a new tar file, how to gzip a tar file, how to unzip a file, how to get a peek of [...]

How to Install Spotify in Linux?

How to Install Spotify in Linux?

Spotify, the digital music service, that has made listening to music more social has crossed the Atlantic ocean and landed in US. With Spotify, you dont need to buy songs any more. Instead, for a monthly subscription, the whole world of music is yours to stream to almost any device (Well almost). Needless to say [...]