50 Linux Commands You MUST Know

Written by

Reviewed by

Last updated: July 30, 2024

Expert verified

SVG Image

Are you new to Linux and feeling overwhelmed by the command line? Don’t worry; you’re not alone. Many users feel the same at first, but there’s a solution. This guide will introduce you to 50 essential Linux commands you must know about. You’ll learn how to navigate your system, manage files, and perform everyday tasks efficiently. By the end, you’ll feel more confident in using the Linux terminal and ready to explore more advanced topics.

What Are Linux Commands?

Linux commands are instructions you type into the terminal to perform tasks on your computer. They allow you to interact directly with the system, helping you manage files, run programs, and configure settings. These commands are powerful tools that give you control over your Linux system, making tasks faster and more efficient.

Basic Syntax and Structure: A typical Linux command consists of three parts:

  1. Command: The name of the program or function (e.g., ls).
  2. Options: Modifiers that change how the command runs (e.g., -l for long format).
  3. Arguments: The targets of the command, like files or directories (e.g., Documents).

Example:

ls -l Documents

Here, ls lists files, -l displays details, and Documents is the directory you’re listing. This structure allows you to perform specific tasks by combining commands, options, and arguments.

50 Linux Commands You Must Know About

Mastering Linux commands is essential for anyone looking to maximize their efficiency and control over the system. Here are 50 essential Linux commands you must know about. These commands will help you navigate directories, manage files, and optimize system performance. Let’s get started:

1. ls

The ls command lists the contents of a directory, showing files and subdirectories.

ls

Running ls without options will display all visible files and directories in your current location.

viewing contents of a current directory 1

Options:

  • -l: Shows detailed information about each file, including permissions, owner, size, and modification date.
  • -a: Displays all files, including hidden ones (files starting with a dot).

You can also use ls command to sort files in Linux.

2. cd

The cd (change directory) command is used to navigate between directories in your file system.

cd /path/to/directory

Moves you into the specified directory. If you type cd Documents, you’ll switch to the Documents folder.

navigating to directory 1

Options:

  • ..: Move up one directory level.
  • ~: Move to your home directory.

3. pwd

pwd (print working directory) shows the full path of your current directory.

pwd

It will display the directory path where you are currently located, helping you understand your position in the file system.

viewing full path of a current directory

4. cp

The cp command copies files or directories from one location to another. This command duplicates files, allowing you to make backups or transfer files. Be cautious as it overwrites files in the destination without warning.

cp source.txt destination/

Copies source.txt into the specified destination directory.

copying file to specified destination 1

Options:

  • -r: Recursively copy directories and their contents.
  • -i: Prompt before overwriting existing files.

5. mv

The mv command moves or renames files and directories. Run the following command to rename a file:

mv oldname.txt newname.txt

Renames oldname.txt to newname.txt within the same directory.

renaming a file using mv command 1

To move a folder, enter the following command:

mv -v old_folder /new_location/

This command moves old_folder to /new_location/, displaying the process.

moving file from current location to specified destination 1

Options:

  • -i: Prompt before overwriting.
  • -v: Verbose mode, showing what is being moved.

6. rm

The rm (remove) command deletes files or directories. Be very careful with rm, as it permanently deletes files. 

rm filename.txt

Deletes filename.txt from the current directory.

deleting a file in linux 1

To delete directories and their contents, you need to use the -r option.

rm -r full_folder

The terminal removes full_folder and all its contents recursively.

deleting a directory with its content in linux 1

Options:

  1. -r: Remove directories and their contents recursively.
  2. -f: Force deletion without prompting for confirmation.

7. cat

The cat command concatenates and displays the content of files. Useful for viewing short text files. For longer files, consider using less or more for easier navigation.

cat file.txt

Displays the content of file.txt directly in the terminal.

viewing content of a file in terminal 1

Options:

  • -n: Number all output lines.
  • -E: Show $ at the end of each line to indicate line breaks.

8. less

less allows you to view file contents one screen at a time, ideal for large files.

less file.txt
viewing paginated format of a file

Opens file.txt in a paginated format, letting you scroll through it.

paginated output

Options:

  • -N: Show line numbers.
  • /search_term: Search for a specific term within the file.

9. tail

The tail command displays the last part of a file. Run the following command to view the last 10 lines of file.

tail filename.txt

This command shows the last 10 lines of filename.txt.

tail command

Options:

  • -f: Continuously monitor the file for new lines.
  • -n: Specify the number of lines to display.

10. head

The head command displays the first part of a file. Run the following command to display the first 10 lines:

head filename.txt

This command shows the first 10 lines of filename.txt.

head command

Options:

  • -n: Specify the number of lines to display.

11. nano

nano is a simple, user-friendly text editor that operates within the terminal. Ideal for quick edits or creating new text files. Use the keyboard shortcuts displayed at the bottom of the editor (e.g., Ctrl + O to save, Ctrl + X to exit).

nano file.txt
opening a file in nano text editor 3

Opens file.txt for editing, allowing you to make changes directly.

editing file in nano editor 2

Here is the detailed guide on how to save and quit in nano editor, an important skill to learn to make sure all your change are saved.

Options:

  • Ctrl + G: Display help.
  • Ctrl + K: Cut the current line.

12. mkdir

The mkdir command creates new directories. Run the following command to create a new folder:

mkdir new_folder

Creates a directory named new_folder.

mkdir command

Options:

  • -p: Create parent directories as needed.

13. uname

The uname command displays system information, such as the kernel version and architecture.

uname

Outputs the system’s name, typically Linux.

viewing system information

Options:

  • -a: Display all available system information.
  • -r: Display the kernel release.

To learn how to use the rename command in Linux, read this detailed guide.

14. free

The free command displays memory usage statistics, including total, used, and available memory.

free -m

Shows memory usage in megabytes, providing a snapshot of your system’s memory resources.

viewing memory usage in megabytes

Options:

  • -h: Human-readable format.
  • -t: Show total memory.

15. ps

The ps command provides a snapshot of current processes running on the system.

ps aux

Lists all running processes with detailed information such as user, PID, and CPU usage.

Explore my post on how to check CPU frequency for a better understanding of CPU speed.

viewing all running processes with detailed info

Options:

  • aux: Display all users’ processes.
  • -e: Show all processes.

16. top

top is an interactive command that displays real-time information about system processes. Allows you to monitor system performance and manage processes.

top
monitoring system performance using top command 1

Shows a dynamic view of system processes, including CPU and memory usage.

top command output 1

Options:

  • h: Display help within top.
  • k: Kill a process by entering its PID.

17. kill

The kill command sends signals to terminate processes. Commonly used to stop unresponsive or unwanted processes. To find a process’s PID, use ps or top.

kill PID

Terminates the process with the specified PID (Process ID).

killing a process

Options:

  • -9: Forcefully kill a process.
  • -l: List all available signals.

18. ping

The ping command checks network connectivity between your system and a specified host. Useful for troubleshooting network issues, such as connectivity or latency problems.

ping google.com

Sends packets to google.com and measures the response time, indicating network connection quality.

checking if the remote host is reachable 1

Options:

  • -c: Specify the number of packets to send.
  • -i: Set the interval between packets.

19. ifconfig / ip

ifconfig and ip commands are used to display and configure network interfaces.

ifconfig

Shows all network interfaces and their configuration, including IP addresses and status.

viewing network interface settings 1

Options for ip:

  • ip a: Display all network interfaces and their details.
  • ip link set eth0 up: Enable the eth0 interface.

20. chmod

The chmod command changes file permissions, controlling who can read, write, or execute files.

chmod 755 script.sh

Sets the permissions of script.sh to be readable and executable by everyone, but only writable by the owner.

changing permission of file using numeric values 1
  • Permissions are represented by three sets of numbers (owner, group, others). Each set controls read (4), write (2), and execute (1) permissions.

21. chown

The chown command changes the owner and group of a file or directory. Important for managing file permissions and ensuring that the correct users have access to files.

sudo chown user:group file.txt

Changes the owner of file.txt to user and the group to group.

changing ownership and group of a file 1

22. tar

The tar command is used to create and extract archive files. tar is commonly used to back up files and compress them for easier storage or transfer.

tar -cvf archive.tar /path/to/directory

Creates an archive named archive.tar containing the specified directory and its contents.

creating an archive of a directory 1

To extract an archive run the following command:

tar -xvf archive.tar

The terminal extracts the contents of archive.tar into the current directory.

extracting an archive in linux 1

23. gzip / gunzip

gzip compresses files, while gunzip decompresses them. Useful for reducing file sizes to save space or for faster transfer.

gzip file.txt

Compresses file.txt, creating file.txt.gz, reducing its size.

compressing a file in linux 1

Compressed files can be decompressed with gunzip.

gunzip file.txt.gz

The terminal decompresses file.txt.gz back to file.txt.

uncompressing a file in linux 1

Options:

  • -k: Keep the original file after compression.
  • -r: Compress directories recursively.

24. find

The find command searches for files and directories in a specified location. This command is powerful for locating files based on various criteria such as name, type, size, and modification time.

find /path -name filename.txt

Searches for filename.txt within the specified path.

searching for file in specified location

Options:

  • -type d: Search specifically for directories.
  • -size +1M: Find files larger than 1MB.

25. grep

The grep command searches through text for specific patterns. Useful for finding specific information within files, like log entries or configuration settings.

grep "pattern" file.txt

Searches file.txt for lines containing pattern and displays them.

searching for specific pattern in a file

Options:

  • -i: Case-insensitive search.
  • -r: Recursively search through directories.

26. locate

The locate command quickly finds files by their names using a pre-built database. locate is much faster than find because it uses an index created by updatedb. It may not show files created after the last database update.

locate filename

Displays paths of files that match filename, providing quick search results.

searching files along with their path

Options:

  • -i: Case-insensitive search.
  • -c: Show the count of matching files.

27. awk

awk is a powerful text processing tool used to manipulate and analyze data. awk processes input text line by line and applies specified actions to lines matching given patterns.

awk '{print $1}' file.txt

Prints the first column of each line in file.txt, commonly used for extracting data.

viewing first column of the file using awk

28. sed

sed is a stream editor for performing basic text transformations on an input stream (a file or input from a pipeline). sed allows you to modify files directly or output changes to the terminal. It’s widely used for search and replace operations in scripts.

sed 's/old/new/g' file.txt

Replaces all occurrences of old with new in file.txt.

modifying file directly using sed

Options:

  • -i: Edit files in place.
  • -n: Suppress automatic output.

29. cut

The cut command removes sections from each line of files, useful for processing data in text files. It is commonly used to extract specific fields from structured text files, such as CSV files.

cut -d':' -f1 /etc/passwd

Displays the first field (username) from /etc/passwd, using : as a delimiter.

extracting specifi fields from structured text files

Options:

  • -d: Specify the delimiter.
  • -f: Specify fields to extract.

30. apt / yum / dnf

These commands manage software packages in Linux distributions. These package managers simplify software installation, update, and removal, handling dependencies automatically.

sudo apt update

Updates the package list for available upgrades and new installations on Debian-based systems.

updating system package list 6

Options:

  • install: Install specific packages.
  • upgrade: Upgrade all installed packages to the latest versions.

31. dpkg / rpm

Low-level package management commands for Debian (dpkg) and Red Hat (rpm) systems. These commands are used for installing, removing, and querying software packages, often used in scripts and automation.

dpkg -i package.deb

Installs the specified .deb package on Debian-based systems.

installing a deb package using dpkg

Options:

  • -r: Remove a package.
  • -l: List installed packages.

32. snap

The snap command manages snap packages, which are self-contained software packages. Snap packages are universal across different Linux distributions, making them convenient for installation and updates.

snap install package

Installs the specified snap package, which includes all dependencies.

installing a package using snap

Options:

  • remove: Uninstall a snap package.
  • list: List installed snap packages.

33. cron

cron is a job scheduler that allows you to run commands or scripts at specified intervals. Use cron to automate repetitive tasks such as backups, updates, or system maintenance.

crontab -e

Opens the crontab file for editing, where you can schedule tasks.

opening crontab file

Options:

  • -l: List current scheduled tasks.
  • -r: Remove all scheduled tasks.

34. iptables

iptables configures the packet filtering rules for the firewall. iptables is powerful for network security, enabling you to set up rules to control incoming and outgoing traffic.

sudo iptables -L

Lists the current firewall rules, showing which traffic is allowed or blocked.

viewing current firewall rules

Options:

  • -A: Append a new rule.
  • -D: Delete a rule.

35. fail2ban

fail2ban helps prevent brute-force attacks by monitoring log files and banning suspicious IP addresses. Configurable to monitor different services, fail2ban improves security by automatically blocking malicious login attempts.

sudo fail2ban-client status

Displays the status of fail2ban, including active jails and banned IPs.

checking fail2ban status

Options:

  • start: Start the fail2ban service.
  • stop: Stop the fail2ban service.

36. htop

htop is an interactive system-monitoring process viewer. More user-friendly than top, htop allows for easy navigation and process management with a visual interface.

htop
monitoring system performance using htop command 2

Provides a real-time, color-coded view of system processes, including CPU and memory usage.

htop command output 1

Here is the detailed guide for installing and using htop in Linux.

Options:

  • F4: Filter processes by name.
  • F9: Kill a selected process.

37. rsync

rsync synchronizes files and directories between two locations, locally or remotely. Commonly used for backups and file transfers, rsync is efficient, only transferring changed files.

rsync -avh source/ destination/

Synchronizes the source/ directory with the destination/, copying only the differences.

synchronizing source directory with destination directory

Options:

  • -z: Compress data during transfer.

38. curl

curl transfers data from or to a server, supporting various protocols. Useful for interacting with web APIs, curl can send and receive data, including headers and authentication.

curl http://example.com

Fetches the content of the specified URL, displaying it in the terminal.

fetching content of specified url

Options:

  • -o: Save output to a file.
  • -I: Fetch headers only.

39. tr

The tr command translates or deletes characters from input text. Often used in pipelines to process text, tr is useful for case conversion, character replacement, and deletion.

echo "hello" | tr 'a-z' 'A-Z'

Converts lowercase letters to uppercase in the input string hello.

converting lowercase letters into uppercase letters of a string

Options:

  • -d: Delete specified characters.
  • -s: Replace repeated characters with a single occurrence.

41. df

The df command reports file system disk space usage, helping you monitor available storage. This command helps you understand how much space is left on your drives, displaying sizes in kilobytes, megabytes, or gigabytes.

df -h

Shows disk space usage for all mounted file systems in a human-readable format.

viewing disk usage in human readable format

Options:

  • -i: Show inode usage.
  • -T: Show the file system type.

42. du

The du command estimates file space usage, showing the size of files and directories. Useful for identifying large files or directories consuming disk space, du helps manage storage effectively.

du -h /path/

Displays disk usage of each file and directory under /path/ in a human-readable format.

viewing disk usage of a directory

Options:

  • -s: Show total size of each argument.
  • -d: Limit the depth of directories displayed.

43. who

The who command displays logged-in users and their session information. Useful for monitoring user activity on a system, who provides information about active sessions.

who

Lists currently logged-in users, including their login times and terminals.

Here is my detailed guide on how to check Linux login history.

listing currently logged in users

Options:

  • -b: Show the last system boot time.
  • -u: Show idle time for each user.

44. date

The date command displays or sets the system date and time. Besides displaying the date and time, you can format the output or set the date and time.

date

Shows the current date and time, useful for checking the system clock.

viewing current date and time

Options:

  • -u: Display UTC time.
  • -s: Set the date and time.

45. history

The history command shows the command history, allowing you to re-execute previous commands. Helps you track and reuse commands without retyping them, and you can use specific commands from the history list.

history

Lists previously executed commands in the current session.

listing previously executed commands in the current session

Options:

  • !n: Execute the nth command from history.
  • -c: Clear the command history.

46. alias

The alias command creates shortcuts for frequently used commands. Aliases help save time and reduce errors by shortening long commands or commands with options.

alias ll='ls -l'

Creates an alias ll for ls -l, simplifying the command input.

creating an alias

Options:

  • unalias: Remove an existing alias.
  • alias: List all defined aliases.

47. uptime

The uptime command shows how long the system has been running since the last reboot. Useful for monitoring system stability and performance, showing load averages for the past 1, 5, and 15 minutes.

Uptime

Displays the current time, system uptime, user sessions, and system load averages.

viewing uptime of system

48. which

The which command locates a command’s executable path. Useful for identifying the specific executable that will run when a command is invoked, particularly in environments with multiple versions.

which ls

Displays the path of the ls command executable, helping you find where commands are installed.

viewing path of ls command

49. echo

The echo command displays text or variable values. Useful for displaying messages or the contents of variables. It supports special characters and formatting options.

echo "Hello, World!"

Prints Hello, World! to the terminal, commonly used in scripts to output text.

printing text in the terminal output

Options:

  • -n: Omit trailing newline.
  • -e: Enable interpretation of backslash escapes.

50. man

The man command displays the manual pages for other commands. The man pages are an essential resource for understanding command syntax and options, especially for complex commands.

man ls
opening manual for ls command

Opens the manual for the ls command, providing detailed information about usage, options, and examples.

ls command manual file

Final Thoughts

As you explore these essential Linux commands, you’ll gain the skills needed to effectively manage your system. Mastering these commands covers everything from file management to system monitoring, equipping you to handle daily tasks with confidence.

If you’re eager to learn more, I recommend exploring:

  • How to use the command line on Linux, which will help you navigate and execute tasks more efficiently.
  • Additionally, learning about the help command in Linux will enhance your understanding of various command options and their usage.
  • Finally, understanding how to run Linux commands in the background can improve your multitasking and productivity, allowing you to manage multiple processes seamlessly.

Frequently Asked Questions

How do I find help or documentation for Linux commands?

You can find help for Linux commands using man pages, which provide detailed documentation directly in the terminal. Additionally, the info command offers more comprehensive guides. Online resources like the Linux Documentation Project and various forums also provide valuable insights and examples for understanding command usage.

What are the differences between Linux and Unix commands?

While Linux and Unix share many similar commands, there are differences due to their development environments. Linux is open-source, with many distributions, leading to variations in command implementations. Unix, being older and proprietary, has commands that may differ slightly in syntax and options. However, the core functionality remains similar.

Can I use Linux commands on macOS?

Yes, many Linux commands work on macOS because it uses a Unix-based system. The macOS Terminal supports commands like ls, cp, and mkdir. However, some commands may have different options or variations. Installing additional packages with Homebrew can enhance compatibility and provide more Linux-like functionality on macOS.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Use Command Line on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next