Home » Linux » Shell

Bash Aliases – What They Are and How To Use Them

Bash Aliases

If you live in the Linux Shell/Terminal, aliases are a massive timesaver. Here’s how to create your own Bash aliases, with examples. What is an Alias in Bash/Linux Shell? An alias is a shortcut to a longer command. It’s similar to a keyboard shortcut – like the CTRL + C key combination is a shortcut to the copy command in many graphical operating systems (saving the time in dragging your mouse across the screen and clicking multiple menus to reach the command), aliases are shortcuts to longer terminal commands (saving time typing out the full … Read more

Home » Linux » Shell

Remove/Delete Files/Directories in Linux with rm

Linux rm Remove File Directory

This article will outline how to delete files and directories in Linux with the rm command and give example usage. The rm Command in Linux Files and directories can be deleted from the shell/command line in Linux using the rm command. rm Command Syntax rm OPTIONS FILES Note that: OPTIONS is a list of options from the below table FILES is a list of files or directories (if the -r option is specified) to be removed Multiple files or directories can be specified, separated by spaces Options Here are the most commonly used options for … Read more

Home » Linux » Shell

Move Files With the mv Command in Linux, With Examples

Linux Move File mv

This article will walk you through moving files in Linux with the mv command, with examples and tips on moving files safely. mv Syntax Moving files is done using the mv command, which has the following syntax mv OPTIONS SOURCE DESTINATION Note that: OPTIONS is a list of options from the below table SOURCE is the path to the file you wish to move DESTINATION is the path to the destination you want to move the file 2 This can include a new file name or simply be the path to a … Read more

Home » Linux » Shell

Exiting Bash Scripts with the exit Command, With Examples

Bash Exit Script

Bash/Shell scripts usually run sequentially until all of the code in the file has been executed. The exit command will exit the script before this based on conditions of your choosing. exit Command Syntax Here’s the syntax for the exit command, which can be used in Bash/Shell scripts: exit STATUS Note that: STATUS is an optional parameter that sets the exit status of the script The exit status tells other programs whether the script executed successfully or not It will default to either 0 or the exit status of the last command executed by … Read more

Home » Linux » Shell

Array Variables in Bash, How to Use, With Examples

Bash Array

We’ve covered using variables in Bash previously – this article will explain Bash array variables and provide some example usage. What is an Array An array is a type of variable that can hold multiple values. It’s a list of values you can loop through and perform operations on each individual value. For example, you might want to perform an action on a list of files. By storing that list as an array, you can loop through the file names in it and perform the action on each … Read more

Home » Linux » Shell

What is $@ (Command Line Arguments) In Bash/Linux?

Bash $@

This article will explain what the $@ is in Bash and Bash/Shell scripting and how and why you might use it. The $@ variable is a special variable in Bash which holds the value of all of the command line arguments/parameters passed to the script. Command Line Arguments/Parameters in Bash Using command-line arguments/parameters in shell scripts is an important and useful feature, so we have a full article on it: This article follows on from our article on Command Line Arguments in Shell/Bash Scripts $@ Contains All Parameters/Arguments Passed to … Read more

Home » Linux » Shell

Linux diff – How to Show Differences and Make Patches, With Examples

Linux Diff Command

The diff command is an easy way to compare files or directories from the Linux shell. This article will show you how to use it, with some examples of common usage. The diff command performs a line-by-line comparison of two files or directories and outputs the differences between them. Why would you want to compare files or directories? You might have two files with the same name that look similar and want to see the difference between them. Comparing changes to the programming code in a project you’re … Read more

Home » Linux » Shell

cat Command in Linux/Bash – How to Use It, With Examples

cat Command Linux Bash

The cat (concatenate) command in Linux/Bash is most commonly used to read the contents of a file. It outputs the contents of a given file. Here’s how to use it. cat concatenates files to standard output – by default, this is to the console for viewing on your computer screen. This makes it useful for quickly viewing the contents of files. It also has other uses, but first, the syntax: cat Syntax cat [OPTIONS] [FILE] Note that: If FILE is not specified, will read from standard input (stdin) Multiple FILEs can be specified, separated by … Read more

Home » Linux » Shell

Redirect stdin, stdout, stderr in Linux/Bash, With Examples

Redirect stdin, stdout, stderr in Linux & Bash

The Linux/Bash shell has three data streams that you can tap into when executing commands – stdin, stdout, and stderr. Here’s how to use them. stdin, stdout, stderr allow for the display of text in the console, and the data being output each stream can be directed into other programs. These are referred to as Standard Streams. What is stdin (Standard Input)? Text input stream. Applications can accept text via stdin as input. What is stdout (Standard Output)? The text output stream of a program. Applications send data to other programs (or to the console for viewing) via stdout. … Read more

Home » Linux » Shell

Concatenate Strings in Bash/Shell Scripts, With Examples

Bash Concatenate Strings

Here’s a short article on concatenating (merging) strings in Bash – the right way. Examples included. There are various ways two or more strings could be joined in a shell script. Various programs will accept strings and return them merged/concatenated – but using the side-effect of a programs operation to concatenate strings is a bit of a waste of time, so this article will focus on the simplest, most readable method. Inserting a String into Another A string can be inserted when creating another string … Read more