The Terminal

Fredd Somm

Fredd Somm

· 4 min read
This is how a terminal looks like.

Why should I even care?

A terminal application allows us to browse, read, and enter data into the computer quickly. It may look outdated, as it was the only computer interface available until the 1980s. Yet, since working with text-based (i.e. command-line interface (CLI)) terminals is faster than with any GUI operation system (i.e. graphical user interface, such as reading this text in a browser or anything that involves using your mouse and clicking around), it allows you to be more productive and efficient. As you probably have realised, efficient solutions are one of the most important goals for engineers.

What is a terminal?

As an example, this is what my terminal looks like:

Image

A terminal is an application that lets us input commands into the computer (i.e. a console), and so lets us interact with the shell. A shell program (like Bash in Linux and Mac OS X, PowerShell for Windows; other popular ones are Fish or Zsh) is a command-line interface (i.e. CLI) program that interprets user commands (e.g., cd Documents/Personal/Photos = command cd lets you go into different folders on your computer, such as, in this case, your personal photos folder) from the terminal and executes them.

The shell and the terminal are programs installed by default on all operating systems, but the user can install or remove them. Additionally, the syntax and features of various shells vary. Shells allow us to type in scripts, which are collections of commands/instructions (such as cd) that a computer can understand and execute.

Simply put, a terminal is software that allows you to input text, and your computer will execute these commands by understanding the shell interpreter.

Interestingly, the program in which the shell will run is the terminal. However, the shell and terminal programs run separately. This implies that you can run any shell on any terminal. In that sense, there is no dependency between the two programs. Bash is typically the default shell that most OSs ship with, yet many advise installing ZSH since it provides a more flexible plugin experience. For example, the default shortcuts for git. I use it on my MacBook Pro as well. Download them here.

Different terminals

Although a default terminal is installed on all operating systems, other choices are available, each with unique features and functionalities. Here is a small list of different operating systems:

Operating SystemTerminal NameComment
macOShttps://iterm2.com/iTerm2 is a great alternative to macOS's default terminal. I use it next to my VSCode in-built terminal.
macOShttps://www.warp.dev/Warp is a sleek macOS terminal alternative (i.e. it’s prettier), but you need to sign in and agree to their terms of service, which I find strange. Still, some love it.
Windowshttps://canonical-ubuntu-wsl.readthedocs-hosted.com/en/latest/Windows 11 now offers the Windows Subsystem for Linux, allowing Linux systems to run on Windows PCs.
Linuxhttps://launchpad.net/terminatorEvery Linux distribution emphasizes the terminal and has a decent built-in terminal, but some developers seem pleased by the terminator.

How do you learn the command lines?

Learning to interact well with the terminal is only done through practice. In contrast to GUI operating systems, where you do not need much prior knowledge to interact with the computer, with a CLI operating system, you need to learn and know the “vocabulary”/commands for the computer to understand you.

Many videos and articles are out there regarding learning the command lines, yet they are often quite long (I watched some videos for hours), and I believe a personalised cheat sheet is helpful. In this sense, I have listed useful terminal commands below, and you can copy, expand and personalise your own command line cheat sheet. Feel free to share your expanded list with me.

Terminal Commands Cheat Sheet:

//Intro Information:

//Important! Generally, play around and have fun with the terminal!

$ //$ indicates that the user, typically with regular privileges, can input commands.

# //# indicates that the user is a root user (dangerous to be always a root user as you can wipe out large data)

control(or commandfor macOS)shiftminus or plus //to get bigger or smaller text size in the terminal

directories // mean “folders” \nfiles //mean “files”

ls //List Storage = Gives you a list of current directories you are logged in to

ls -a //List Storage All = Shows all directories

ls -l //List Storage Long = Shows a long list of directories (with additional information like last edit time etc)

pwd //present working directory = shows the entire path (absolute path) directory and explains where you are

cd(+directory name) //Change Directory =open directory

cd.. //Change Directory = go back one level

cd //Change Directory = bring me to the home menu

\\ //Means it is a whitespace in bash

pushd /(directory name) //to remember where the before directory and then go to another directory

popd //go back to push directory name

file .(directory name) //tells you what file you are looking at. Like directory, image, etc

locate(directory name) //search-like function

whatis which(command name like cal) //explains shortly what a command is or does

which(command name like cal) //where a command is or if it is installed

man //manual page that gives a detailed description of a command

mkdir(directory name) //make directory = creates a directory

touch(directory name, can be multiple names as well) //creating files

(Press up arrows) //to see the most recent commands you have typed

cp(directory name) //copy = copy file

nmv(file name to file name where it should move) //Move = move file

history //shows all commands that you have typed

history|(command name like less) //see all the commands

rm // !!watch out!! remove = permanently removes all the files

rm * // !!watch out!! removes ALL files

rm -r // !!watch out!! removes all files and directories attached to it

rmdir // !!watch out!! Remove directory = remove all empty directories with no files inside

cat(directory name) //concatenate = will list everything in a bunch of files

cat(two file names) //concatenate = merge two file information

cat>(file name) //concatenate = move it to file2\n\nControl D //to tell it you are done

cat>>(two file names) //concatenate = append add information or text files quickly

more(file name) //(not so popular or used often)= pager that just pages through the entire file

less(file name) //read a text file\n\n“Q” is to quit more or less command

nano(file name) //text editor to edit a file(control O to overwrite and control Esc to exit)

ls -al / > fileName.txt //list all root directories and (!) put it in a new file

sudo or also su- //(spoken suduu) substitute user due = root user or admin account

su - (user name) //login as the specific user

id //id from any user

exit //leave user account


Following 5 examples shows us how the permissions can be calculated using the simple method of addition, where each permission is assigned a number. Adding them will produce the appropriate number for the rights given. r (read) - 4 bit; w (write) - 2 bit; x (execute) - 1 bit —> so if all are allowed 4+2+1 = 7

chmod(ex. +x)(file name) //change mode command = add or subtract rights/permissions

chmod700 //change mode command = only gives the admin all the rights (permissions), and the other two (groups and users) don’t get any access

chmod644 //change mode command(only makes sense for files)= give admin read and write privileges and rest view rights

chmod755 //change mode command(mostly makes sense for directories)= give admin read and write privileges and rest view rights

Control C //kills commands to stop a command

killall(file or executed program) //hard stop for Firefox

Control d or exit //exit complete terminal

control l //redraw screen= “empty” previous prompts

//to copy an existing repository down to your computer 

git clone <your URL> //example git clone https://github.com/freddsomm/indiehacker.info

//Install all dependencies on your newly copied project. This depends on the project and is usually npm, yarn or pnpm
npm install
#or
yarn install
#or 
pnpm install

//Try your code on localhost (test environment)
npm run dev 
#or 
yarn dev 
#or
pnpm dev

//Test your code with valid tests
npm test 
#or
yarn test
#or
pnpm test

//When adding a commit to an existing git repository 

git add .
git commit -m 'FREDD SOMM made a commit.'
git push origin main

Cmd and k //Clears the screen of the terminal (I find it quite helpful to get the terminal ordered)

Conclusion

Terminals may seem antiquated initially, but they offer unparalleled speed and efficiency in computer interaction, making them indispensable tools for productive (software) engineers. As engineers strive for efficient solutions, mastering the command-line interface becomes crucial for communicating well with your computer.

I hope you found this article and the cheat sheet helpful. I would love to hear your feedback on it.

Fredd Somm

About Fredd Somm

I deeply care about creating exceptional digital experiences but come from a non-technical background.

IndieHacker.Info is the guide I wished I had to start my own SaaS company as a total beginner. Pre-order the Notion Template "From 0 to IndieHacker" now!

Made with ❤️ by FreddSomm.com
Copyright © 2024 IndieHacker.Info | Subscribe to my newsletter here