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

Summary of essential Linux terminal commands for backend developers

Throw away the mouse and become familiar with the keyboard

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 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. Rather than trying to memorize all commands at first, it is better to understand the role of frequently used core commands and find and use them when necessary.

1. File and directory search function

These are the most basic commands that serve as Windows' 'File Explorer'.

  • pwd (Print Working Directory): Shows the full absolute path of the folder (directory) in which I am 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

2. File manipulation (create, copy, move, delete)

  • 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)

3. Check and search file contents

Used when modifying code or checking the 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)

4. System management and 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 (↑)

It is inefficient to type out every file name in the terminal. If you just type the first letter of the file name and press the Tab key, the rest of the name is automatically completed. Also, by pressing the up (↑) arrow key, you can recall 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

I need my own server! The joy I felt when I studied programming and created my first web application is indescribable. However, if it only works on my computer's local host (localhost:3000), it w

Complete CI/CD pipeline automation starting with GitHub Actions

Complete CI/CD pipeline automation starting with GitHub Actions

Escape the nightmare of manual deployment “Okay, now the coding is done! Let’s connect to the server, get git pull, reinstall dependencies, build, kill the existing process, and launch a new pr

Platform Engineering: The Next Evolutionary Step in DevOps

Platform Engineering: The Next Evolutionary Step in DevOps

Introduction: The Paradox of "You build it, you run it" The DevOps culture, epitomized by Amazon CTO Werner Vogels' famous quote "You build it, you run it," has contributed greatly to increasing