Home » Linux » Shell

Linux Tip: Using visudo to Avoid Costly Mistakes

Linux visudo

Linux Tip: Use visudo to Edit the sudoers File to Avoid Costly Mistakes This article will show you how to use visudo to edit the sudoers file to grant root access to users – and protect against making mistakes that could lock you out of your Linux system forever. What is the sudoers File? The sudoers file defines which users have access to the sudo command on Linux systems. The file is located at: /etc/sudoers …and it looks like this: # # This file MUST be edited with the ‘visudo’ command as root. # # … Read more

Home » Linux » Shell

How to Unzip Files in Linux with the unzip Command

Linux unzip

We’ve zipped files from the Linux command line; now, let’s unzip them. This short article will show you how. Zipping Files Zipping files is common parlance for compressing one or more files or directories into a .zip file – a compressed file format. We cover how to do that in this article, so there’s no need to repeat too much of it here. The Unzip Command The unzip command may not be installed on your system by default. If it isn’t, it can be installed on Debian/Ubuntu-based OS by running: … Read more

Home » Linux » Shell

How to Execute PHP from the Command Line (Bash/Shell)

Execute PHP from the Command Line/Bash

This article will quickly run through the ways PHP can be used from the Bash shell/command line, with examples. PHP is usually used for generating content to be served on the web – but it can also be used from the command line. This is usually done for the purposes of testing or finding out information about the PHP environment – but PHP can also be used for writing command-line scripts (though, again, it’s not really done that frequently – probably because there are better … Read more

Home » Linux » Shell

Bash Scripts Set Environmental Variables with EXPORT [HowTo]

Bash Set/Export Environmental Variable

This tutorial will show you how to set environmental variables in Bash/Shell scripts using the export keyword. Generally, variables declared in Bash/Shell scripts exist only within the scope of that running Bash/Shell script. To make them available elsewhere, they can be set as an environmental variable – meaning that the variable will be available when executing commands outside of the script on your system – for example, making the variable available from the command line after the script has completed. The export keyword does this – … Read more

Home » Linux » Shell

HEREDOC (Here Documents) in Bash and Linux Shell – Tutorial

Bash Heredoc

This article will show you how to use a Heredoc (Here Document) in Bash/Shell scripts to work with multi-line text. Heredocs are most useful for accepting multi-line input- the user can enter a line of text, press enter, then enter the next line, and so on. It can also be used to define multi-line text in scripts. It can also send multiple commands into an interactive program – this will be shown in the examples later. The examples in this article will work in both … Read more

Home » Linux » Shell

Using the printf Command in Bash/Shell, With Examples

Bash printf Command

This article will show you some practical examples for using the printf command in the Bash/Shell on Linux. The printf command outputs text much like the echo command does – but it allows for more control over the output formatting. It’s a useful tool for generating your own formatted text output – especially if you need to embed variables in text, include newlines, align and format text, and even display converted values. printf Syntax The printf command has the following syntax: printf [-v var] format [arguments]… Note that: The -v option … Read more

Home » Linux » Shell

How to Prompt for User Input in Bash/Shell Scripts

Bash Prompt For Input

This short tutorial will teach you to prompt the user for typed input from your Bash/Shell scripts. It’s easy to learn, easy to do, so read on! The read Command To read user input in shell scripts, use the aptly named read command. It has the following syntax: read OPTIONS VARIABLES Note that: The read command will read a line from standard input and split that input into fields Usually, standard input is the terminal with input from your keyboard, but you can also pipe or redirect input to the read command From the users perspective, they will … Read more

Home » Linux » Shell

How To Run Commands in the Background [Linux/Ubuntu]

Linux Ubuntu Run Command in Background

This article will show you how to run commands in the Linux (including Ubuntu) shell background. This is useful when working remotely via SSH. Say you’re connected remotely via SSH to a remote computer, and you want to execute a lengthy task. While the task is running, usually, you’d have to keep the connection open, with the terminal window open. However, this can be a hassle if you need to close the window to perform another task or if you have a spotty internet connection … Read more

Home » Linux » Shell

The tr Command in Linux – What It Is and How To Use It

Linux tr Command

The tr (translate) command in Linux reads text from standard input, performs some modification to the text, and then sends it to standard output. This article explains and shows why and how you might use it. tr Command Syntax Here’s the syntax you’ll need to use the command: tr OPTIONS SET1 [SET2] Note that: OPTIONS should be a list of options from the below table The characters in SET1 will be replaced with the characters in the corresponding position in SET2 These are optional – some of the OPTIONS are capable of performing translations, … Read more

Home » Linux » Shell

How to Use the which Command in Linux, With Examples

Linux which Command

This tutorial will teach you how to use the which command in Linux with some simple examples. The which command will tell you the path to the executable used by a command on the system if it exists. Why is this useful? Say you’ve got two copies of the MySQL executable installed on your system (installed via different means), and you want to know which one is actually in use so that the other can be removed – the which command can tell you which of the two is called when you execute MySQL on … Read more