Essential Linux Terminal Commands: Your First Steps in Linux
Have You Ever Faced a Black Screen Full of Text?

Essential Linux Terminal Commands: Your First Steps in Linux
Have You Ever Faced a Black Screen Full of Text?
At first glance, the Linux terminal might look intimidating. However, once you know which commands to use and when to use them, it becomes one of the most powerful tools in your arsenal for working with systems. This article is a simple yet practical guide to mastering basic Linux commands. Even if you’re a complete beginner, you’ll find it easy to follow and get your tasks done efficiently. From managing files and folders to exploring networks and services, this guide covers everything you need to get started. So, let’s dive into this fascinating and powerful world together!
Topics:
Navigating Files and Directories in Linux
File and Directory Management in Linux
Displaying File Contents in Linux
Managing Users and Permissions in Linux
Managing Processes in Linux
Installing and Managing Packages in Linux
Network and Connections in Linux
Service Management in Linux
Navigating Files and Directories in Linux
The first step in mastering Linux is understanding how to navigate its file and directory structure. Everything in Linux is organized into directories, from system files to your personal data. With just a few commands, you can move like a pro through directories, find files, and switch paths effortlessly. Let’s explore the essential commands for navigation, ensuring no file or folder remains out of your reach.
1. pwd: Display Current Directory
The pwd command shows your current directory path. This is especially useful when you need to confirm where you are in the system.
pwd
# Output example:
# /home/mehdi/projects/
2. cd: Change Directory
The cd command allows you to navigate to a specific directory. You can return to your home directory with cd ~, or go back to the previous directory using cd -.
# Navigate to a specific directory
cd /home/mehdi/projects/
# Return to the previous directory
cd -
# Go to the home directory
cd ~
3. ls: List Directory Contents
Use ls to view the contents of a directory. Add the -a flag to display hidden files as well.
# Display contents of the current directory
ls
# Show all files, including hidden ones
ls -a
4. pushd and popd: Temporary Directory Navigation
The pushd command saves your current directory and moves you to a new one, while popd takes you back to the last saved directory.
# Save the current directory and move to /home/mehdi/projects/
pushd /home/mehdi/projects/
# Return to the previously saved directory
popd
5. find: Search Files and Directories
The find command is incredibly versatile, letting you search for files based on criteria such as name, size, type, or modification time.
# Find all .sh files in a directory
find /path/to/directory -name "*.sh"
# Search for a specific file by name
find /path/to/directory -name "document.txt"
# Perform a case-insensitive search
find /path/to/directory -iname "document.txt"
# Locate all log files in /var/log
find /var/log -name "*.log"
# Find files modified in the last 7 days
find /path/to/directory -mtime -7
# Search for files larger than 100MB
find /path/to/directory -size +100M
# List directories only
find /path/to/directory -type d
# Remove all temporary files
find /path/to/directory -name "*.tmp" -type f -delete
# Search for files with 777 permissions
find /path/to/directory -perm 777
6. locate: Quick File Finder
The locate command searches files using a pre-built database, making it faster than find. Remember to update the database regularly using updatedb.
# Locate a specific file
locate config.txt
# Find all configuration files
locate "*.conf"
# Update the locate database
updatedb
7. tree: Visual Directory Structure
The tree command displays directories in a tree-like structure, making it easier to understand the hierarchy.
# Display the tree structure of a directory
tree /path/to/directory
# Show directories only
tree -d
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
File and Directory Management in Linux
Managing files and directories is a fundamental skill for any Linux user. Whether you’re creating, deleting, copying, or moving them, mastering these tasks will make your system organized and efficient. In this section, we’ll cover essential commands to manage files and directories effortlessly. With these, file management will feel intuitive, helping you quickly find or organize anything you need.
1. mkdir Command
The mkdir command, short for make directory, is used to create one or more directories.
# Create a single directory named 'new_folder'
mkdir new_folder
# Create multiple directories in one go
mkdir folder1 folder2 folder3
# Create nested directories, ensuring parent directories exist
mkdir -p parent_folder/child_folder/grandchild_folder
2. rmdir Command
Use the rmdir command to delete empty directories. If a directory contains files or subdirectories, it cannot be removed with rmdir.
# Remove an empty directory named 'empty_folder'
rmdir empty_folder
3. rm Command
The rm command is a powerful tool for deleting files and directories. Be cautious when using it, as it permanently deletes items without moving them to a trash bin.
# Delete a single file named 'file.txt'
rm file.txt
# Recursively delete a directory and all its contents
rm -r folder_name
# Force delete a file without confirmation
rm -f file.txt
4. cp Command
The cp command is used for copying files and directories.
# Copy a file to a specified directory
cp file.txt /path/to/destination/
# Recursively copy a directory and its contents to a destination
cp -r folder_name /path/to/destination/
5. mv Command
The mv command is used for moving files or directories, as well as renaming them.
# Rename a file from 'old_name.txt' to 'new_name.txt'
mv old_name.txt new_name.txt
# Move a file to a specified directory
mv file.txt /path/to/destination/
6. touch Command
The touch command creates a new empty file or updates the last access time of an existing file.
# Create a new empty file named 'newfile.txt'
touch newfile.txt
# Update the last access time of an existing file
touch existingfile.txt
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Displaying File Contents in Linux
Sometimes, you need to see what’s inside a file without editing or opening it directly. Linux has several handy commands to help you quickly view file contents, from reading simple text files to checking through large log files line by line. With these commands, you can save time and access file contents efficiently.
1. cat Command
The cat command is one of the simplest and most popular tools for displaying file contents. It allows you to view the content of one or more text files easily. This command can also be used to concatenate files or create new ones.
# Display the contents of a file
cat example.txt
# Combine the contents of two files into a new file
cat file1.txt file2.txt > combined.txt
Note: If the file is very large, its content will quickly scroll through the terminal, which might make it hard to read. For such cases, you may want to use other commands that offer more control.
2. less Command
The less command is an excellent tool for viewing large files. Unlike cat, which displays the entire file at once, less allows you to scroll through the file using keyboard keys, making it easier to read.
# View the contents of a large file interactively
less largefile.txt
Useful Keys in less:
Space: Move to the next page.b: Go to the previous page./: Search within the file.q: Exitlessand return to the terminal.
3. more Command
The more command is designed to display file contents one page at a time. It's similar to less but lacks some advanced navigation features.
# View the contents of a file page by page
more example.txt
While more is helpful for quick views of large files, its limited functionality often makes less a better choice when working with large files.
4. head Command
The head command lets you view only the beginning of a file. By default, it shows the first 10 lines, but you can change this number using options
# Display the first 10 lines of a file
head example.txt
# Display the first 20 lines of a file
head -n 20 example.txt
5. tail Command
The tail command works opposite to head, showing the end of a file. By default, it displays the last 10 lines. You can use the -f option to follow a file in real-time, making it particularly useful for viewing log files.
# Display the last 10 lines of a file
tail example.txt
# Monitor a file for real-time updates
tail -f logfile.log
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Managing Users and Permissions in Linux
One of the most important tasks in Linux administration is managing users and permissions. With proper user management, you can determine who has access to which files and services, ensuring the security of your system. Linux provides powerful tools for creating, deleting, and configuring user access levels, allowing you to precisely control permissions and ensure that only authorized individuals can access sensitive information.
1. adduser Command
This command is used to create new users on the system. With adduser, you can create a new user with the desired specifications.
# Creates a new user named "newuser"
adduser newuser
2. passwd Command
This command is used to change the password of users. You can use this command to set or change a specific user’s password.
# Sets the password for the user "newuser."
passwd newuser
3. userdel Command
This command is used to delete users from the system. You can delete a user that is no longer needed.
# Deletes the user "newuser" from the system but leaves their files.
userdel newuser
# Deletes the user "newuser" along with their files in their home directory.
userdel -r newuser
4. groupadd Command
This command is used to create new groups on the system. Groups allow you to manage multiple users at once and easily configure permissions.
# Creates a new group named "developers."
groupadd developers
5. usermod Command
This command is used to modify the settings of existing users. You can use usermod to add a user to different groups.
# Adds the user "newuser" to the "developers" group.
usermod -aG developers newuser
6. chmod Command
This command is used to manage file and directory access permissions. With chmod, you can specify which users or groups have access to a particular file.
# Sets the permissions for the file "example.txt" so that the owner can read and modify it, while others can only read it.
chmod 644 example.txt
Access codes are as follows:
7: Read, write, and execute (rwx)6: Read and write (rw-)5: Read and execute (r-x)4: Read only (r--)
7. chown Command
This command is used to change the ownership of files and directories. You can use chown to change the owner of a file or directory.
# Changes the owner of the file "example.txt" to "newuser."
chown newuser example.txt
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Managing Processes in Linux
In Linux, every activity running on the system is considered a “process.” These processes can include active programs, services, and even commands that are running. Sometimes, it is necessary to monitor the performance of processes, stop some of them, or adjust priorities to ensure the system works efficiently. Process management in Linux allows you to easily view running processes, move them to the background or foreground, and stop troublesome processes when needed.
1. ps Command
The ps command allows you to view a list of running processes. This list shows information such as the process's unique ID (PID), the user running the process, the process's status, and additional details.
# Displays a small list of current running processes.
ps
# Displays a list of processes running by the specified user.
ps -u yourusername
2. top Command
top is an interactive tool that allows you to view running processes in real-time. It shows information such as CPU usage, RAM usage, and the PID of processes in real-time.
# Displays a live view of running processes with detailed information.
top
3. htop Command
htop is an enhanced, more user-friendly version of top that offers a more interactive, colorful interface for managing and viewing processes. It is not typically installed by default on most distributions and needs to be installed.
# Install htop on Red Hat-based systems.
dnf install htop
# Install htop on Debian-based systems.
apt install htop
# Run the htop command.
htop
4. kill Command
The kill command is used to stop a process by its PID (Process ID). For example, if a program freezes or slows down the system, you can use kill to terminate it by providing its PID.
# Stops the process with PID 1234.
kill 1234
Note: If a process does not stop with the kill command, you can use a stronger signal:
# Forcefully stops the process with PID 1234 using signal 9.
kill -9 1234
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Installing and Managing Packages in Linux
One of the exciting aspects of Linux is how you can install or remove any software you need with just a few simple commands. Every Linux distribution has its own package management system. Packages are essentially the software and tools that your system needs or that you need for your tasks. Depending on whether your distribution is from the Debian or Red Hat family, you’ll use different tools to install, remove, and manage packages.
1. Installing Packages
Before installing a new package, it’s always a good idea to update the system repositories to ensure you have access to the latest versions.
On Debian-based systems (like Ubuntu and Debian)
If you’re using Ubuntu or Debian, you’ll use the apt command to manage packages. First, you need to update the package list, and then specify the package you want to install:
# Updates the list of available repositories to make sure you have access to the latest versions
apt update
# Installs the 'net-tools' package
apt install net-tools
On Red Hat-based systems (like CentOS and Rocky Linux)
On Red Hat-based systems, you’ll use dnf or yum. As with Ubuntu, it's a good practice to update the package list before installing anything:
# Checks for available updates to the system's repositories
dnf check-update
# Updates the package list to get the latest available versions
dnf update
# Installs the 'net-tools' package
dnf install net-tools
2. Removing Packages
Sometimes you may no longer need a particular piece of software, and you want to free up system space. You can use these commands to remove a package:
# Debian-based systems:
# Removes the 'net-tools' package from the system
apt remove net-tools
##################################################
# Red Hat-based systems:
# Removes the 'net-tools' package from the system
dnf remove net-tools
3. Searching for Packages
If you’re looking for a specific software but aren’t sure of the exact package name, you can search for it among all available packages using a simple command:
# Debian-based systems:
# Searches for a package by name in the available repositories
apt search package_name
################################################################
# Red Hat-based systems:
# Searches for a package by name in the available repositories
dnf search package_name
4. Displaying Package Information
Sometimes, you might want more details about a package, such as its version or a description. To do this, you can use the following commands:
# Debian-based systems:
# Displays detailed information about the 'package_name' including version and description
apt show package_name
###########################################################################################
# Red Hat-based systems:
# Displays detailed information about the 'package_name' including version and description
dnf info package_name
5. Managing Package Cache
Every time you install or update a package, the system keeps some temporary files, or cache. You can clean this cache to free up more space on your system.
# Cleaning cache on Debian-based systems:
# Cleans the local repository of retrieved package files
apt clean
# Removes packages that were automatically installed and are no longer needed
apt autoremove
##############################################################################
# Cleaning cache on Red Hat-based systems:
# Cleans all cached data from the system
dnf clean all
# Removes packages that were installed as dependencies but are no longer needed
dnf autoremove
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Network and Connections (Managing Network Communications in Linux)
When it comes to networking, Linux provides a variety of commands that help us understand how we are connected to the internet or how we communicate with other devices. Let’s take a look at some of the most important commands for managing networks and connections.
1. Displaying Network Settings with ip
The ip command is one of the main tools for managing networks. It allows you to view IP addresses, interface statuses, and a lot of other network information. This command tells you which IP addresses are active on your system, the status of interfaces (whether active or inactive), and even the MAC address of each interface. The information you get with this command helps you understand which interfaces are working.
# Displays IP addresses and the status of network interfaces
ip a
# Displays IP addresses in a simpler format
ip addr show
# Adds a new IP address to the eth0 interface
ip addr add 192.168.1.10/24 dev eth0
2. Checking Network Connectivity with ping
The ping command is one of the simplest and most useful tools to check connectivity to a server or device. It sends ICMP packets to the destination server and waits for a reply. By checking the response time, you can also determine how fast the connection is.
# Pings the google.com server to check connectivity
ping google.com
# Sends a specific number (4) of pings to the google.com server
ping -c 4 google.com
Note: The second example sends only four packets to the destination and stops afterward. This helps you get a quick result.
3. Displaying the Routing Table with route
The route command shows how your network traffic is routed through various paths. It helps you understand how data is reaching its destination. This command displays network addresses and gateways. With this information, you can determine if any changes are needed in your routing setup.
# Displays the routing table for your system
route -n
4. Displaying Connections and Ports with netstat and ss
Both netstat and ss are useful commands that show the status of connections and open ports on your system. With netstat, you can check all active connections and which ports are being used. ss performs the same function but is faster and provides more detailed information. Whenever you want to see what connections are open and which programs are using ports, these commands are handy.
# Displays active connections and open ports using netstat
netstat -tuln
# Displays active connections and open ports using ss
ss -tuln
5. Finding Your Public IP Address with curl
If you want to find out your public IP address, you can use the curl command. This allows you to easily find your IP without visiting websites.
# Displays your public IP address using curl
curl ifconfig.me
6. Checking Connections with traceroute
If you want to track the path data takes from your system to another server, use the traceroute command. It tells you the intermediate steps the data passes through and the time taken to reach each host along the way. This information can help you identify network problems more effectively.
# Traces the path data takes to reach google.com
traceroute google.com
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Service Management in Linux
Managing services is one of the most important tasks for a system administrator. You need to know which services are running on your system and how to control them. In this section, we will introduce the main commands for service management.
1. Checking the Status of Services with systemctl
The systemctl command is the main tool for managing services in modern Linux systems (like RHEL, Ubuntu, etc.). With this command, you can check the status of services and start or stop them.
# Checks the status of a service
systemctl status service_name
Replace service_name with the name of the service you're interested in to see its status. This command will provide information about whether the service is running or stopped.
2. Starting and Stopping Services with systemctl
You can use the following commands to start and stop services as needed.
# Starts a service
systemctl start service_name
# Stops a service
systemctl stop service_name
3. Enabling and Disabling Services with systemctl
You can configure services to automatically start at boot or disable them from the startup list.
# Enables a service to start at boot
systemctl enable service_name
# Disables a service from starting at boot
systemctl disable service_name
4. Viewing the List of Services with systemctl
You can view a list of all active and inactive services with the following command. This will show you which services are currently running.
# Lists all services with their status
systemctl list-units --type=service
5. Restarting Services with systemctl
Sometimes you need to restart a service, for example, when you make changes to its configuration. Restarting the service will apply the changes.
# Restarts a service
systemctl restart service_name
6. Viewing Service Logs with journalctl
You can use journalctl to view logs related to services. This information can help you troubleshoot issues with services.
# Views logs for a specific service
journalctl -u service_name
7. Checking Running Services with ps
You can use the ps command to check the running services and processes on your system.
# Views all running processes
ps aux
Linux Power is in Your Hands
Now that you’re familiar with basic Linux commands and how to manage files, folders, services, and networks, you can easily function as a successful system administrator. With its power and flexibility, Linux can help you manage complex systems with ease.
Remember, every command you’ve learned is just a gateway to the broader world of Linux. With practice and experience, you’ll be able to strengthen your skills and become a true expert in the field.
메타데이터
- post_id
- 7e6bfc0d73f9
- slug
- have-you-ever-faced-a-black-screen-full-of-text-7e6bfc0d73f9
- url
- https://medium.com/@mahdifathi1001/have-you-ever-faced-a-black-screen-full-of-text-7e6bfc0d73f9
- canonical_url
- https://medium.com/@mahdifathi1001/have-you-ever-faced-a-black-screen-full-of-text-7e6bfc0d73f9
- author_url
- https://medium.com/@mahdifathi1001
- status
- ok
- fetched_at
- 2026-07-21 16:52:50