Introduction to Essential Linux Commands

Introduction to Essential Linux Commands

All Essential Linux Commands at One place with description.

Essential Linux commands are a set of basic commands used to interact and control the Linux operating system through the command-line interface (CLI). These commands include basic file management commands, commands to manage and display system information, commands to manage users, groups, permissions, and more.

1. ssh

Secure Shell (SSH) is a way for you to securely, remotely access, and control a computer or network from another computer and another location. SSH uses encryption to protect your login information and the data that is transferred between the two computers, making it much more secure than other methods of remote access. It is commonly used to remotely manage servers, network devices, and other systems.

In simple terms, SSH allows you to remotely access and control a computer as if you were sitting in front of it, in a secure way.

For example, Imagine you have a website hosted on a server at your office, and you want to make updates to it from your home. Instead of physically going to the office to make the updates, you can use SSH to remotely access the server and make the updates from your home computer. SSH encrypts the connection between your home computer and the server so that any information exchanged between the two is secure and cannot be intercepted by anyone else.

ssh-keygen

"ssh-keygen -t rsa" command is used to generate a new SSH key pair. The "ssh-keygen" command is used to create, manage and convert SSH keys, and the option "-t rsa" is used to specify the type of the key to generating, in this case, RSA.

RSA is the algorithm used for public-key encryption and digital signatures.

It's important to note that the private key should be kept safe, and never shared with anyone. The public key can be shared with others and added to remote servers to allow for passwordless login.

In summary, "ssh-keygen -t rsa" is a command in Linux that is used to generate a new SSH key pair, it prompts for a file name and passphrase to encrypt the private key, RSA is the algorithm used to generate the key and the private key should be kept safe, while the public key can be shared with others to allow for passwordless login.

2. sudo su -

"sudo su -" command allows a user to temporarily gain the privileges of the superuser, also known as the "root" user. The "sudo" part of the command grants the user temporary superuser privileges, and the "su -" part allows the user to switch to the root user account.

For example, imagine you are a regular user on a Linux machine and you need to install a new software package. Normally, you would not have permission to do so because the package manager is restricted to the superuser. By using the command "sudo su -", you can temporarily gain superuser privileges and install the package as root.

It's important to note that using the root account can be a security risk, it's recommended to use the least privileged account whenever possible, and use the "sudo" command to temporarily gain superuser privileges only when necessary.

In summary, "sudo su -" is a command that allows a regular user to temporarily gain superuser privileges, which can be useful for performing certain tasks that are restricted to the root user. However, it's important to use it carefully and with caution.

3. chmod

"chmod o+rx" command is used to change the permissions of a file or directory. The "chmod" command stands for "change mode" and it is used to modify the permissions of a file or directory.

In this specific case, "o+rx" is an argument passed to the chmod command. The "o" stands for "others", " + " means "add" and "rx" stands for read and execute permission. This means that the command is adding read and execute permission to the "others" category of users for the specified file or directory.

There are three types of permissions: read (r), write (w), and execute (x). These permissions can be assigned to three different classes of users: the file's owner, the owner's group, and all other users.

4. ls

"ls -ltr" command is used to list the files and directories in a directory, with additional information, and in a specific order. The "ls" command stands for "list" and it is used to display the contents of a directory. The options "l", "t" and "r" added to the command change the way the files and directories are displayed.

The option "l" stands for "long format" and it shows additional information about the files and directories, such as permissions, owner, size, and date of last modification.

The option "t" stands for "sort by modification time" and it will sort the files and directories based on when they were last modified.

The option "r" stands for "reverse" and it will reverse the order of the files and directories.

For example, if you are in a directory and you want to see the contents of the directory with additional information sorted by the time they were last modified in reverse order, you can use the command "ls -ltr". This will display all the files and directories in the directory, including hidden files, with details like permissions, owner, size, and date of last modification and will be sorted in reverse order of modification time.

In summary, "ls -ltr" is a command that lists the files and directories in a directory with additional information, sorted by the time they were last modified in reverse order.

5. cat

"cat" is a command in Linux that is used to display the contents of a file on the terminal in a human-readable format.

we can also use "cat" command to concatenate multiple files and display the contents of all the files in sequence. For example, you can use the command "cat file1.txt file2.txt > combined_file.txt" this will combine the contents of file1.txt and file2.txt and store the combined content in a new file called combined_file.txt.

In summary, "cat" is a command that is used to display the contents of a file on the terminal, it can also be used to concatenate multiple files and display the contents of all the files in sequence or store them in a new file.

6. grep

"grep" is a command in Linux that is used to search for patterns in text and it is used to search for a specific word or phrase in a file or a group of files.

For example, if you have a file named "example.txt" and you want to find all the lines that contain the word "apple", you can run the command "grep apple example.txt", this will search the file "example.txt" and print all the lines that contain the word "apple".

You can also use the "grep" command to search for patterns in multiple files by specifying a directory instead of a file name.

For example, you can use the command "grep apple /home/user/documents" this will search all the files in the directory "/home/user/documents" and print the lines that contain the word "apple".

In summary, "grep" is a command that is used to search for patterns in text, it can search for a specific word or phrase in a file or a group of files, and it prints the lines that contain it.

7. timedatectl

The "timedatectl" command is used to manage the system time and date settings, including the timezone. It can be used to check the current time and date settings, as well as to change them.

For example, "timedatectl set-timezone America/New_York" will set the timezone to Eastern Time (ET).

In summary, "timedatectl" is a command that is used to manage the system time and date settings, including the timezone, it can be used to check the current time and date settings, as well as to change them, it also allows checking the NTP (Network Time Protocol) synchronization status.

8. crontab

The "crontab" command is used in Linux to manage and view the cron jobs for a specific user. It allows you to create, edit, view, and delete scheduled tasks that are executed at specified intervals.

For example, you can use "crontab -e" to edit the cron jobs for the current user, "crontab -l" to list the cron jobs for the current user, or "crontab -r" to remove the cron jobs for the current user.

9. sed

"sed" is a stream editor command in Linux that allows you to perform text transformations on files and input streams. It is often used to search, find and replace, insert, and delete text in a file without opening it.

For example, you can use "sed" to search for a specific word in a file and replace it with another word, or you can use it to delete specific lines from a file. "sed" is a powerful tool for processing text data in Linux and is commonly used by system administrators and developers.

10. chage

"chage" is used to manage user account aging information such as password expiration, account expiration, and other settings. It allows you to view and modify the aging information for a user account in Linux.

chage -E

The chage -E 2021-04-15 mark command is used to set the account expiration date for the user 'mark' to April 15th, 2021 in Linux.

Thank you so much for taking your valuable time to read

I took the initiative to learn in public and share my work with others. I tried my level best in squeezing as much information as possible in the easiest manner. Hope you learned something new today :)

Any feedback for further improvement will be highly appreciated!

via GIPHY

Did you find this article valuable?

Support Learn by Doing by becoming a sponsor. Any amount is appreciated!