SOURCE ~/.zshrc

This is the tenth in a series of posts, featuring Protips, tips, tricks, hacks, and secrets provided by Our Team 🙊 — We want to share our top tips for the growing and thriving Linux community out there. Because sometimes you need a little help...

SOURCE ~/.zshrc
Image credit: Unknown. Please contact us if you are the owner.

The source command in Linux is used to execute the contents of a file within the current shell session. It reads and parses the file line by line, running each command as if it had been written straight into the terminal. This command is very handy for reloading configuration files without having to open a new shell session.

🎧



For instance; the command source ~/.zshrc reloads the Zsh configuration file .zshrc in the current shell session.

Here's a breakdown of what this command does:

  1. source: This command, which is built into shells, runs the contents of the given file in the active shell session. Line by line, it reads and parses the file, carrying out each command as though it were entered straight into the terminal.
  2. ~/.zshrc: This is the path to the Zsh (Z shell) configuration file in the user's home directory.
    The tilde ~ symbol is a shorthand notation for the current user's home directory. This notation is very convenient for navigating and referencing files and directories within a user's home directory without needing to type the full path.
  3. .zshrc: This file is used to customize the behavior and appearance of the Zsh shell according to the user's preferences. It contains user-specific configuration settings, such as environment variables, aliases, functions, and other customization.



Why Use source ~/.zshrc?

When you make changes to your .zshrc file, such as adding new aliases, changing environment variables, or modifying prompt settings, these updates do not take effect instantly in your current shell session. By running source ~/.zshrc, you can apply these changes immediately without needing to close and reopen the terminal or start a new shell session. This command re-executes the contents of the .zshrc file, making any updates or modifications effective in the current session.

Practical Example:

Let's say you added the following alias to your .zshrc file:

$ alias ll='ls -lah'


Save the changes and run:

$ source ~/.zshrc

This command will reload the .zshrc file, making the new alias available in your current terminal session, ensuring your updates take effect immediately, streamlining your workflow, and enhancing your productivity.
Now you can use ll to list files in the long format, including hidden files, with human-readable sizes.

We hope this was of great use!

Keep Us Caffeinated  ⦿ ⦿