Skip to main content

Linux Commands | If you’re an aspiring system administrator, a curious developer, or just someone who loves exploring the depths of technology, understanding these powerful commands will propel you into the realm of command line mastery.

The command line interface (CLI) is a powerful tool that allows you to control your UNIX/Linux system with lightning speed and unparalleled flexibility.

In this post, we’ll look at the 20 most frequently used UNIX/Linux commands that will help you to navigate, manipulate, and unleash the true potential of Linux.

Linux commands

1. ls – Listing Files and Directories:

The “ls” command stands for “list” and is your trusty companion for listing files and directories within a specified location.

With a variety of flags such as “-l” for detailed information or “-a” to display hidden files, “ls” enables you to explore the contents of your system with ease.

ls -l            # Display files and directories with detailed information
ls -a            # Display all files and directories, including hidden ones

2. cd – Changing Directories:

The “cd” command, short for “change directory,” is your key to navigating through the file system. With “cd,” you can move seamlessly between directories, be it jumping to a specific location or traversing up the directory tree using “..” as a shortcut.

cd /path/to/directory      # Change directory to the specified path
cd ..                     # Move to the parent directory

3. pwd – Present Working Directory:

To unveil the mystery of your current location within the file system, simply type “pwd,” which stands for “present working directory.”

This command displays the absolute path of your current directory, giving you a clear sense of where you are in the vast hierarchy of your system.

pwd              # Display the current working directory

4. mkdir – Creating Directories:

Need to create a new directory? Say no more! The “mkdir” command is here to save the day. Just provide a name for your new directory, and voila! You have a fresh empty canvas to organize your files.

mkdir new_directory      # Create a new directory with the specified name

5. rm – Removing Files and Directories:

When it’s time to bid farewell to files or directories, the “rm” command comes to your rescue. Whether you want to delete a single file or an entire directory tree, the power of “rm” combined with options like “-r” for recursive deletion will make it a breeze.

rm file.txt              # Delete a file
rm -r directory          # Delete a directory and its contents recursively

6. cp – Copying Files and Directories:

The “cp” command, short for “copy,” allows you to duplicate files and directories effortlessly. Specify the source and destination, and “cp” will handle the rest, preserving permissions and ownership along the way.

cp file.txt new_location/file.txt         # Copy a file to a new location
cp -r directory new_location/directory    # Copy a directory and its contents recursively to a new location

7. mv – Moving and Renaming Files and Directories:

Need to relocate a file or directory? Or perhaps give it a shiny new name? The “mv” command is your go-to tool. Whether it’s a simple move or a complete rename, “mv” executes the task swiftly and efficiently.

mv file.txt new_location/file.txt        # Move a file to a new location
mv file.txt new_name.txt                 # Rename a file
mv directory new_location/directory      # Move a directory to a new location

8. cat – Concatenating Files:

Imagine a world where you can effortlessly combine multiple files into one. Well, “cat” makes it possible! This nifty command, short for “concatenate,” allows you to merge files, display their contents, or even create new ones.

cat file1.txt file2.txt > merged.txt      # Concatenate file1.txt and file2.txt into merged.txt
cat file.txt                             # Display the contents of a file
cat > new_file.txt                        # Create a new file and input contents (press Ctrl + D to save)

9. touch – Creating Empty Files:

In need of a blank canvas to unleash your creativity? The “touch” command enables you to create empty files in an instant. Simply specify the file name, and watch the magic happen.

touch new_file.txt        # Create a new empty file with the specified name

10. grep – Searching for Text Patterns:

The “grep” command is a text-searching powerhouse. With its ability to scan files and extract lines that match specific patterns, it’s an indispensable tool for locating information within files or even across multiple files.

grep "pattern" file.txt                  # Search for lines containing the specified pattern in a file
grep -r "pattern" directory/             # Search for lines containing the pattern recursively in a directory

11. find – Discovering Files and Directories:

When you find yourself lost in the labyrinth of your system, fear not! The “find” command is here to guide you. With its robust search capabilities, “find” enables you to locate files and directories based on various criteria such as name, size, or modification time, helping you regain your bearings in no time.

find /path/to/search -name "*.txt"        # Find files with the .txt extension in the specified path
find /path/to/search -size +1M            # Find files larger than 1MB in the specified path

12. chmod – Modifying File Permissions:

Security is paramount in the UNIX/Linux world, and the “chmod” command grants you the power to control file permissions with precision. Whether you want to make a file executable or restrict access to specific users, “chmod” is your trusted companion.

chmod +x script.sh             # Grant execute permission to a script
chmod 644 file.txt             # Set read and write permissions for the owner, and read-only permissions for others

13. man – Getting Help:

In the vast universe of UNIX/Linux commands, it’s natural to encounter unfamiliar territory. Fret not! The “man” command, short for “manual,” provides comprehensive documentation for almost every command at your fingertips. Need clarification or examples? “man” has got you covered.

man ls                # Display the manual page for the "ls" command

14. tar – Archiving and Compression:

When it’s time to bundle files and directories together or compress them into a compact package, the “tar” command is your go-to tool. Whether you’re creating backups or sharing files, “tar” ensures seamless archiving and compression operations.

tar -cvf archive.tar file1.txt file2.txt         # Create a new tar archive with the specified files
tar -xvf archive.tar                            # Extract files from a tar archive

15. ssh – Secure Remote Access:

The “ssh” command unlocks the power of secure remote access. Whether you want to log into a remote machine or execute commands on a remote server, “ssh” establishes a secure connection, protecting your data and allowing you to manage remote systems effortlessly.

ssh user@hostname              # Log into a remote machine using SSH
ssh user@hostname command      # Execute a command on a remote server using SSH

16. wget – Downloading Files from the Web:

Need to download files from the web without the hassle of a graphical interface? Enter the “wget” command! With its ability to retrieve files using HTTP, HTTPS, or FTP, “wget” simplifies the process of acquiring files, making it a must-have for any command line aficionado.

wget https://example.com/file.txt         # Download a file from the web using HTTP/HTTPS
wget ftp://example.com/file.txt           # Download a file from an FTP server

17. top – Monitoring System Processes:

Keeping a watchful eye on system processes is crucial for optimal performance. The “top” command provides real-time monitoring of CPU usage, memory utilization, and much more. With “top,” you can keep tabs on your system’s heartbeat and ensure smooth operation.

top               # Monitor system processes in real-time

18. sed – Stream Editing:

When it comes to text manipulation, the “sed” command shines brightly. As a powerful stream editor, “sed” allows you to transform text, substitute patterns, and perform intricate editing tasks on the fly. It’s a secret weapon for text processing aficionados.

sed 's/pattern/replacement/' file.txt         # Substitute the first occurrence of a pattern in a file
sed 's/pattern/replacement/g' file.txt        # Substitute all occurrences of a pattern in a file

19. awk – Text Processing and Analysis:

If you find yourself needing advanced text processing and data analysis, look no further than the “awk” command. With its robust pattern scanning and processing capabilities, “awk” is the tool of choice for complex data extraction, manipulation, and reporting.

awk '/pattern/ {print $1}' file.txt         # Search for lines matching a pattern and print the first field

20. history – Recall Command History:

Last but not least, the “history” command brings forth the magic of hindsight. It presents a chronological record of previously executed commands, enabling you to review, reuse, or modify them effortlessly. With “history,” your command line journey becomes even more efficient and productive.

history              # Display the command history

Conclusion

Remember, the UNIX/Linux command line is a vast and ever-evolving domain. While these 20 commands cover a wide range of essential functionalities, there’s always more to discover. Continue to expand your knowledge, experiment with new commands, and tailor them to suit your specific needs. The command line is your gateway to efficiency, productivity, and control. Enjoy your journey!