Linux is a flexible operating system popular among users worldwide. Want to learn how to use Linux and navigate the command line efficiently? Let's dive in.
Linux terminal basics
The Linux Terminal is a text-based interface that enables users to interact with the operating system using command-line instructions. It provides the capability to:
- Configure the system
- Manage files and directories
- Execute scripts
- Run commands and more.
There are several methods to access the Linux terminal, each varying based on your system and preference:
- Through Application Search: Useful if the terminal shortcut isn't immediately visible. Typically, there's a search field in the taskbar or application menu. Type "terminal" or "command line" to locate the terminal application.
- Via the Graphical Interface: Many Linux distributions feature a button or shortcut on the desktop or in the application menu that initiates the Linux terminal. Simply click on it. Common names include "Konsole", "Terminal", and "XTerm".
- Using Keyboard Shortcuts: Some Linux versions provide shortcuts for swift terminal access. A common combination is pressing Ctrl + Alt + T simultaneously.
How to use the Linux terminal: gaining root access in Linux
Upon launching the terminal, you'll encounter a command prompt where you can input Linux commands and observe their results. While the Linux terminal typically operates under the current user's context, there are instances when you might need elevated privileges (root) to execute specific commands. To run commands with elevated privileges, utilize the
sudo command. Simply type
sudo [terminal_command_name] and press Enter. To validate this action, the system might prompt you for the password associated with an administrative account. In essence, the Linux Terminal is a robust tool for interacting with the OS. Familiarity with it not only deepens your understanding of the system's capabilities but also enables automation, system customization, and full control over your computer or server.
Basic principles of working in the Linux terminal
- Basic Commands: These are essential commands used to:
Create directories (
View the contents of directories (
Change the current directory (
Create files (
Move files (
Copy files (
Delete files and directories (
Display file contents (
- Create directories (
- Access Rights and Privileges: In Linux, both files and directories possess access rights, which specify who can read, write, or execute them. Certain tasks might necessitate administrator rights, for which the
sudocommand is employed.
- Command Line Interface (CLI): This is where users input textual commands to carry out various functions. With the Linux terminal, you can control processes, manage files and directories, and configure the system, among other tasks. To execute these commands, press the Enter key.
- Autocompletion and Command History: The Linux terminal offers an autocompletion feature, which enables the automatic filling out of commands after typing just a few initial characters, simplifying the input of lengthy or intricate commands. Furthermore, the terminal keeps a record of previously entered commands. The Up and Down arrow keys allow for easy navigation through this command history.
- Path Types - Absolute and Relative: A path indicates a file's or directory's location within the file system. While Linux employs absolute paths starting with '/', it also uses relative paths which describe a location concerning the present directory. For instance, /home/user/Documents is the absolute path to the "Documents" directory, whereas Documents/notes.txt is the relative path to the "notes.txt" file situated in the "Documents" folder.
- Command Parameters and Flags: These are supplementary components that can be added to a command in the terminal to modify its behavior or furnish extra information. For instance, the
-rflag in the
rmcommand signals the recursive removal of files and directories. Conversely, the
-lflag in the
lscommand shows directory contents as an exhaustive list.
Popular commands for system management in Linux: system commands
- Shutdown and Reboot: The
rebootcommands are employed to power down or restart the system, respectively. An example usage is
sudo shutdown -h now, which will immediately shut down the system.
- Systemctl: This command manages system services in Linux, providing the ability to start, stop, restart, and check the status of these services. For instance,
sudo systemctl start [service-name]will begin the specified service.
- Network Configuration: The
ifconfig(older but still used) and ip commands are essential for retrieving information about network interfaces and setting network parameters, such as the gateway, IP address, and subnet mask.
- Process Monitoring - PS: The
pscommand gives a snapshot of the current processes in the system, including their process identifiers (PIDs), resource usage, and other related data.
- Memory Overview - Free: The
freecommand provides insights into the system's memory usage. It presents details about RAM consumption, swap space usage, and total memory capacity.
- Real-Time System Monitoring - Top: The
topcommand delivers an interactive monitoring interface, showcasing real-time active processes, memory usage, CPU load, and other vital statistics.
- Disk Space Analysis - DF: The
dfcommand reveals information about the disk space used and available across various segments of the file system, helping users understand space utilization in each partition.
Commands for installing, updating, and removing programs in Linux
Linux uses a range of package managers to facilitate the installation, upgrading, and removal of software applications. Below are some key commands associated with the DNF and APT package managers:
DNF (Fedora and CentOS):
sudo dnf install [package_name]
Example: To install the Firefox web browser, use
sudo dnf install firefox.
System and Software Update:Command:
sudo dnf upgrade
Note: This updates all installed packages to their latest versions.
sudo dnf remove [package_name]
Example: To remove the installed Firefox package, use
sudo dnf remove firefox.
APT (Debian-based distributions, e.g., Ubuntu):
sudo apt install [package_name]
Example: To install the Firefox web browser, use
sudo apt install firefox.
- System and Software Update:
Update Package Lists:
sudo apt update
Update Installed Packages:
sudo apt upgrade
apt updatecommand refreshes the list of available packages, while
apt upgradeupdates the installed packages to their latest versions.
- Update Package Lists:
sudo apt remove [package_name]
Example: To uninstall the Firefox package, use
sudo apt remove firefox.
Commands for file and directory management in Linux
Linux provides a suite of commands for managing files and directories. Below are some of the essential commands:
find: Search for files and directories based on various criteria, such as name, size, and type.
find / -name file_name.txt
mkdir: Create a new directory.
cat: Display the content of a file.
touch: Create a new file.
rm: Delete files and directories. Caution: Deleted files cannot be restored.
To delete a directory and its contents:
rm -r directory_name
To delete a file:
rename: Rename files.
rename old_file_name new_file_name
mv: Move or rename files or directories.
mv ~/source_directory/file_name.txt ~/target_directory/
pwd: Display the path of the current directory.
cd: Change the current directory.
cp: Copy files or directories.
cp ~/source_directory/file_name.txt ~/destination_directory/
ls: List the contents of the current or specified directory.
Commands for managing users in Linux
sudo: Execute commands with superuser (root) privileges.
useradd: Create a new user account.
su: Switch to another user or assume superuser (root) privileges.
passwd: Set or change a user's password. After executing this command, you'll be prompted to input a new password for the designated user.
userdel: Delete a user account, which will also remove their home directory.
usermod: Modify user account settings, such as their home directory, associated group, and more.
usermod [options] user_name
Conclusively, the Linux operating system offers an extensive suite of tools for system management. While this guide touches upon the basics suitable for newcomers, there are numerous other commands available for diverse requirements.