Becoming a Linux Shell Ninja in 5 minutes

h@shtalk
Level Up Coding
Published in
4 min readDec 12, 2022

--

Linux is a powerful and popular open-source operating system known for its stability and flexibility. At the heart of the Linux system is the Linux shell, a command-line interface that allows users to interact with the operating system and run commands to perform various tasks. In this article, we will take a closer look at Linux shell commands and how they can be used to automate and streamline common tasks.

Visual representation of how a linux terminal looks like, linux commands typed in the image
Source: https://www.pexels.com/photo/blur-bright-business-codes-207580/

The Linux shell is a command-line interface that allows users to interact with the operating system using text-based commands. Unlike graphical user interfaces (GUIs), which use icons and menus to represent and execute commands, the shell uses a text-based interface that requires users to type in commands manually. While this may seem less intuitive at first, the shell provides users with a high degree of control and flexibility, allowing them to perform a wide variety of tasks quickly and efficiently.

Linux Shell Commands

Shell commands are the building blocks of the Linux shell. These commands are used to perform a wide variety of tasks, from managing files and directories to interacting with system processes and installing new software. There are hundreds of shell commands available in Linux, each with its own unique purpose and syntax. Some of the most commonly used commands include ls for listing files in a directory, cd for changing directories, mkdir for creating new directories, and mv for moving and renaming files.

One of the key advantages of using shell commands is that they can be combined and chained together to perform complex tasks. For example, the ls and grep commands can be combined to search for files with a specific name or pattern. The output of one command can be passed as input to another command using a pipe (|), allowing you to create powerful and efficient command sequences.

Below is a short Linux cheatsheet that will help you get started:

  1. Navigating directories:
  • cd: Change the current directory
  • pwd: Print the current working directory
  • ls: List the files and directories in the current directory
  1. Working with files and directories:
  • touch: Create an empty file
  • mkdir: Create a new directory
  • cp: Copy a file or directory
  • mv: Move or rename a file or directory
  • rm: Delete a file or directory
  1. Working with text files:
  • cat: Print the contents of a file to the terminal
  • less: View the contents of a file one page at a time
  • grep: Search for a text pattern in a file
  • sed: Edit the contents of a file
  1. Running programs:
  • ./program: Run a program in the current directory
  • which: Print the location of a program
  • man: View the manual for a program
  1. Getting help:
  • --help: View the options and usage for a command
  • man: View the manual for a command
  • apropos: Search for commands related to a keyword

Linux Shell Scripts

Shell scripts are simply collections of shell commands that are executed in sequence. These scripts allow users to automate repetitive tasks and save time by executing multiple commands with a single command. Shell scripts are written in a text editor and are saved with the .sh file extension. To run a shell script, you simply use the sh command followed by the name of the script file.

Shell scripts can be incredibly useful for automating tasks that would otherwise be tedious or time-consuming to perform manually. For example, if you need to create a large number of directories, you could write a shell script that uses the mkdir command to create each directory, one by one. Similarly, if you need to copy files from one location to another on a regular basis, you could write a shell script that uses the cp command to do this automatically.

In addition to automating tasks, shell scripts can also be used to customize the Linux operating system to your liking. For example, you could write a script that modifies the system’s configuration files to change the default desktop environment or add new entries to the system’s PATH variable. These custom scripts can save you time and effort by allowing you to easily customize your system to meet your specific needs.

In addition to these basic commands, the Linux shell also includes a number of powerful features that can be used to automate and streamline common tasks. For example, the find command can be used to search for files based on their name, size, or other attributes. The grep command can be used to search for patterns within files, allowing you to quickly locate specific information. The awk and sed commands can be used to manipulate text files, making it easy to extract or modify specific pieces of information.

Overall, Linux shell commands and scripts are an essential part of the Linux operating system, providing users with the ability to automate and customize their systems. Whether you are a seasoned Linux user or a newcomer to the world of open-source operating systems, learning to use shell commands and scripts can greatly enhance your experience and productivity.

I know it’s been a while friends, but our hashtalks are finally back, I hope you missed them!

--

--