Basic Linux commands in the terminal

Базовые команды Linux в терминале

Linux is a flexible operating system that is very popular among users all over the world. Getting to know Linux can seem daunting at first. In this article, we’ll look at how to use Linux, as well as take a look at Linux console commands and provide you with a cheat sheet to help you get started quickly with the command line.

Linux Terminal Basics

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 run commands, execute scripts, manage files and folders, configure the system, and much more.

Linux терминалLinux терминал

How to open a Linux terminal? This can be accomplished in several ways, depending on your system and preference:

  1. Using the GUI . Most Linux distributions have a button or shortcut on the desktop or in the applications menu designed to launch the Linux terminal. They are usually named “Terminal”, “Konsole”, “XTerm”. Click on it to open a terminal.
  2. Using hotkeys . Some Linux distributions offer keyboard shortcuts to quickly open a terminal. For example, the keyboard shortcut Ctrl + Alt + T is often used for this purpose. Try pressing these keys at the same time to open the terminal.
  3. Using Application Search . If you can’t find the terminal shortcut, you can use the application search. There is usually a search box on the taskbar or application menu. Type “terminal” or “command prompt” to find the corresponding terminal application.

After opening a 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 in the context of the current user. However, to run certain commands, especially those that require administrator privileges, you may need to run the terminal as an administrator (root).

To run the command prompt as an administrator in Linux, you can use the sudo command . For example, to open a terminal with administrator privileges, you can type sudo terminal_command_name and press Enter. The system may require you to enter a user password with administrator privileges to confirm the operation.

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

Overview of the basic principles of working in the Linux terminal

There are a huge number of commands in Linux that provide a wide range of functions and capabilities. Let’s talk about the basic principles of working in the terminal.

  • Command Line
    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. In Linux, terminal commands can be used to manipulate files and folders, manage processes, configure the system, and much more.
  • Basic commands
    To start working in the terminal, you need 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), output file contents (cat), and many others.
  • Command Parameters and Flags
    Many commands in the terminal can accept additional parameters or flags that change their behavior or provide additional information. For example, the -l flag of the ls command is used to display the contents of a directory as a list with additional details, and the -r flag of the rm command specifies the removal of files and directories recursively.
  • Absolute and relative path
    A path is an indication of the location of a file or directory in the file system. Linux uses absolute paths, starting with /, and relative paths, which point to a location relative to the current directory. For example, /home/user/Documents is the absolute path to the Documents folder, and Documents/notes.txt is the 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 makes it easier to enter long and complex paths or commands. Additionally, the terminal saves a history of entered commands, and you can use the up and down keys to navigate through the history and repeat commands.
  • Permissions and Privileges
    In Linux, files and directories have access rights that determine who can read, write, and execute them. When running commands in the terminal, you may need to use administrator (root) privileges to perform certain operations. To do this, use the sudo command, which allows you to run the command as an administrator.

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

Commands for managing files and directories

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

  • mkdir – command on how to create a directory (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 on how to create a file in Linux
    touch ~/directory/file_name
    Type touch and the name of the new file, such as touch file.txt, to create an empty file called file.txt. The file will be created in the current working directory.
  • rename – command on how to rename a file in Linux
    rename ~/directory/file_name
  • mv – command on how to move a file in Linux
    mv ~/directory/file ~/mv_directory/file
    To move a file to another directory, use mv file_name directory_path. For example, mv file.txt Documents/ will move the file file.txt to the Documents folder. You can specify both relative and absolute path to the directory.
  • cp – command on how to copy a file in Linux
    cp ~/directory/file ~/copy_directory/copy_file
    cp [options] original_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 located in the current working directory. For example, ls or ls -l will display a list of files with additional information such as file permissions, size, and file modification times.
  • cd – command to change the current working directory
    cd ~/Documents
    You can use this command to change to another directory. For example, cd Documents will take you to the Documents directory.
  • pwd is a command that prints the full path of the current working directory.
    It is useful when you want to know which directory you are currently in.
  • rm is a command on how to delete a directory in linux, as well as how to delete a file in linux. Be careful, deleted files and directories cannot be recovered. To delete files, use rm file.txt. To remove a directory and its contents recursively, use rm -r directory.
  • cat is a command to display the contents of files on the screen. For example, cat file.txt will display the contents of file.txt.
  • find is a command that searches for a folder in Linux, as well as directories, text, lines in the specified directory and its subdirectories based on various criteria such as file name, type, size, etc.

User Management Commands

Commands that allow you to manage users and their accounts:

  • useradd – command that is used to create a new user
    useradd username
  • passwd – command on how to set or change a user password in Linux. After running 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 his home directory, if it exists.
    userdel username
  • usermod – allows you to change user settings, such as username, home directory, group, etc.
    usermod parameters user_name
    For example: usermod -d /home/new_directory john – this command will change the home directory of 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, uninstalling and updating programs

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

  • apt is a command for Debian-based distributions such as Ubuntu.
    1. Installing the program
      sudo apt install package_name
      For example, sudo apt install firefox will install the Firefox web browser.
    2. Updating your system and programs
      sudo apt update or sudo apt upgrade
      The apt update command updates package lists, and apt upgrade upgrades installed packages to the latest versions.
    3. Uninstalling a program
      sudo apt remove package_name
      For example, sudo apt remove firefox will remove the installed Firefox package.
  • dnf is a command for Fedora and CentOS distributions.
    1. Installing the program
      sudo dnf install package_name
      For example, sudo dnf install firefox will install the Firefox web browser.
    2. Updating systems and programs
      sudo dnf upgrade
      This command upgrades installed packages to the latest versions.
    3. Uninstalling 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 is a 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 is used to view a list of active processes on the system. It allows you to obtain information about running processes, their identifiers (PID), resource usage, etc.
  • top – provides interactive system monitoring and displays a list of active processes in real time. Allows you to view CPU load, memory usage and other system statistics.
  • df – used to display information about the available disk space on various partitions of the file system. Allows you to find out how much space is occupied and how much is left on each partition.
  • free – shows information about memory usage in the system. It displays the total memory, RAM and swap usage.
  • ifconfig or ip – used to obtain information about network interfaces and configure network parameters such as IP address, subnet mask and gateway.
  • shutdown or reboot – used to shutdown or reboot the system, respectively. For example, sudo shutdown -h now will shut down the system.

We’ve covered the basic Linux commands. The cheat sheet contains the basic commands used to manage the system on Linux. Don’t forget that the Linux operating system offers extensive system management capabilities, so there are many other commands that can be useful in a variety of cases.

Similar Posts

Leave a Reply