Type something to search...
Summary of essential Linux terminal commands for backend developers

Summary of essential Linux terminal commands for backend developers

To manage a cloud server or Docker environment, you need a small set of core Linux terminal commands: navigation (pwd, ls, cd), file manipulation (mkdir, cp, mv, rm), reading logs (cat, less, tail, grep), and system control (sudo, ps, kill, chmod). Rather than memorizing everything, learn the role of these frequently used commands and look up the rest when necessary.

Why do backend developers need the Linux terminal?

The overwhelming majority of web servers around the world run on the Linux operating system. Familiarity with Linux terminal commands is essential for managing servers, checking logs, and deploying applications.

If you are used to the fancy GUI (graphical user interface) environment of Windows or Mac OS, when you first connect to a remote server such as AWS EC2, it is easy to be confused by the terminal environment (CLI) that only displays white text on a black screen. The commands below are the ones worth getting comfortable with first.

How do you navigate files and directories in Linux?

Navigation commands play the role of Windows' 'File Explorer' and are the most basic commands in the terminal.

  • pwd (Print Working Directory): Shows the full absolute path of the folder (directory) in which you are currently located. It acts as a compass when you get lost.
  • ls (List): Prints a list of files and folders in the current folder.
    • ls -l: Displays a detailed list vertically, including file permissions, owner, capacity, and modification time. (most used)
    • ls -a: Shows all hidden files whose names start with ..
    • ls -al: Combines the above two options to view hidden files in detail.
  • cd [path] (Change Directory): Move to another folder.
    • cd /: Move to the top directory (Root)
    • cd ~: Go to the home directory of the currently connected user (e.g. /home/ubuntu)
    • cd ..: Move to one level higher (parent) folder

How do you create, copy, move, and delete files?

Linux uses mkdir, cp, mv, and rm to create, copy, move, and delete files and folders.

  • mkdir [folder name] (Make Directory): Creates a new folder.
  • cp [source] [destination] (Copy): Copies a file or folder.
    • To copy the entire folder, including its contents, add the -r (recursive) option. (cp -r myfolder backup_folder)
  • mv [source] [destination] (Move): ‘Move’ a file or folder to another location. This command is also used when 'changing' the name of the original file. (mv old_name.txt new_name.txt)
  • rm [file/folder name] (Remove): Deletes a file. (Caution: It cannot be recovered like Windows Recycle Bin, so be very careful!)
    • To delete a folder, the -r option is also required.
    • To force erase without asking, add the -f (force) option. (e.g. rm -rf node_modules)

How do you view and search file contents and logs?

cat, less, tail, and grep let you read files and search them, which you need when modifying code or checking a server error log.

  • cat [file name]: Prints the entire contents of the file on the terminal screen at once. If the file is long, it will scroll up.
  • less [file name]: Displays the contents of the file in a scrollable format. (Move with the arrow keys, press q to exit)
  • tail [file name]: Shows only the last (tail) part of the file. By default it shows the last 10 lines.
    • tail -f error.log: The most commonly used option in practice! It continuously updates and displays newly added content (log) to the file in real time on the screen.
  • grep [search word] [file name]: Finds only lines containing specific words or patterns in a file.
    • Example: grep "Error" server.log (find only lines containing the word Error in the server log)
    • It is often used with a pipe (|) when receiving and searching the output results of another command. (Example: ps -ef | grep node)

Which commands handle processes and permissions?

sudo, ps, kill, and chmod cover administrator privileges, process management, and file permissions.

  • sudo [command] (SuperUser DO): Executes the command with super administrator (root) privileges. When installing a program or changing system settings, add it before the command to avoid the 'Permission Denied' error.
  • ps (Process Status): Check the list of currently running processes. Usually, all process information is displayed with the ps -ef option.
  • kill [PID]: Used to forcefully terminate a process that has stopped due to a problem. Enter the unique identification number (PID) found with the ps command. When you want to kill for sure, use kill -9 [PID].
  • chmod [permissions] [file name] (Change Mode): Changes the read (r), write (w), and execute (x) permissions of a file or folder. (Example: Give execution permission chmod +x script.sh)

Tip: Tab key and up arrow key (↑)

The Tab key and the up arrow key are the two shortcuts that save the most typing in the terminal. If you just type the first letter of a file name and press the Tab key, the rest of the name is automatically completed. Pressing the up (↑) arrow key recalls the history of commands you previously entered. Even if you just get into the habit of using these two keyboard operations, your work speed will increase dramatically.

Related Post

Introduction to AWS EC2: Building Your First Cloud Server

Introduction to AWS EC2: Building Your First Cloud Server

Amazon EC2 lets you rent a virtual server in AWS's data centers with a few clicks, and the free tier makes it practical for learning. Creating your first instance comes down to six settings (region,

Complete CI/CD pipeline automation starting with GitHub Actions

Complete CI/CD pipeline automation starting with GitHub Actions

CI/CD replaces error-prone manual deployment with automated builds, tests, and releases, and GitHub Actions is one of the easiest ways to set it up because it runs directly inside your GitHub reposit

Platform Engineering: The Next Evolutionary Step in DevOps

Platform Engineering: The Next Evolutionary Step in DevOps

Platform engineering is the practice of building a self-service Internal Developer Platform (IDP) that hides infrastructure complexity behind a "golden path," so application developers can ship safel