Basic Linux Commands for Beginners

Basic Linux Commands for Beginners

#90 Days of DevOps Challenge - Day 2

Table of contents

No heading

No headings in the article.

▶ What is Linux?

Linux is an open-source operating system (OS). An OS is a 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.

▶ What is a command line?

It is your direct access to a computer. It is where you ask the software to perform hardware actions that point-and-click graphical user interfaces (GUIs) merely cannot ask.

Command lines are available on many operating systems—proprietary or open source. But it is usually associated with Linux because both command lines and open-source software jointly give users unrestricted entry to their computers.

▶ How does Linux work?

Linux was designed to be similar to UNIX but has evolved to run on a vast variety of hardware from phones to supercomputers. Every Linux-based OS involves the Linux kernel—which manages hardware resources—and a set of software packages that make up the rest of the operating system. Most organizations choose to run their Linux OS on a Linux server.

The Linux OS includes some standard core components, like the GNU tools, among others ones. These tools give a way to manage the resources provided by the kernel, install additional software, configure performance and security settings, and more. Because Linux is an open-source OS, combinations of software can vary between Linux distributions, and there are many of them.

▶ What is Kernel?

It is the base component of the OS, and without it, the OS does not work. The kernel manages the system’s resources and communicates with the hardware. It’s responsible for memory, process, and file management.

▶ Linux File System Hierarchy

The file system hierarchy in Linux is like a tree structure where each directory(folder) has a specific purpose and location.

▶ Some basic Linux Commands

  1. Create a Directory

    mkdir: This command is used to create a new directory(folder). You can create a single directory by specifying its name after the "mkdir" command, or multiple directories by separating their names with spaces. Or, also create nested directories (a directory inside of another directory) by using the "p " option followed by the path of the nested directories.

    To create a simple directory:

    To create multiple directories:

    To create a directory path(directory inside another directory):

  2. Create a simple file 1

    touch: To create a simple file you can use touch command, creating an empty file with the specified name. You can create a single file by specifying its name after the "touch" command, or multiple files by separating their names with spaces. You can also create multiple files with similar names by using curly braces and a range of numbers.

  3. Create a simple file 2

    cat: This command can be used to create a file and add data to it. You can use it by typing "cat > filename" and then entering the data you want to add. To read a file, you can use the "cat <filename>" command. You can also use the "cat >> filename" command to append data to an existing file.

    After running this command, you can enter the text you want to add to the file. When you're done, press "Ctrl+D" to save and exit.

    Alternatively, if you want to append data to an existing file, you can use the following command:

  4. Copy/paste

    cp: This command is used to copy and paste files or directories using the syntax:

    cp <option><source> <destination>

    Options:

    -r for recursive

    -v for verbose

    -f for forcefully

    i.e.

    # cp test1.txt dev

    #cp -rvf prod/test1.txt test

  5. Remove file or directory

    rm: This command is used to remove objects such as files, directories, symbolic links and so on from the file system.

    Options:

    -r for recursive

    -v for verbose

    -f for forcefully

    i.e.

    # rm file5.txt

    i.e.

    # rm -rvf prod

  6. Moving or renaming files and directories

    mv: This command supports moving or renaming files/group_of_files/directories using these syntaxes:

    mv [OPTION]... [-T] SOURCE DEST

    mv [OPTION]... SOURCE... DIRECTORY

    mv [OPTION]... -t DIRECTORY SOURCE...

    Options:

    -r for recursive

    -v for verbose

    -f for forcefully

    i.e.

    # mv test1.txt test5.txt

    i.e.

    # mv dev/ prod/

▶Other Basic Linux Commands

r/linux - Basic Linux Commands