30 Basic Commands for Ubuntu Server

30 Basic Commands for Ubuntu Server

Ubuntu Server is a popular choice for running web services, databases, and other server-based applications. Its stability, security, and extensive community support make it an ideal platform for both beginners and experienced users. However, getting started with Ubuntu Server can be daunting, especially if you’re unfamiliar with the command line interface (CLI). This guide will walk you through 30 basic commands that every Ubuntu Server user should know, providing detailed explanations and practical examples to help you master your server environment.

1. sudo

sudo allows a permitted user to execute a command as the superuser or another user. It’s vital for performing administrative tasks.

Example:

sudo apt update

This command updates the package lists for upgrades and new packages.

2. apt-get

apt-get is a package management command-line tool. It’s used to install, update, and remove software.

Example:

sudo apt-get install nginx

This installs the Nginx web server on your Ubuntu Server.

3. cd

cd stands for “change directory.” It allows you to navigate between directories.

Example:

cd /var/www/html

This command takes you to the directory where website files are usually stored.

4. ls

ls lists the files and directories within the current directory. It’s one of the most commonly used commands.

Example:

ls -l

This shows a detailed list, including file permissions, sizes, and modification dates.

5. pwd

pwd stands for “print working directory.” It displays the full path of the current directory.

Example:

pwd

This command helps you confirm your location within the directory structure.

6. mkdir

mkdir is used to create a new directory. It’s essential for organizing files on your server.

Example:

mkdir my_new_directory

This creates a directory named my_new_directory in the current path.

7. rm

rm deletes files and directories. Be careful with this command, as it removes data permanently.

Example:

rm myfile.txt

This deletes the file named myfile.txt.

8. cp

cp copies files or directories from one location to another.

Example:

cp source.txt destination.txt

This command copies source.txt to destination.txt.

9. mv

mv moves files or directories and can also be used to rename them.

Example:

mv oldname.txt newname.txt

This renames oldname.txt to newname.txt.

10. cat

cat is used to display the contents of a file. It can also concatenate multiple files.

Example:

cat myfile.txt

This shows the contents of myfile.txt on the screen.

11. nano

nano is a simple, command-line text editor that’s easy to use for editing files.

Example:

sudo nano /etc/hosts

This opens the hosts file for editing with nano.

12. vi

vi is another text editor, more powerful but with a steeper learning curve compared to nano.

Example:

vi /etc/hosts

This command opens the hosts file in vi for editing.

13. grep

grep searches for patterns within files. It’s powerful for finding specific information quickly.

Example:

grep "error" /var/log/syslog

This searches for the word “error” in the system log.

14. find

find searches for files and directories based on various criteria like name, size, or modification date.

Example:

find /var/www -name "*.html"

This command searches for all .html files in the /var/www directory.

15. top

top provides a real-time view of running processes and their resource usage. It’s useful for monitoring server performance.

Example:

top

This command shows the top processes using the most CPU and memory.

16. ps

ps displays currently running processes. It’s similar to top but outputs the information as a list.

Example:

ps aux

This lists all running processes with detailed information.

17. kill

kill terminates a process using its process ID (PID).

Example:

kill 1234

This command kills the process with PID 1234.

18. df

df reports the disk space usage of your file systems. It’s vital for managing storage.

Example:

df -h

This command shows disk usage in a human-readable format.

19. du

du estimates the disk space used by files and directories.

Example:

du -sh /var/www

This command shows the size of the /var/www directory.

20. chmod

chmod changes the permissions of files or directories. It’s crucial for managing access rights.

Example:

chmod 755 myscript.sh

This command sets the permissions of myscript.sh to 755, allowing the owner to read, write, and execute it.

21. chown

chown changes the ownership of files or directories. It assigns the owner and group.

Example:

sudo chown user:usergroup myfile.txt

This sets user as the owner and usergroup as the group for myfile.txt.

22. scp

scp securely copies files between servers using SSH. It’s useful for transferring data securely.

Example:

scp myfile.txt user@remote_server:/path/to/destination

This copies myfile.txt to a remote server at the specified path.

23. wget

wget downloads files from the web. It supports downloading files in the background and resuming interrupted downloads.

Example:

wget http://example.com/file.zip

This downloads file.zip from example.com.

24. curl

curl transfers data from or to a server. It supports various protocols, including HTTP, HTTPS, and FTP.

Example:

curl -O http://example.com/file.zip

This downloads file.zip from example.com.

25. tar

tar is used to compress and extract files from archives. It’s essential for managing backups and large file collections.

Example:

tar -czvf archive.tar.gz /path/to/directory

This command creates a compressed archive of the specified directory.

26. zip and unzip

zip compresses files into a .zip archive, while unzip extracts files from a .zip archive.

Example:

zip -r archive.zip /path/to/directory

This creates a .zip archive of the specified directory.

Example:

unzip archive.zip

This extracts the contents of archive.zip.

27. service

service manages services on your Ubuntu Server. It allows you to start, stop, or restart services.

Example:

sudo service nginx restart

This command restarts the Nginx service.

28. systemctl

systemctl is a more modern tool for managing services and system states on Ubuntu. It offers more functionality than service.

Example:

sudo systemctl status nginx

This checks the status of the Nginx service.

29. reboot

reboot restarts the server. It’s often used after applying updates or changing system configurations.

Example:

sudo reboot

This command restarts your server.

30. shutdown

shutdown powers off the server safely. It can also be used to schedule a shutdown.

Example:

sudo shutdown now

This shuts down the server immediately.


Conclusion

Mastering these 30 basic Ubuntu Server commands will significantly enhance your ability to manage your server efficiently. Each command has a specific role in system administration, from installing software and managing files to monitoring system performance and securing your server. Whether you’re just starting or looking to solidify your knowledge, these commands provide a strong foundation for working in a Linux server environment.

By understanding these commands, you’ll be better equipped to handle daily tasks, troubleshoot issues, and optimize your server’s performance. As you grow more comfortable with these basics, you can explore more advanced commands and scripts to further enhance your server management skills.

To make the most of your Ubuntu Server, practice these commands regularly. Experiment with them in a test environment before applying them in a production setting. Over time, you’ll find that managing your server from the command line becomes second nature.

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: