Build a Better Process

Linux source Command Summary with Examples

Linux source allows you to read and execute commands from a file.
  1. Purpose - Learn what source is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with source.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux source, 87 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / source-command.html

An ad-free and cookie-free website.

Examples of the Linux source Command


Learn to read and execute commands at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux source Command Summary with Examples (3:38)

Video Script

The Command and Why You Need It

Our eighty-seventh word, or command to memorize is source from our category Workflow.

source allows you to read and execute commands from a file.

Common Linux source Options
-options description
None for this command

Recall from videos (tutorials) #47 and #49 we saw shell built-in programs that modified variables and here we'll learn another shell built-in that reads and executes commands as we transition to our last section on writing scripts to pull together what we've learned here.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The source command has no options, and the argument is the file.

Unlike most commands, help is not available with double-dash --help and information is found in the lengthy man page for bash.

So why is source an important command? Well, at times you need to run scripts in the current setting without say logging out and back in to take effect, like a configuration file. And now you know how to do that.


Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Start with mkdir from video (tutorial) #22 to create a directory called bin and put it in our home directory using the tilde ~/.

$ mkdir ~/bin

So source reviews directories in the PATH, but bin won't be there (meaning typing the name of the script won't work until you add this directory to your PATH). So you can add a line export PATH=~/bin:, you need the colon, and then this section here for the PATH variable "$PATH" to your .bashrc file so that bash at startup adds this directory to the PATH each time.

$ export PATH=~/bin:"$PATH"

Okay, let's move on the script. I used nano to create funscript, and at this point it prints text and the date. We'll add to it in coming videos (tutorials).

$ cd bin $ nano funscript

Please pause the video to read and create this on your end and save it as funscript.

GNU nano 2.2.6 File: funscript #!/bin/bash # The shebang gives the absolute path to the executable program # To see if it points to the right executable try: which bash # This is our first script called funscript # From video 87, print text and the current date/time echo -e "\nThe current date and time:" date [ Read 10 lines ] ^G Get Help ^0 WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell

Okay next, use chmod 700 so the owner can read, write and execute funscript.

$ chmod 700 funscript

And last, let's type source funscript.

The current date and time: Sun Nov 13 22:09:10 PST 2016

And there it is, how fun. 8D

A Final Tip

Okay now you know how to use source. And you know the syntax for commands, options and arguments.

One last tip about the source command. So there is a synonym for source that you really need to know and it's simply a period .. That's it.

Okay, thanks for visiting today. I hope this was a helpful introduction to the source command.

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

We'll keep building on this script as we explore the Intermediate-level topic of shell scripting. It may help to supplement this text-based tutorial with our YouTube videos for the more difficult section ahead.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / source-command.html

linux source command
source command
linux source
source command linux
execute commands
unix source
dot file
what is dot
dot operator
dot slash
bash source
shell source
linux source command
read files
read commands
source linux
bash script
reload configuration files
period character in linux

A newly-updated free resource. Connect and refer a friend today.