News
Seven days of Black Friday madness — great deal from Serverspace!

THE NEW YEAR
WHEEL OF FORTUNE

Spin the wheel and win a guaranteed prize right now!

By registering, you are signing up to receiving emails.
DC
Daniella Coleman
July 27 2023
Updated July 27 2023

Basic Linux Commands in the Terminal

Basic Linux Commands in the Terminal

Linux is a versatile operating system that enjoys great popularity among users worldwide. Getting started with Linux might seem like a challenging task initially. In this article, we will explore how to use Linux, take a look at Linux terminal commands, and provide you with a cheat sheet to help you work efficiently with the command line.

Fundamentals of the Linux Terminal

The Linux terminal is a text-based interface that allows users to interact with the operating system through the command line. It provides the ability to execute commands, run scripts, manage files and folders, configure the system, and much more.

Терминал Linux

How to Open the Linux Terminal? This can be done in several ways, depending on the system and preferences:

  • Using the graphical interface. Most Linux distributions have a button or shortcut on the desktop or in the application menu designed to launch the Linux terminal. They are usually labeled as "Terminal," "Konsole," "XTerm," or similar. Simply click on it to open the terminal.
  • Using hotkeys. Some Linux distributions offer keyboard shortcuts for quickly opening the terminal. For example, the key combination Ctrl + Alt + T is commonly used for this purpose. Try pressing these keys simultaneously to open the terminal.
  • Using the application search. If you can't find the terminal shortcut, you can use the application search feature. Usually, there is a search field on the taskbar or in the application menu. Type "terminal" or "command line" to find the corresponding terminal application.

After opening the terminal in Linux, you will see a command line where you can enter Linux commands and get the results of their execution. By default, the terminal operates within the context of the current user. However, to execute certain commands, especially those that require administrator privileges, you may need to run the terminal as an administrator (root).

To launch the command line as an administrator in Linux, you can use the "sudo" command. For example, to open the terminal with administrator privileges, you can enter "sudo command_name" and press Enter. The system may prompt you to enter the password of a user with administrator privileges to confirm.

The Linux terminal is a powerful tool for working with the operating system. It allows users to perform various tasks, automate processes, configure the system, and gain full control over their computer. Learning and using the Linux terminal opens up new possibilities and helps to gain a deeper understanding of the functionality of the operating system.

Overview of Basic Principles of Working in the Linux Terminal

In Linux, there are vast number of commands that provide a wide range of functions and capabilities. Let's talk about the fundamental principles of working in the terminal.

  • Command Line. The terminal provides you with a command line where you can enter commands to perform various tasks. Commands are entered as text, and then the Enter key is pressed to execute them. Linux terminal commands can be used for working with files and directories, managing processes, configuring the system, and much more.
  • Basic Commands. To get started in the terminal, it's essential to know the basic commands. These include commands for viewing the contents of directories (ls), changing the current directory (cd), creating directories (mkdir), creating files (touch), copying (cp), and moving (mv) files, deleting files and directories (rm), displaying the contents of a file (cat), and many others.
  • Command Parameters and Flags. Many commands in the terminal can take additional parameters or flags that modify their behavior or provide additional information. For example, the "-l" flag of the "ls" command is used to display the contents of a directory in a list format with additional details, and the "-r" flag of the "rm" command indicates recursive deletion of files and directories.
  • Absolute and Relative Paths. A path is the specification of the location of a file or directory in the file system. In Linux, absolute paths start with "/", and relative paths indicate the location relative to the current directory. For example, "/home/user/Documents" is an absolute path to the "Documents" folder, and "Documents/notes.txt" is a relative path to the "notes.txt" file inside the "Documents" folder.
  • Autocompletion and Command History. The Linux terminal usually offers an autocompletion feature that allows you to type the first few characters of a command or path and press the Tab key to automatically complete the rest. This simplifies entering long and complex paths or commands. Additionally, the terminal keeps a history of entered commands, and you can use the up and down arrow keys to navigate through the history and repeat commands.
  • File Permissions and Privileges. In Linux, files and directories have access permissions that determine who can read, write, and execute them. When executing commands in the terminal, you may need to use administrator (root) privileges to perform certain operations. For this purpose, the "sudo" command is used, which allows you to execute a command as an administrator.

Now let's talk about the categories of basic linux commands that you may encounter in Linux.

Commands for Managing Files and Directories

With these commands, you can view the contents of directories, create, copy, move, and delete files, as well as perform other operations with the file system. Below are some of these commands.

  • mkdir - command to create a directory (folder) in Linux
    mkdir ~/directory/
    Simply enter "mkdir" and the name of the new directory, for example, "mkdir Documents," to create a directory named "Documents."
  • touch - command to create a file in Linux
    touch ~/directory/file_name
    Enter "touch" and the name of the new file, for example, "touch file.txt," to create an empty file named "file.txt." The file will be created in the current working directory.
  • rename - command to rename a file in Linux
    rename ~/directory/file_name
  • mv - command to move a file in Linux
    mv ~/directory/file ~/mv_directory/file
    To move a file to another directory, use "mv file_name path_to_directory." For example, "mv file.txt Documents/" will move the file "file.txt" to the "Documents" folder. You can specify both relative and absolute paths to the directory.
  • cp - command to copy a file in Linux
    cp ~/directory/file ~/copy_directory/copy_file
    cp [options] source_location path_to_new_location
  • ls - command to view the contents of the current directory
    ls [options] directory
    Displays a list of files and subdirectories in the current working directory. For example, "ls" or "ls -l" will display a list of files with additional information, such as permissions, size, and modification time.
  • cd - command to change the current working directory
    cd ~/Documents
    You can use this command to navigate to another directory. For example, "cd Documents" will take you to the "Documents" directory.
  • pwd - command that displays the full path of the current working directory
    It's helpful when you want to know which directory you are currently in.
  • rm - command to delete a directory in Linux, as well as to delete a file in Linux. Be careful, deleted files and directories cannot be recovered. To delete files, use "rm file.txt." To delete a directory and its contents recursively, use "rm -r directory."
  • cat - command to display the contents of files on the screen. For example, "cat file.txt" will display the contents of the file "file.txt."
  • find - command that performs searches for folders in Linux, as well as directories, text, strings in the specified directory and its subdirectories based on various criteria, such as filename, type, size, etc.

Commands for User Management

Commands that allow you to manage users and their accounts:

  • useradd - command used to create a new user
    useradd username
  • passwd - command to set or change a user's password in Linux. After executing this command, you will be prompted to enter a new password for the specified user.
    passwd username
  • userdel - command to delete a user. This will also delete their home directory if it exists.
    userdel username
  • usermod - allows you to modify user parameters such as the username, home directory, group, etc.
    usermod parameters username
    For example: usermod -d /home/new_directory john - this command will change the home directory of the user "john" to "/home/new_directory."
  • su - allows you to temporarily switch to another user or become a superuser (root).
    su username
  • sudo - allows you to execute commands as the superuser (root).
    sudo command

Commands for Installing, Removing, and Updating Programs

In Linux, there are various package managers that allow you to manage the installation, removal, and updating of programs.

  • apt - command for Debian-based distributions, such as Ubuntu.
  1. Installing a program
    sudo apt install package_name
    For example, "sudo apt install firefox" will install the Firefox web browser.
  2. Updating the system and programs
    sudo apt update or sudo apt upgrade
    The "apt update" command updates the package lists, and "apt upgrade" updates the installed packages to their latest versions.
  3. Removing a program:
    sudo apt remove package_name
    For example, "sudo apt remove firefox" will remove the installed Firefox package.
  • dnf - command for Fedora and CentOS distributions.
  1. Installing a program
    sudo dnf install package_name
    For example, "sudo dnf install firefox" will install the Firefox web browser.
  2. Updating the system and programs
    sudo dnf upgrade
    This command updates the installed packages to their latest versions.
  3. Removing a program:
    sudo dnf remove package_name
    For example, "sudo dnf remove firefox" will remove the installed Firefox package.

Popular Commands for System Management on Linux

  • systemctl - command for managing system services in Linux. It allows you to start, stop, restart, and check the status of services.
    sudo systemctl start - will start the specified service.
  • ps - command used to view a list of active processes in the system. It provides information about running processes, their process IDs (PIDs), resource usage, etc.
  • top - provides interactive real-time monitoring of the system and displays a list of active processes. It allows you to view CPU load, memory usage, and other system statistics.
  • df - used to display information about available disk space on different file system partitions. It allows you to see how much space is used and how much is left on each partition.
  • free - shows information about memory usage in the system. It displays the total memory, usage of RAM, and swap space.
  • ifconfig or ip - used to get information about network interfaces and configure network parameters such as IP address, subnet mask, and gateway.
  • shutdown or reboot - used to power off or restart the system, respectively. For example, "sudo shutdown -h now" will shut down the system.

We have covered the basic Linux commands. The cheat sheet displays popular commands used for system management on Linux. The Linux operating system offers great flexibility in system management, and there are many other commands that can be useful in various scenarios.

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.