Top 50 Essential Ubuntu Commands for Daily Use: Detailed Guide with Examples


File and Directory Management

  1. ls – List directory contents.
    • Syntax: ls [options] [directory]
    • Example: ls -la /var/www/
    • Details: Lists all files and directories in /var/www/, including hidden files, with detailed information (-la).
  2. cd – Change directory.
    • Syntax: cd [directory]
    • Example: cd /var/www/html
    • Details: Changes the current working directory to /var/www/html.
  3. pwd – Print working directory.
    • Syntax: pwd
    • Example: pwd
    • Details: Displays the full path of the current directory.
  4. mkdir – Make a new directory.
    • Syntax: mkdir [options] [directory]
    • Example: mkdir /var/www/new_project
    • Details: Creates a new directory named new_project.
  5. touch – Create an empty file.
    • Syntax: touch [filename]
    • Example: touch index.html
    • Details: Creates an empty file named index.html.
  6. cp – Copy files or directories.
    • Syntax: cp [source] [destination]
    • Example: cp file.txt /backup/
    • Details: Copies file.txt to the /backup/ directory.
  7. mv – Move (or rename) files or directories.
    • Syntax: mv [source] [destination]
    • Example: mv file.txt old_file.txt
    • Details: Renames file.txt to old_file.txt.
  8. rm – Remove files or directories.
    • Syntax: rm [options] [file/directory]
    • Example: rm -rf /tmp/testdir
    • Details: Removes the directory testdir and its contents recursively (-rf).
  9. cat – Concatenate and display file content.
    • Syntax: cat [file]
    • Example: cat /etc/hosts
    • Details: Displays the content of /etc/hosts.
  10. nano – Simple text editor.
    • Syntax: nano [file]
    • Example: nano /etc/hostname
    • Details: Opens hostname for editing in the nano text editor.
  11. less – View file content page-by-page.
    • Syntax: less [file]
    • Example: less /var/log/syslog
    • Details: Displays the content of syslog file in a scrollable format.
  12. head – Display the first lines of a file.
    • Syntax: head [options] [file]
    • Example: head -n 10 file.txt
    • Details: Shows the first 10 lines of file.txt.
  13. tail – Display the last lines of a file.
    • Syntax: tail [options] [file]
    • Example: tail -f /var/log/syslog
    • Details: Follows the last lines of syslog in real-time.
  14. find – Search for files in a directory hierarchy.
    • Syntax: find [directory] [options] [expression]
    • Example: find / -name "*.conf"
    • Details: Searches for all .conf files starting from the root directory.
  15. grep – Search for text patterns.
    • Syntax: grep [options] pattern [file]
    • Example: grep "error" /var/log/syslog
    • Details: Searches for the word “error” in syslog.
  16. ln – Create hard and symbolic links.
    • Syntax: ln [options] [target] [link]
    • Example: ln -s /var/www/html /var/www/html_link
    • Details: Creates a symbolic link named html_link pointing to /var/www/html.

Permissions and Ownership

  1. chmod – Change file modes or Access Control Lists.
    • Syntax: chmod [options] mode [file]
    • Example: chmod 755 script.sh
    • Details: Sets read, write, and execute permissions for the owner, and read and execute for others.
  2. chown – Change file owner and group.
    • Syntax: chown [owner]:[group] [file]
    • Example: chown user:group file.txt
    • Details: Changes ownership of file.txt to user and group to group.
  3. chgrp – Change group ownership.
    • Syntax: chgrp [group] [file]
    • Example: chgrp www-data index.html
    • Details: Changes the group ownership of index.html to www-data.

System Information and Monitoring

  1. df – Display disk space usage.
    • Syntax: df [options]
    • Example: df -h
    • Details: Displays disk space usage in a human-readable format.
  2. du – Estimate file space usage.
    • Syntax: du [options] [directory]
    • Example: du -sh /var
    • Details: Displays the disk usage of the /var directory.
  3. free – Display memory usage.
    • Syntax: free [options]
    • Example: free -m
    • Details: Displays memory usage in megabytes.
  4. top – Display Linux tasks.
    • Syntax: top
    • Example: top
    • Details: Shows real-time CPU and memory usage.
  5. htop – Interactive process viewer (better version of top).
    • Syntax: htop
    • Example: htop
    • Details: Displays an interactive and improved interface for viewing system processes.
  6. ps – Report a snapshot of current processes.
    • Syntax: ps [options]
    • Example: ps aux
    • Details: Lists all running processes on the system.
  7. uptime – Show how long the system has been running.
    • Syntax: uptime
    • Example: uptime
    • Details: Displays system uptime, number of users, and average system load.
  8. uname – Print system information.
    • Syntax: uname [options]
    • Example: uname -a
    • Details: Displays all system information including kernel name, version, and architecture.
  9. whoami – Print the current user.
    • Syntax: whoami
    • Example: whoami
    • Details: Displays the name of the current user.
  10. id – Print user and group information.
    • Syntax: id [username]
    • Example: id user
    • Details: Displays user and group IDs for the specified user.
  11. kill – Send a signal to a process.
    • Syntax: kill [signal] PID
    • Example: kill -9 1234
    • Details: Kills the process with the specified PID forcefully.

Package Management with apt

  1. apt-get update – Update package index.
    • Syntax: sudo apt-get update
    • Example: sudo apt-get update
    • Details: Refreshes the package lists for upgrades and new installations.
  2. apt-get upgrade – Upgrade all installed packages.
    • Syntax: sudo apt-get upgrade
    • Example: sudo apt-get upgrade
    • Details: Upgrades all installed packages to their latest versions.
  3. apt-get install – Install a new package.
    • Syntax: sudo apt-get install [package]
    • Example: sudo apt-get install nginx
    • Details: Installs the nginx package.
  4. apt-get remove – Remove a package.
    • Syntax: sudo apt-get remove [package]
    • Example: sudo apt-get remove apache2
    • Details: Removes the apache2 package.
  5. apt-get autoremove – Remove unused packages.
    • Syntax: sudo apt-get autoremove
    • Example: sudo apt-get autoremove
    • Details: Removes packages that were automatically installed and are no longer needed.

Network Management

  1. ifconfig – Display network configuration.
    • Syntax: ifconfig [interface]
    • Example: ifconfig eth0
    • Details: Displays the network settings for the eth0 interface.
  2. ping – Send ICMP echo requests to test connectivity.
    • Syntax: ping [host]
    • Example: ping google.com
    • Details: Sends ICMP echo requests to google.com to check connectivity.
  3. curl – Transfer data from or to a server.
    • Syntax: curl [options] [URL]
    • Example: curl https://linuxcloudservers.com
    • Details: Fetches content from linuxcloudservers.com.
  4. wget – Download files from the web.
    • Syntax: wget [options] [URL]
    • Example: wget https://linuxcloudservers.com/download/file.zip
    • Details: Downloads file.zip from the given URL.
  5. ssh – Connect to a remote server securely.
    • Syntax: ssh [user]@[host]
    • Example: ssh [email protected]
    • Details: Connects to the remote server linuxcloudservers.com via SSH.
  6. scp – Securely copy files between hosts.
    • Syntax: scp [source] [destination]
    • Example: scp file.txt [email protected]:/tmp/
    • Details: Copies file.txt to /tmp/ on the remote server linuxcloudservers.com.

Compression and Archiving

  1. gzip – Compress files.
    • Syntax: gzip [file]
    • Example: gzip file.txt
    • Details: Compresses file.txt into file.txt.gz.
  2. gunzip – Decompress .gz files.
    • Syntax: gunzip [file]
    • Example: gunzip file.txt.gz
    • Details: Decompresses file.txt.gz.
  3. tar – Archive multiple files.
    • Syntax: tar [options] [archive-file] [file/directory]
    • Example: tar -czvf backup.tar.gz /var/www/html
    • Details: Creates a compressed archive backup.tar.gz of the /var/www/html directory.

Users and Permissions

  1. adduser – Add a new user.
    • Syntax: sudo adduser [username]
    • Example: sudo adduser john
    • Details: Creates a new user named john.
  2. deluser – Remove a user.
    • Syntax: sudo deluser [username]
    • Example: sudo deluser john
    • Details: Deletes the user john.
  3. passwd – Change user password.
    • Syntax: passwd [username]
    • Example: passwd john
    • Details: Changes the password for the user john.

Scheduling and Jobs

  1. crontab – Schedule periodic jobs.
    • Syntax: crontab [options]
    • Example: crontab -e
    • Details: Edits the crontab file to add, remove, or modify scheduled jobs.
  2. at – Schedule a one-time job.
    • Syntax: at [time]
    • Example: echo "backup.sh" | at 02:00
    • Details: Schedules backup.sh to run at 2:00 AM.

System Shutdown and Reboot

  1. shutdown – Bring the system down.
    • Syntax: shutdown [options] [time]
    • Example: sudo shutdown -h now
    • Details: Immediately shuts down the system (-h for halt).

These commands provide a comprehensive toolkit for navigating and managing an Ubuntu system effectively. Whether you are working on file operations, system monitoring, networking, or scheduling tasks, these commands will come in handy.

Related articles

Create a Project in Azure DevOps-Basic Process in 3 steps

Create a Project in Azure DevOps-Basic Process Introduction Azure DevOps is a comprehensive toolset that supports the full software development...

An Ultimate Guide of How to Manage Linux Systemd Services With Systemctl Command

An Ultimate Guide of How to Manage Linux Systemd Services With Systemctl Command Systemd is the default service manager...

Platform as a Service (PaaS)

Platform as a Service (PaaS) Platform as a Service (PaaS) is a cloud computing model that provides a comprehensive...

How to do Messaging with Azure Web PubSub

How to do Messaging with Azure Web PubSub Introduction Azure Web PubSub is a service that provides real-time messaging using...