Linux Terminal for Beginners: The Most Important Commands for Your Server
Learn the most important Linux terminal commands for your server. A beginner-friendly guide to navigating, managing files, viewing system information, and more.
Table of Contents
- Establishing a Connection
- 1. Navigating the File System: Where am I and where do I want to go?
- 2. Creating and Managing Files and Folders
- 3. Viewing and Editing Text Files
- 4. Understanding and Changing Permissions
- 5. Viewing and Killing Processes
- 6. Network Basics
- 7. System Information and Disk Space
- 8. Installing and Managing Software (Package Manager)
- 9. Powerful Helpers: sudo, Pipes, and Redirection
- Important Tips for Beginners
- Conclusion
If you run your own Linux server, whether it’s a VPS (Virtual Private Server) or a home server, you usually can’t avoid the terminal. At first, it might seem a bit intimidating – a black box with a blinking cursor waiting for your input. But don’t worry, it’s not as complicated as it looks! The terminal, also called the command line or shell, is an incredibly powerful tool to control your server directly and efficiently.
Today, I’ll show you the most important Linux commands that you, as a self-hoster, need to know to navigate your server, manage files, and perform basic tasks.
Establishing a Connection
Before we start, you first need to connect to your server. This is usually done via SSH (Secure Shell). You’ll need:
- The IP address of your server.
- Your username on the server.
- Your password or (better) an SSH key.
On Windows, you can use tools like PuTTY or the integrated OpenSSH in Terminal/PowerShell in Windows 10/11. On macOS and Linux, the SSH client is available directly in the terminal.
ssh YOUR_USERNAME@YOUR_SERVER_IP
Enter your password when prompted, and you’re in!
1. Navigating the File System: Where am I and where do I want to go?
First things first: How do we move around in the file system? Think of the file system as a system of folders (directories) and files.
-
pwd(Print Working Directory): Where am I currently? This command shows you the full path of the directory you are currently in.pwdExample output:
/home/YOUR_USERNAME -
ls(List): What’s in here? Lists the content of the current directory – i.e., which files and folders are located here.lslscan be supplemented with additional parameters (options). Useful options include:ls -l: Shows a detailed list with permissions, owner, size, and modification date. Thelstands for “long”.ls -lh: Like-l, but with “human-readable” file sizes (e.g., “1.5K” instead of “1536”).ls -a: Also lists hidden files and folders (those starting with a dot, e.g.,.bashrc). Here you’ll also see.(current directory) and..(parent directory).
You can also give
lsa path to display the content of another folder:ls /var/log # Shows the content of /var/log ls / # Shows the content of the root directory -
Help!
man(Manual): You don’t have to memorize all commands and options! For common commands, there are built-in manuals, the “man pages”.man lsThis shows you everything about the
lscommand. You navigate with the arrow keys, and press Q to exit the view. -
cd(Change Directory): Change directory Withcd, you change the directory.cd /var/www/html # Changes to the directory /var/www/html cd .. # Moves one level up (to the parent directory) cd # Without arguments, changes back to your home directory cd ~ # Also to the home directory cd - # Changes to the previous directoryYour terminal often shows you which directory you are currently in (e.g.,
YOUR_USERNAME@SERVERNAME:~/docker$). The tilde (~) stands for your home directory. -
Tab Completion: Your Best Friend! An important tip: If you start typing a path or file name and then press the Tab key, the shell tries to complete the name. If you press Tab twice, possible completions are displayed. This saves an enormous amount of time and avoids typos!
cd AdGu # Type "AdGu" and press Tab -> becomes "cd AdGuardHome/" (if unique) -
clear: Clear screen Clears the current screen content of the terminal.
2. Creating and Managing Files and Folders
Now that we can navigate, we also want to create and modify things.
-
mkdir(Make Directory): Create new foldersmkdir my_projectThis creates a folder named
my_projectin the current directory. If you want to create a whole chain of folders that don’t exist yet (e.g.,my_project/assets/images), you can do this with the-p(parents) option:mkdir -p my_project/assets/images -
touch: Create empty files or update timestampstouch important_note.txtCreates an empty file named
important_note.txt. If the file already exists, its timestamp is updated. -
cp(Copy): Copy files and folders The command iscp SOURCE DESTINATION.cp important_note.txt backup_note.txt # Copies the file cp important_note.txt my_project/ # Copies the file into the my_project folderTo copy entire folders with content, you need the
-r(recursive) option:cp -r my_project /tmp/project_backup -
mv(Move): Move or rename files and folders Similar tocp, but the source is removed.mv important_note.txt just_a_note.txt # Renames the file mv just_a_note.txt my_project/ # Moves the file into the folder mv my_project/important_note_2.txt . # Moves file from my_project to the current dir (.) -
rm(Remove): Delete files and folders Be careful withrm! Deleted files are usually gone for good.rm just_a_note.txt # Deletes the fileTo delete a folder, you again need the
-r(recursive) option. If the folder is not empty, a prompt will often appear.rm -r my_project # Deletes the my_project folder and its contentSometimes, prompts appear during deletion. These can be suppressed with
-f(force). EXTREMELY DANGEROUS:rm -rf PATHrecursively deletes everything in the specified path without prompting. A wrongrm -rf /can delete your entire system! Use-fonly when absolutely necessary and you know exactly what you are doing.
3. Viewing and Editing Text Files
To view and edit configuration files or scripts, you need a text editor.
-
cat(Concatenate): Display content of a file Displays the entire content of a file directly in the terminal. Practical for short files.cat testfile.txt -
less: Display content of a file page by page For longer files,lessis better. You can scroll with the arrow keys or Page Up/Down. With / you can search for text, with N jump to the next match. Press Q to exitless.less /var/log/syslog -
nano: Simple text editornanois a beginner-friendly editor that runs in the terminal. The most important commands are displayed at the bottom of the screen (e.g., Ctrl+O to save, Ctrl+X to exit).nano my_config.conf -
vim(orvi): Powerful, but takes getting used tovimis pre-installed on almost every Linux system. It has a steeper learning curve but is extremely efficient once mastered.vim testfile.txtThe most important
vimbasics:- Press I to switch to Insert Mode (
INSERT) and type text. - Press Esc to exit Insert Mode and enter Command Mode.
- In Command Mode:
:wsaves the file (write).:qquits Vim (quit).:wqor:xsaves and quits.:q!quits without saving (discards changes).
- Press I to switch to Insert Mode (
4. Understanding and Changing Permissions
Every file and folder in Linux has permissions that define who can do what with it.
-
Displaying permissions with
ls -lAt the beginning of each line ofls -l, you’ll see something likedrwxr-xr-xor-rw-r--r--.- The first character:
dfor Directory,-for a regular file. - The next nine characters are in groups of three: Owner, Group, Others.
rstands for Read permission.wstands for Write permission.xstands for Execute permission (for folders, this means you can enter them). Example:drwxr-xr-xd: It’s a directory.rwx(Owner): The owner can read, write, and execute.r-x(Group): Members of the group can read and execute, but not write.r-x(Others): All others can also read and execute.
- The first character:
-
chmod(Change Mode): Change permissions You can change permissions symbolically or numerically.- Symbolically:
u(user/owner),g(group),o(others),a(all).+(add),-(remove),=(set exactly).
chmod u+x my_script.sh # Adds execute permission for the owner chmod g-w sensitive_file.txt # Removes write permission for the group chmod a+r important_info.txt # Gives read permission to all chmod go-rwx private_data # Removes all permissions for group and others - Numerically (Octal):
Each permission has a numerical value:
r=4,w=2,x=1. Add the values for the desired permissions.7(4+2+1) =rwx6(4+2+0) =rw-5(4+0+1) =r-x4(4+0+0) =r--The command ischmod OWNER_NUMBER GROUP_NUMBER OTHERS_NUMBER FILE/FOLDER.
chmod 755 my_script.sh # Owner: rwx, Group: r-x, Others: r-x chmod 600 private_keys # Owner: rw-, Group: ---, Others: ---
- Symbolically:
chmod Permissions Calculator
Owner
Group
Others
Octal:644
Symbolic:-rw-r--r--
Example: chmod 644 my_file.txt
ls -l Output: -rw-r--r-- 1 user group ... my_file.txt
chown(Change Owner): Change owner and group To change the owner and/or group of a file. Often requiressudo.sudo chown new_owner:new_group file.txt sudo chown YOUR_USERNAME:YOUR_USERNAME important_note.txt # Changes owner and group
5. Viewing and Killing Processes
Sometimes you need to see which programs (processes) are running on your server or kill a process that’s causing problems.
-
ps aux: Show all running processes Displays a detailed list of all processes. The output can be very long.ps aux # To search for a specific process (e.g., nginx): ps aux | grep nginx -
top: Dynamic process view Shows a continuously updating list of processes, sorted by CPU usage. Press Q to exittop. -
htop: More user-friendly alternative totophtopis colorful and offers more interaction options (e.g., select processes with arrow keys and sendkillwith F9). Often needs to be installed first:sudo apt install htop.htopPress Q (or F10) to exit
htop. -
kill: Kill processes If a process hangs, you can kill it withkilland its Process ID (PID – found withpsorhtop, for example).# Find the PID of htop, e.g., 62434 kill 62434By default,
killsends aTERMsignal (15), telling the process to terminate cleanly. If that doesn’t help, you can send aKILLsignal (9), which terminates the process immediately and “hard”:kill -9 PID_OF_THE_PROCESS # Use only in emergencies!
6. Network Basics
A few commands to check your network connection.
-
ip addr(orifconfigon older systems): Show network configuration Displays your network interfaces and their IP addresses. -
ping: Test reachability Tests if another host on the network or internet is reachable and measures the response time.ping google.comPress Ctrl+C to stop the ping.
-
curl: Transfer data from/to URLscurlis a versatile tool for transferring data with URLs. A simple application is downloading the HTML content of a webpage:curl https://deployn.deThis displays the HTML source code of the page in the terminal.
7. System Information and Disk Space
Important commands to monitor the state of your system.
-
df -h(Disk Free): Show disk space usage Displays the usage of your hard drive partitions in human-readable format (-h).df -h -
free -h: Show memory usage Displays the usage of your RAM and swap space. -
journalctl: View system logs (systemd) On modern systems withsystemd(like Ubuntu, Debian),journalctlis the central tool for viewing system logs.journalctl -f: Shows logs live (“follow”). Press Ctrl+C to stop.journalctl -u SERVICE_NAME: Shows logs for a specific service (e.g.,sshdornginx).journalctl -xe: Shows the latest log entries with additional explanations for errors.
-
dmesg(Driver Messages): Show kernel messages Useful for diagnosing hardware problems or issues during system startup.
8. Installing and Managing Software (Package Manager)
To install, update, or remove software, you use a package manager. On Debian-based systems like Ubuntu, this is apt.
-
sudo apt update: Update package lists Downloads the latest information about available packages from the servers (repositories). Should be run beforeupgradeorinstall. -
sudo apt upgrade: Upgrade installed packages Installs the latest versions of all packages already installed on your system. Confirm with Y when prompted. -
sudo apt install PACKAGENAME: Install a new packagesudo apt install htop tree mc # Installs htop, tree, and Midnight Commander -
sudo apt remove PACKAGENAME: Remove a package Uninstalls a package but often leaves configuration files behind. -
sudo apt purge PACKAGENAME: Completely remove a package Uninstalls a package including its configuration files. -
sudo apt autoremove: Remove no longer needed packages Removes dependencies that are no longer needed after uninstalling other packages. -
apt search SEARCH_TERM: Search for packages Searches the available packages for a specific term.
9. Powerful Helpers: sudo, Pipes, and Redirection
-
sudo(Superuser Do): Execute commands with root privileges Many system commands require administrator rights (root privileges).sudotemporarily prepends root privileges to these commands. You will be asked for your user password. -
|(Pipe): Chain outputs The pipe redirects the standard output of one command to the standard input of another command. Extremely useful!ps aux | grep sshd # Shows only process lines containing "sshd" ls -l /etc | less # Pipes the long list from /etc to `less` for scrolling journalctl -u nginx | grep "error" # Searches nginx logs for errors -
>(Redirection): Write output to a file (overwrites!) Redirects the output of a command to a file. If the file exists, it will be overwritten.ls -l > filelist.txt # Writes the output of ls -l to filelist.txt -
>>(Redirection): Append output to a file Redirects the output to a file. If the file exists, the new output will be appended to the end. If not, it will be created.echo "New log entry: $(date)" >> server.log # Appends a timestamp to server.log
Important Tips for Beginners
- Tab Completion: Your best friend! Saves typing and avoids errors.
manPages: Useman COMMANDto learn more about a command.history: Shows you a list of your most recently entered commands. With!NUMBERyou can re-execute a command from the history.- Ctrl+C: Cancels the currently running command.
- Ctrl+R: Searches backward through your command history.
- Small Steps: Especially at the beginning, try out commands and understand what they do before applying them to important data or system configurations.
- Test Server: If possible, play around on a test server or a virtual machine before making changes to a production system.
Conclusion
That was a lot of basics! The terminal is an incredibly versatile and efficient tool once you’ve understood the fundamentals.