...

Introduction to Linux Commands for Everyone in 10 Minutes in an Easy Way

5/5 - (1 vote)

Welcome to the exciting world of Linux commands! This journey starts with understanding the command-line interface (CLI), its importance in Linux, and the basic structure of commands you’ll be wielding.

Linux or Unix commands are simple short programs that do one and only one thing very well. They are often cited as a reference for the SRE principle of the SOLID principle.

E.g – the ls command is only responsible for listing files and directories. rm command is only responsible for deleting files and directories. Further, these commands can be piped together using | to achieve more complex tasks.

E.g – Please sort names in names.txt and save it in names_sorted.txt

# first see the contents of names.txt
Command - cat names.txt
John
Sarah
David
Emily
Michael
Jessica
Chris
Anna
Alex
Emma

# Solution - We need to sort contents of names.txt so we will send this file's content as input to sort program then we need to save the output in names_sorted.txt. So we will redirect sorted output to write in names_sorted.txt
Let us see this in action

Command - cat names.txt | sort > names_sorted.txt

# Validate the solution
Command - cat names_sorted.txt
Alex
Anna
Chris
David
Emily
Emma
Jessica
John
Michael
Sarah

See, how easy and interesting it is to learn Linux commands and solve complex system tasks in a single-line command.

Prerequisites

LInux Commands
Linux Commands

Overview of command-line interface (CLI) or Terminal

  • Imagine a text-based environment where you type commands and receive responses directly. That’s the CLI, a powerful tool in Linux used for system administration, scripting, automation, and even everyday tasks.
  • While graphical interfaces (GUIs) offer icons and buttons, the CLI provides precise control and efficiency for experienced users.

Overview of SHELL

Shell is a program that executes Linux commands. When we open a terminal it opens with a shell.
Bash is the default pre-installed shell on Linux systems. But, generally, users prefer to use zsh due to its user-friendliness, ease-of-use, and customization.

Significance of command-line usage in Linux

  • Granular control: Access and manipulate files, processes, and configurations with greater detail than GUIs.
  • Automation: Write scripts to automate repetitive tasks, saving time and effort.
  • Troubleshooting: Diagnose and fix issues efficiently using specific commands.
  • Flexibility: Work remotely on servers without graphical environments.
  • Efficiency: Master keyboard shortcuts for lightning-fast interactions.

Basic command structure and syntax

  • Most commands follow a basic structure: command [options] [arguments].
    • Command: The specific action you want to perform (e.g., ls for listing files, mkdir for creating directories).
    • Options: Modify the command’s behavior (e.g., -l for long listing with ls).
    • Arguments: Specify what the command operates on (e.g., file names, directory paths).
  • Syntax rules define how to combine these elements correctly. For example, spaces usually separate options and arguments, while some options might take values after =.

Linux Command Examples

Q1 – list all files in a given directory(~/Downloads) in a sorted order (timewise ascending)

ls -t ~/Downloads

Explanation – Let us understand the structure of the above command.
ls – command -> to list the files
-t – options(or flags) -> to sort listed files in timewise ascending order
~/Downloads (arguments) -> list files inside this directory
Reasoning behind the above command – to list files we need the ls command, then we need to provide the required options, in this case -t to list the files in a sorted order, then ~/Downloads – this is the directory we want to list.
Lesson – Linux Commands are not hard to learn. Once we understand how to break the problem into subproblems, find solutions, and combine those sub-solutions into the final solution. Then it becomes fun to play with Linux commands.

Just Practice the above principle on a lot of problems and you will master it.

Let us extend the above problem by adding some difficulty
Q2 – list all log files along with its details in a given directory(~/Downloads) in a sorted order (timewise ascending)
Approach – 2 More extension as compared to previous problem
1 – List only log files – add filter for this -> *.log
2 – list details of files – add option to show details -> -l
Add the above two sub-solutions to previous solution
Final solution

ls -tl ~/Downloads/*.log

See how easy it is to solve problems on Linux commands

Top FAQs on Linux Commands

Q1 – What is a Linux command?

Answer – A Linux command is a program that performs a given task as instructed. Please see for this in the previous section

Q2 – Why do we need to learn the Linux command?

Answers – A basic mastery of Linux commands makes our lives easy. It adds to our efficiency. It enables us to perform most complex tasks which are not possible through GUI. Also, we cannot do everything with GUI.

Conclusion

In this post, we learned about Linux command, their structure, and how to use them to perform system-related tasks.

Spread the love
Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.