Most used Linux commands - focus on Ubuntu

Ivan Radunovic

Mar 01, 20247 min read
Most used Linux commands - focus on Ubuntu

Linux, including Ubuntu, relies heavily on the terminal for system administration and file management tasks. The terminal provides a powerful interface to control your system and perform tasks efficiently. Here's a detailed guide starting from the most used commands to more specific ones, including examples of command input and output.

Navigating the File System

Understanding how to move around the file system is crucial. Here are some commands to get you started:

  • pwd (Print Working Directory): This command shows you the current directory you're in, helping you keep track of your location in the filesystem hierarchy.
    • Example: Typing pwd might return /home/username, indicating your current directory.
  • ls (List): To see what files and directories are in your current directory, ls is the command to use.
    • Example: ls might display Documents Downloads Music, showing the contents of your current directory.
  • cd (Change Directory): When you need to move to another directory, cd is your go-to command.
    • Example: cd Documents changes your current directory to Documents.

Managing Files and Directories

Creating, moving, copying, and deleting files and directories are common tasks you'll perform in the terminal.

  • mkdir (Make Directory): Creates a new directory.
    • Example: zmkdir NewFolderz creates a directory named NewFolder.
  • rmdir (Remove Directory): Deletes an empty directory.
    • Example: rmdir NewFolder deletes NewFolder, provided it's empty.
  • cp (Copy): Copies files or directories.
    • Example: cp file1.txt file2.txt makes a copy of file1.txt named file2.txt.
  • mv (Move or Rename): Moves or renames files or directories.
    • Example: mv file2.txt Documents/ moves file2.txt to the Documents directory.
  • rm (Remove): Deletes files (use cautiously).
    • Example: rm file2.txt deletes file2.txt permanently.

Working with File Content

Viewing, searching, and manipulating the content of files are essential skills.

  • cat (Concatenate and Display): Shows the content of one or more files.
    • Example: cat file1.txt displays the content of file1.txt.
  • less and more: Both commands let you read text files one screen at a time.
    • Example: less file1.txt opens file1.txt in a scrollable interface.
  • grep (Global Regular Expression Print): Searches for text within files.
    • Example: grep "search term" file1.txt finds "search term" in file1.txt and shows each matching line.
  • head and tail: Display the beginning and end of files, respectively.
    • Example: head file1.txt shows the first 10 lines of file1.txt.

System Information and Management

Monitoring and managing system resources are critical for maintaining system health.

  • top: Provides a dynamic, real-time view of running processes.
    • Example: top displays a list of all running processes and their resource usage.
  • df (Disk Free): Shows disk space usage.
    • Example: df -h displays disk space in a human-readable format.
  • du (Disk Usage): Reports the space usage of directories.
    • Example: du -sh Documents/ shows the total size of the Documents directory.
  • ps (Process Status): Displays information about active processes.
    • Example: ps aux provides a detailed view of all running processes.

Networking Commands

Managing network settings and troubleshooting connectivity are common tasks.

  • ping: Tests connectivity with another network host.
    • Example: ping google.com checks if google.com is reachable and measures the response time.
  • ip addr show: Displays IP addresses assigned to all network interfaces.
    • Example: ip addr show lists all network interfaces and their associated IP addresses.

Managing File Permissions

Linux's file permission system controls access to files and directories.

  • chmod (Change Mode): Alters the access permissions of files and directories.
    • Example: chmod 755 script.sh sets the permissions of script.sh to read-execute for everyone but write for the owner.
  • chown (Change Owner): Changes the owner and group of a file or directory.
    • Example: chown username:groupname file1.txt changes the ownership of file1.txt to "username" and the group to "groupname".

Package Management in Ubuntu

Ubuntu uses the Advanced Packaging Tool (APT) for package management, simplifying the process of installing, updating, and removing software.

  • Update and Upgrade: Keeping your system up-to-date is crucial for security and stability.
    • Example: sudo apt update refreshes the list of available packages, and sudo apt upgrade upgrades all installed packages to their latest versions.
  • Install and Remove Software: APT makes software installation and removal straightforward.
    • Example: sudo apt install [package_name] installs a new package, and sudo apt remove [package_name] removes an installed package.

Archiving and Compression

Archiving and compressing files can save space and facilitate file transfers.

  • tar: Combines multiple files into one archive file and can compress them.
    • Example: tar -czvf archive_name.tar.gz /path/to/directory creates a compressed archive of a directory.

By mastering these commands, you'll be well-equipped to navigate, manage, and optimize your Ubuntu system from the terminal. Practice each command to become familiar with its options and nuances, enhancing your Linux command-line proficiency.

Share
Author Photo
Ivan Radunovic is a Senior Developer with over 11 years of experience in web development. His expertise are Laravel SaaS solutions. So far he developed or took part in 300+ Laravel projects.

More Infrastructure tutorials

Get visitors real IP address when using Cloudflare Proxy

When Cloudflare Proxy is active our webserver will receive it's IP as a visitor IP address. This quick fix will help you get true IP.

Mar 03, 2024 Ivan Radunovic

Block unwanted GA4 referrals - Google analytics spam

If you're wondering what is that huge spike in Google Analytics traffic, and is it legit traffic. This is the latest GA4 spam campaign

Feb 26, 2024 Ivan Radunovic

Self host Plausible - Google Analytics open source alternative

Google Analytics is tracking only small portion of your visitors, because majority of them have adblockers installed. With Plausible on a custom domain you'll capture more visits.

Feb 23, 2024 Ivan Radunovic