Basic Linux Commands

Basic Linux Commands

🐧 What is Linux?

Linux is an open-source operating system. An operating system is the software that directly manages a system's hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and makes the connections between all of your software and the physical resources that do the work. In 1991, an individual by the name as Linus Torvalds constructed it. The system’s source code is accessible to everyone for anyone to look at and change, making it cool that anyone can see how the system works. It acts as the basis for a variety of devices, such embedded systems, cell phones, servers, and personal computers. Linux, that’s well-known for its reliability, safety, and flexibility, allows users to customize and improve their environment to suit specific needs.

Architecture of Linux

The main components of the Linux architecture are:

  1. Kernel :- The Linux kernel is the core part of the operating system. It is responsible for interacting with the hardware and providing services to the rest of the system. It handles critical tasks such as process management, memory management, device management, and system calls.

  2. System Libraries:- These libraries can be specified as some special functions. These are applied for implementing the operating system's functionality and don't need code access rights of the modules of kernel.

  3. System Utility Programs:- It is responsible for doing specialized level and individual activities.

  4. Hardware layer:- Linux operating system contains a hardware layer that consists of several peripheral devices like CPU, HDD, and RAM.

  5. Shell:- It is an interface among the kernel and user. It can afford the services of kernel. It can take commands through the user and runs the functions of the kernel. The shell is available in distinct types of OSes. These operating systems are categorized into two different types, which are the graphical shells and command-line shells.

🐧 Basic Linux Commands

Listing Commands

  • ls : ls command is used to list out all files & directories available. It displays all files in alphabetical order.

    Note - We can pass several options for ls command

  • ls -r : It displays all files in reverse alphabetical order.

  • ls -l : It displays long listing of files with extra information

  • ls -t : It displays all files based on last modified date and time. Most recent file will be displayed on top.

  • ls -la : It is used to display hidden files like .ssh, .cache. Hidden files are displayed using ‘.’

  • ls -R : It will display all files and directories along with sub directories content.

Directory Commands

  • mkdir directoryName : It is used to create a new directory file. Basically it creates a new folder on server.

  • pwd : The pwd command stands for (print working directory). It displays the current working location or directory of the user.

  • cd : The cd command stands for (change directory). It is used to change to the directory you want to work from the present directory.

  • rmdir directoryName : The rmdir command stands for remove directory. It helps to delete a particular directory.

  • rm -r directoryName/ : This command will recursively remove mentioned directory and all files inside that directory.

File Commands

  1. Create Files & Directories

  • touch f1.txt : Creates a new text file with name f1.txt

  • mkdir new_dir : Creates a new directory

  • mkdir -p dir1/dir2 : Create nested directories

  • cat > f2.txt : Creates a new file f2.txt

  • cat » f2.txt : Appends data to f2.txt

  • cat f2.txt : To Display File Content

  1. Copy, Move and Rename Files

  • cp f1.txt f2.txt : This command will help to copy file contents from f1.txt to f2.txt

  • cp -r dir1 dir2 : Copy a directory recursively

  • mv f1.txt sumita.txt : Rename file from f1.txt to sumita.txt

  • mv file.txt /sumita/ : Move file from ubuntu directory to sumita directory

  1. File Viewing

  • cat file.txt : Show file contents

  • less file.txt : This command will help us to show data in chunks or pages in paginated way. Used for large files

  • more file.txt : Similar to less, but less powerful

  • tail file.txt : Show last 10 lines of a file

  • tail -f log.txt : Live update as new lines are added

  • head file.txt : Show first 10 lines of a file

  1. Comparing Files

  • cmp f1.txt f2.txt : cmp command will display only first difference in given two files

  • diff f1.txt f2.txt : diff command will display all the differences in the given two files