Using Backticks

The backtick is a special type of quotation mark that you’ll usually find near the 1 key on your keyboard. You use it in a command line to tell Ubuntu to execute the contents between the ticks as a separate command, and then to paste the output in place of the backtick’s contents.

For example, you can combine some text with a command to display the current date like this:

echo "Today is `date`"

Or, to list the current working directory in a friendly way, you could use this command:

echo "You are in `pwd`"

Or here’s how you can list all the files in your home folder (and its subfolders) that have the file extension .txt:

echo -e "`clear`Your text files:\n\n`find ~ -name *.txt`";

As you can see, there are two uses of backticks here: once to clear the screen and again to search for the text files. The -e argument tells Ubuntu to allow escaped characters such as \n, which is used to display new lines.