We talk to our computer’s operating system (OS) all the time. Most of us do this through a graphical user interface (GUI), with icons,windows, and fancy visuals that make it pleasing to the eye to interact withour computers. Another – more powerful – way to do this is through what’scalled a command-line interface, enabling a higher level of communication withthe computer. A popular way to interact through this interface type is the Bash scripting language which we’ll work up to focusing on.
The command line interface is a computer program that enables you to talk to and navigate a computer and files. On is what’s called the Terminal on Mac and for Windows it’s the Command Prompt.
To communicate through this interface, we use what’s called a command-line interpreter (CLI). This is the part of a computer OS that understands and executes commands from human/program input. In some OSs, the CLIis referred to as the shell. Common shells used today include:
Bash (Bourne-again SHell) – A Unix shell and used by default in Linux distributions. The name is a pun on the shell it superset (Bourne shell) and its author (Stephen Bourne). We’ll be looking at this Bash and some of its commands more in depth.
Zsh (Z shell) – An extension of Bash and the current default CLI for MacOS.
PowerShell – Not quite a shell per-say, PowerShell is Microsoft’s task automation and configuration management program including a CLI and the associated scripting language.
The first thing you’ll see pop up in a Linux Terminal when launching it is something like this:
<username>@<hostname><current working directory>$
Here, the dollar sign stands for a user. The default folder (AKA directory) we start out in when we first log in is the home directory denoted by a tilde:
From here we can start typing in Bash commands to communicate with the OS! Heads up, it's best practice to use a Virtual Machine (VM) while learning so you can play around without the worry of accidentally harming your computer.
The number of available commands to use in with the Bash shell is overwhelming not to mention the different ways you can use each command.If you’re ever unsure of a command’s use, input options, flag options, or Feel like learning more about it, use the man command followed by the command in question to display it’s manual.
As mentioned, most Unix shell commands have multiple flag options to invoke while using it. These allow you to tailor a command along with its arguments. These are either denoted by a single (-) or double (--) dash followed by a letter or sequence of letters. Again, use man to see a command’s possibilities and the particular syntax!
One of the most important uses of the CLI is navigating and managing a system’s directories and the files they contain:
pwd Print current working directory
cd Changes one’s directory in relation to their current directory
cd ~ Navigate directly to the home directory
cd .. Navigate up one directory level
cd - Navigate to the previous directory
cd / Navigate into the root directory
mkdir Make directories
rmdir Remove directories – BE CAREFUL WITH THIS COMMAND
cp Copy files
touch Change file access and modification times / create file with default permissions if file doesn’t exist
rm Remove/delete files – BE CAREFUL WITH THIS COMMAND
ls List directory contents
ls -a Don't ignore entries starting with “.” (hidden files/directoriesunseen in the GUI)
ls -l Use a long listing format
ls -h With -l and -s, print sizes
Interacting with different Linux systems, it’s important to learn as much information about the system as possible. Here’s a list command tools that will help with this, most automatically installed:
whoami Displays effective user id
id Return user identity
hostname Set or print name of current host system
uname Print operating system name
ifconfig Configure network interface parameters
ip Internet Protocol
netstat Show network status
ss Another utility to investigate sockets
ps Process status
who Display who is logged in
env Set environment and execute command, or print environment
lsblk List block devices
lsusb List USB devices
lsof List open files
lspci List all PCI devices
To end a session in the shell, you can use the exit command. Now you have a basic grip on Bash commands! For more information,check out our other posts below! Stay tuned to the writings.