<img src="https://ws.zoominfo.com/pixel/6169bf9791429100154fc0a2" width="1" height="1" style="display: none;">
Curious about how StrongDM works? 🤔 Learn more here!
Search
Close icon
Search bar icon

Linux Commands Cheat Sheet: Basic, Advanced & More

StrongDM manages and audits access to infrastructure.
  • Role-based, attribute-based, & just-in-time access to infrastructure
  • Connect any person or service to any infrastructure, anywhere
  • Logging like you've never seen

Over the past few decades, Linux command has filled a wide variety of critical needs for various computing tasks. These range from system administration to software development. Hence, a good understanding and mastering of these commands is pivotal for anyone deploying Linux-based systems.

While Linux offers a user-friendly graphical interface (GUI) for solving tasks, the command remains its core. Understanding Linux commands increases agility with development work, enables you to solve tasks efficiently, and provides an easier way to troubleshoot issues with greater precision. It also helps you to automate repetitive tasks.

This article explores essential Linux commands ranging from navigation, file management, text manipulation, system maintenance, user management, process management, and more.

Basic Linux Commands

Navigation Command 

  • pwd:

Displays the current location of the user within the directory structure. Executing this command retrieves the absolute pathway of the current working directory and its output is sent to the terminal. 

  • ls, ls -a, ls -l:

This command list the contents of your working directory
This is an essential tool used in obtaining information about files and directories.
ls lists out filenames and directory names in the current directory
ls -a lists out all files and directories including the hidden files
ls -l provides a list of files and directories showing additional information such as size, modification date and ownership

  • cd:

Alter the current working directory in a terminal session. It facilitates navigation through the hierarchical structure of a file system efficiently. 

File Management Command

  • touch: 

Used in creating empty files. The touch command can also be used to update the modification timestamps of existing files without modifying their content. 

  • mkdir: 

This command is used to create one or more directories. 
mkdir directory_name - Creates a single directory 
mkdir dir1 dir2 dir3 - Creates multiple directories 
mkdir -m 755 my_directory - Creates a directory with specific permissions
mkdir -p parent_dir/child_dir/grandchild_dir - Creates nested directories 

  • rm, rm -r, rm -rf: 

The rm command deletes one or more specified files or directories. It is essential to note that this action is irreversible, and deleted files cannot be recovered using standard methods.
rm: Deletes the specified files.
rm -r:   Recursively removes the specified directories and their contents.
rm -rf: Forcefully removes the specified directories and their contents without prompting for confirmation.

  • mv: 

Facilitates the relocation of files from one location to another within the file system while providing options for control and customization. 

  • Cp, cp -r: 

Copies files or directories from a source location to a destination location. 

  • The cp -r commands allows cp to copy directories and their contents recursively. 
  • ln -s: 

Enables creation of links between files. Specifically, the -s option facilitates the creation of symbolic links, which are references to other files or directories. 

  • cut: 

Extracts sections from each line of input data or files. 

  • head: 

Displays the first ten lines of a file, providing a quick glimpse into its contents. 

  • tail: 

This command displays the last few lines of a file.

System Information Command

The System Information Command is used to gather comprehensive information about the system's hardware, software configuration, network settings, and running processes.

  • Checking system status
    -top: Displays a list of processes sorted by various criteria such as CPU usage, memory consumption, and execution time.
    -htop: Presents system processes in a hierarchical tree structure, allowing users to visualize the relationship between parent and child processes. 
  • Disk Usage and Files
    -du: By executing du followed by the desired directory path, users can obtain a summary of disk space utilization for that directory and its subdirectories.
    -df: displays free disk space on the file system.

Network Information

These Network Information tools offer crucial insights into network configuration, connectivity, and performance, enabling administrators to diagnose issues, optimize routing, and ensure seamless network operation.
        -ip manages network interfaces and routing tables.
        -netstat provides details on active connections, routes, and interface statistics.
        -ping assesses host connectivity through ICMP echo requests.
        -traceroute maps the packet path to a destination, identifying network hops. 

User Management

User management is a fundamental aspect of system administration, involving tasks such as creating, modifying, and deleting user accounts, as well as managing user groups. 

  • Adding and removing files
    -useradd: Creates new user accounts on the system.
    -userdel: Employed for the removal of user accounts, effectively erasing their entry from the system's user database.
    -usermod: Modifies various attributes, including the username, home directory, shell, and user ID (UID)
  • Changing User Information
    -passwd: Enables users to change the password associated with their user account. 

Group Management

        -groupadd: Creates a new group on the system.
        -groupdel: Facilitates the removal of existing groups from the system by erasing the group's entry from the system's group database.
        -groupmod: Empowers administrators to modify attributes of existing groups.

File Permissions

File and directory permissions play a critical role in regulating access to resources, thereby ensuring security and privacy within a system. These permissions dictate whether a user can read (r), write (w), or execute (x) a file or directory. 

  • Modifying permissions
    -chmod: Alters the permissions of files and directories.
    -chgrp: Changes the group ownership of a file or directory, allowing the file's group to be set to a specified group. 

Process Management

Process management plays a crucial role in ensuring efficient resource utilization and maintaining system stability. Process management involves the creation, scheduling, and control of processes within an operating system environment.

  • Viewing active processes
    -ps: Lists running processes on a system.
    -pstree: Displays the processes on the system in a tree-like structure, illustrating their hierarchical relationships
  • Managing Processes
    -kill: Sends a signal to a process, instructing it to terminate.
    -pkill: Terminates processes based on their names rather than PIDs.
    -nice: Launches a new process with a specified priority level (niceness). 
    -renice: Changes the priority (niceness) of an already running process. 

Networking Commands

  • Managing network Interfaces
    -ifconfig: Primarily to configure network interfaces.
    -Ip link set up/down: Activates a network interface, while ip link set down deactivates it.  
  • Firewall and security
    -iptables: Sets rules and policies for packet filtering
    -ufw: Simplifies the process of firewall by providing a more intuitive command line interface and application profiles for common services.
  • Transfering files
    -scp: Secures copy files between hosts on a network. it deploys SSH( Secure Shell) for data transfer and authentication, ensuring data confidentiality during transmission.
    -resync: Used for remote file and directory synchronization either locally or between remote hosts. 

Page Management 

  • Using package Managers
    -apt: Upgrades, installs and updates and removes network packages from your system
    -yum: Installs, updates and removes and manages network packages on your system.
    -dnf: Similar to yum, dnf is used for installing, updating, removing, and managing software packages on your system.
    -pacman: Installs, upgrades, and removes software packages on your system. 

Advanced Commands

  • Scripting Basics

Scripting basics involve writing scripts, which appear in sequences of commands and are interpreted and executed by a technique known as a scripting language interpreter. Key concepts include variables, control structures (like conditionals and loops), comments, input/output handling, and error handling. Mastering these basics enables automation, customization, and data processing tasks through scripting.

Introduction To Bash

Bash is a versatile Unix shell and scripting language used for interacting with the operating system. With Bash, users can execute commands directly or automate tasks by writing scripts. 

Its customizable shell environment enables efficient system management and workflow customization. Learning Bash enhances productivity and efficiency in the command line environment.

  • Finding Files and Directories
    -find: Searches for files and directories in a directory hierarchy based on various criteria, such as name, type, size, and time.
    -locate: Locates files and directories by searching through a pre-built database of file paths.
  • Monitoring Logs and systems
    -tail: Displays the last few lines of a text file or a stream of data.
    -grep: Searches for patterns within files.It's commonly used to find lines in files that match a specific pattern or to filter output based on certain criteria.
    -awk: Uses for pattern scanning and processing language.With apt, you can easily search for packages, install dependencies, and manage software repositories.
    -sed: Uses stream editor for filtering and transforming text.

Tips and Tricks

  • Customizing the Command Line
    -alias: Creates shortcuts or alternate names for other commands.
  • Useful Keyboard Shortcuts 
    ctrl + A: move to the beginning of the line
    ctrl + F: move forward one character.
    ctrl + B: move back one character.
    ctrl + E: move to the end of the line.
    alt + B: move back one word.
    alt + F: move forward one word.

Conclusion

These basic Linux commands should help you perform essential tasks in a Linux environment. Keep in mind that specific command options and behaviors may vary depending on your Linux distribution. Always refer to your distribution’s documentation for more details.

Simplifying Linux Commands with StrongDM

StrongDM is a valuable tool, simplifying not just Linux command management but also security and compliance across your infrastructure.

After exploring a broad range of Linux commands and their applications,  StrongDM helps with the management of access to systems and databases across an organization, especially in complex Linux environments.

Book a demo with us to discover StrongDM.


About the Author

, Zero Trust Privileged Access Management (PAM), the StrongDM team is building and delivering a Zero Trust Privileged Access Management (PAM), which delivers unparalleled precision in dynamic privileged action control for any type of infrastructure. The frustration-free access stops unsanctioned actions while ensuring continuous compliance.

StrongDM logo
💙 this post?
Then get all that StrongDM goodness, right in your inbox.

You May Also Like

How To Use SSH to Connect to a Remote Server (Windows, Linux & Mac)
How To Use SSH to Connect to a Remote Server (Windows, Linux & Mac)
Secure Shell (SSH) is one of the most effective ways to access and manage remote systems. This technology encrypts communications between the client and the server, enhancing system security and preventing unauthorized access. Another important benefit of SSH is its simplicity. This technology is relatively easy to use with various tools and clients, as we will demonstrate below. Plus, you can also use SSH for file transfers, running commands, and even tunneling. This guide explains how to use SSH to connect to remote servers across Windows, Linux, and MacOS environments.
How to Create Users in Linux with useradd (Step-by-Step)
How to Create Users in Linux with useradd (Step-by-Step)
Setting permissions, revoking access, and performing other user management duties in Linux can improve your system's security and organization, ensuring users can access the resources they need when they need to. The useradd command lets you create, modify, and check user accounts, helping you handle multi-user environments across various Linux distributions.
How to Change Password in Linux: A Step-by-Step Guide
How to Change Password in Linux: A Step-by-Step Guide
Explore our in-depth guide on how to change and edit passwords in Linux using various commands and tools. Also, learn some advanced Linux password management techniques.
How to Extract or Unzip .tar.gz Files in Linux (With Examples)
How to Extract or Unzip .tar.gz Files in Linux (With Examples)
A .tar.gz file is a compressed archive file format that combines the tar and gzip formats. These files are popular among system administrators, developers, and regular computer users for archiving and compression. You might need to extract or unzip .tar.gz files if you're transferring big datasets or distributing software with Linux, the third-most popular desktop operating system in the world.
15 Kubernetes Security Best Practices