programox
Let's Learn How to Use the Terminal Together

Let's Learn How to Use the Terminal Together

Published on

Welcome to the exciting world of terminals! If scenes of hackers rapidly typing away or developers engrossed in black screens filled with text intrigue you, you're in the right place.

1. What is the Terminal and how does it differ between operating systems?

Terminal:

A text-based interface where instead of clicking on icons or menus, you type commands to perform tasks.

Think of the terminal as the app and the shell (Bash, Zsh, Cmd) as the engine. Different operating systems come with various default shells, but the purpose remains consistent: execute user commands through text.

Unix-like Operating System (Linux / MacOS)

Unix-like OS (e.g., Linux, macOS) emphasizes modular, command-line-focused operations and treats everything as a file, often offering open-source flexibility.

Bash:

  • Definition: Short for "Bourne Again SHell", it's a shell program that reads and executes commands.
  • Usage: Default shell for Linux and older Macs.

Z shell (Zsh):

  • Definition: Another shell, like Bash, but packed with features and improved customizability.
  • Usage: Growing in popularity and often used as a replacement for Bash in many systems - MacOS switched to use zsh by default in 2019.

Windows

In contrast, Windows provides a more standardized, GUI-centric experience with proprietary components.

cmd.exe (CMD):

  • Definition: Also known as Command Prompt, cmd.exe is the original command-line interpreter for the Windows operating system, rooted in its MS-DOS heritage.
  • Usage: Predominantly used for executing batch scripts and basic system tasks on Windows. Over the years, while it's maintained its core functionalities, newer and more powerful alternatives like PowerShell have been introduced to cater to advanced needs. However, cmd remains an essential tool for many due to its simplicity and direct lineage to the classic Windows command line.

PowerShell:

  • Definition: Developed by Microsoft, PowerShell is a task automation and configuration management framework that consists of a command-line shell and scripting language.
  • Usage: Unlike the traditional cmd, PowerShell is more powerful, offering advanced scripting capabilities, integration with .NET framework, and comprehensive management tools for Windows systems. Introduced to replace the cmd, it has become the preferred CLI for many Windows administrators.

2. Why is the Terminal Useful?

Utilizing the terminal allows users to engage directly with system processes, initiate scripts, and execute commands—capabilities that might be absent or harder to access in a GUI. This kind of engagement paves the way for swifter and streamlined operations, particularly for intricate tasks or managing system configurations.

  • Power & Flexibility: Accomplish tasks faster than graphical interfaces.
  • Automation: Write scripts to automate repetitive tasks.
  • Troubleshooting: Get detailed logs and feedback.
  • Advanced Features: Access tools and configurations available only through the command line.

3. Key Commands and Things to Do

Bash / Zsh Examples

Basic Commands

  1. ls: List files and directories.

    $ ls
    MoonMissionNotes.txt  Apollo11Photo.jpg  SecretBaseBlueprints/
    
  2. cd [directory name]: Change directories.

    $ cd SecretBaseBlueprints
    
  3. pwd: Display the current directory path.

    $ pwd
    /home/astronaut/SecretBaseBlueprints
    
  4. echo [text]: Print a message.

    $ echo "Houston, we have a solution!"
    Houston, we have a solution!
    
  5. man [command]: Show the manual for a command.

    $ man ls
    

Advanced Commands

  1. grep [pattern] [file]: Search for a pattern within a file.

    $ grep "landing" MoonMissionNotes.txt
    Line 42: Ensure safe landing site is chosen.
    
  2. find [path] -name [filename]: Find files by name.

    $ find /home/astronaut -name Apollo11Photo.jpg
    /home/astronaut/MoonMissions/Apollo11Photo.jpg
    
  3. chmod [permissions] [file]: Change file permissions. (For instance, make a file executable)

    $ chmod +x LunarBaseActivator.sh
    
  4. chown [user]:[group] [file]: Change file ownership.

    $ chown captain:mooncrew MoonMissionNotes.txt
    
  5. |: Pipe, used to send the output of one command as input to another.

    $ ls | grep "Apollo"
    Apollo11Photo.jpg
    

CMD Examples:

  1. dir: List files and directories.

    > dir
    AdventureLog.txt  HolidaySnap.jpg  Bookshelf\
    
  2. cd [directory name]: Change directories.

    > cd Bookshelf
    
  3. echo [text]: Print a message.

    > echo "Command Prompt, here we come!"
    Command Prompt, here we come!
    
  4. type [filename]: Display the content of a file.

    > type AdventureLog.txt
    
  5. copy [source] [destination]: Copy files.

    > copy HolidaySnap.jpg Backup\
    

PowerShell Examples:

  1. Get-ChildItem: List files and directories.

    PS> Get-ChildItem
    AdventureLog.txt  HolidaySnap.jpg  Bookshelf\
    
  2. Set-Location [directory name]: Change directories.

    PS> Set-Location Bookshelf
    
  3. Write-Output [text]: Print a message.

    PS> Write-Output "PowerShell in action!"
    PowerShell in action!
    
  4. Get-Content [filename]: Display the content of a file.

    PS> Get-Content AdventureLog.txt
    
  5. Copy-Item [source] [destination]: Copy files.

    PS> Copy-Item HolidaySnap.jpg -Destination Backup\
    

4. Wrapping Up and Next Steps

You've just scratched the surface of the vast world of terminals. Practice regularly, and soon, you'll harness the full power of the command line. Explore:

  • Scripting: Combine commands to automate tasks.
  • Text editors: Dive into terminal-based editors like vim or nano.
  • WSL: For Windows users, unlock the power of Linux commands on your PC.

The terminal might seem like an old-school tool, but its relevance in today's tech world is undeniable. Keep exploring, and happy coding!

Some resources to keep learning:

Bash

https://www.learnshell.org/

Zsh

https://linuxconfig.org/learn-the-basics-of-the-zsh-shell

CMD

https://github.com/security-cheatsheet/cmd-command-cheat-sheet

PowerShell

https://learn.microsoft.com/en-us/training/modules/introduction-to-powershell/

Author

Authors