Skip to content

henderson-01/Bash-Nano-Guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

🚀 The Beginner's Guide to Bash & Nano

Master the Ubuntu terminal by customizing the Nano editor, creating shortcuts (Aliases), and writing your first Bash scripts.


📝 Nano Editor Optimization

Nano is the most beginner-friendly terminal editor. By creating a .nanorc file, we can add features like mouse support, custom colors, and line numbers.

Configure Nano

Open your configuration file:

nano ~/.nanorc

Add these "Pro" Settings

Copy and paste the following into the file to enable a modern, powerful editor interface:

# --- General Settings ---
set linenumbers      # Show line numbers for easy debugging
set autoindent       # Match indentation of previous line
set tabsize 4        # Set tabs to 4 spaces
set tabstospaces     # Convert tabs to actual spaces
set minibar          # A cleaner look for the bottom bar
set softwrap         # Wrap long lines so they stay on screen
set positionlog      # Re-open files at the last used cursor position
set mouse            # Enable mouse clicking and scrolling

# --- Syntax Highlighting ---
include "/usr/share/nano/*.nanorc"

# --- Interface Colors ---
set titlecolor black,yellow     # Top Bar/Minibar (Black text on Yellow)
set statuscolor black,yellow    # Status messages/pop-ups
set numbercolor yellow          # Side bar line numbers
set keycolor yellow             # Shortcut keys (^X, ^O, etc.)
set functioncolor yellow        # Descriptions of the shortcuts

Tip

Understanding Keybindings: In Nano documentation, the ^ symbol stands for the Ctrl key, and M (Meta) stands for the Alt key. For example, M-U means Alt + U.


⚡ Custom Aliases & Functions

In Ubuntu, the best practice is to keep your shortcuts in a dedicated file called .bash_aliases.

Create the Alias File

nano ~/.bash_aliases

Add your Shortcuts

Copy and paste these functions to automate your system maintenance:

#!/bin/bash

# This is the update & upgrade shortcut.
update() {
    echo "Checking for updates and upgrades..."
    sudo apt update && sudo apt upgrade -y
    echo "Process completed!"
}

# This is the autoremove shortcut.
cleanup() {
    sudo apt autoremove
    echo "Autoremove process completed!"
}

Activate Changes

To make these shortcuts work immediately without restarting your terminal, run:

source ~/.bashrc

📜 Creating & Executing Scripts

A script allows you to automate repetitive tasks. One of the coolest things about Nano is that it handles file creation and editing at the same time.

Create a New Script

nano myscript.sh

Note

Did you know? If myscript.sh doesn't exist yet, Nano won't give you an error, It will simply open a blank new file for you. Once you save (Ctrl + O), the file is officially created on your system.

Write the Code

Always start with the "Shebang" (#!) so the system knows to use Bash.

#!/bin/bash
echo "Hello! Today is $(date)"
echo "Your current directory is: $(pwd)"

Make it Executable

By default, Linux blocks files from "running" for security. Give it permission:

chmod +x myscript.sh

Execute it

Run your script using the relative path:

./myscript.sh

🛠️ Pro Tips & Shortcuts

Once you've customized your terminal, these are the essential commands to keep you moving fast.

⌨️ Nano Essentials

Action Shortcut
Save File Ctrl + O then Enter
Exit Nano Ctrl + X

💡 Terminal Tricks

  • The "Tab" Key: Never type a full file name! Type the first few letters and hit Tab to auto-complete it.
  • Stop a Runaway Script: If a script gets stuck in a loop, press Ctrl + C to force-kill the process.
  • Clear the Screen: Type clear or press Ctrl + L to wipe the terminal clutter.
  • Recall Commands: Use the Up/Down arrow keys to cycle through your previous commands.

⚠️ Disclaimer

Caution

This is provided "as is" without warranty of any kind. I am not responsible for any damage, data loss, or issues caused by the use of this information. Use it at your own risk.

About

Master the Ubuntu terminal by customizing the Nano-editor, creating shortcuts (Aliases), and writing your first Bash scripts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors