Published on

👨‍💻Linux Essentials A Crash Course for New Users🎯 Part-1

Authors

📚 Introduction to Linux

Linux is an open-source operating system developed in 1991 by a student named Linus Torvalds. It comprises a kernel, known as Linux's kernel, combined with GNU applications, forming the Linux operating system.

Linux is a versatile operating system used across various platforms, including computers, servers, mainframes, mobile devices, and embedded systems. It enjoys extensive support on major computer architectures, such as x86, ARM, and SPARC, making it one of the most widely adopted operating systems.

Some of the prominent Linux distributions available in the market include:

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora
  • SuSe
  • Scientific
  • CentOS

Advantages of Linux

Linux offers several advantages, including:

  • Resistance to viruses
  • High system stability, reducing the risk of crashes
  • Cost-effective, often available for free
  • Supports multiple users, multitasking, and multiprocessing

Disadvantages of Linux

Despite its strengths, Linux has some drawbacks, such as:

  • A wide array of distributions, which can be overwhelming for newcomers
  • A steeper learning curve for users accustomed to other operating systems
  • Frequent updates and version changes can pose challenges
  • Some tasks may be more complex to perform compared to user-friendly operating systems.

Difference between Linux and Unix

SrNoKeyLinuxUnix
1.DevelopmentLinux is open source and is developed by Linux community of developers.Unix was developed by AT&T Bell labs and is not open source.
2.CostLinux is free to useUnix is licensed OS
3.Supportd File systemsExt2, Ext3, Ext4, Jfs, ReiserFS, Xfs, Btrfs, FAT, FAT32, NTFS.fs, gpfs, hfs, hfs+, ufs, xfs, zfs.
4.GUILinux uses KDE and Gnome. Other GUI supported are LXDE, Xfce, Unity, Mate.Unix was initially a command based OS. Most of the unix distributions now have Gnome.
5.UsageLinux is used in wide varieties from desktop, servers, smartphones to mainframes.Unix is mostly used on servers, workstations or PCs.
6.Default ShellBash (Bourne Again SHell) is default shell for Linux.Bourne Shell is default shell for Unix.
7Target processorLinux was initially developed for Intel's x86 hardware processors. Now it supports 20+ processor families.CUnix supports PA-RISC and Itanium family.
8ExampleUbuntu, Debian GNU, Arch Linux, etc.SunOS, Solaris, SCO UNIX, AIX, HP/UX, ULTRIX etc.

Architecture of Linux

Linux System Architecture Layers

  • Hardware layer: This includes all peripheral devices like RAM, HDD, and CPU.
  • Kernel: The core component of the operating system that interacts directly with hardware and provides low-level services.
  • Shell: A program that acts as an interface between the user and the operating system. Examples include:
    • Bourne shell (denoted as sh)
    • Korn shell (denoted as ksh)
    • C shell (denoted as csh)
    • Bourne Again shell (denoted as bash).
  • Utilities: These are utility programs that offer various functionalities of an operating system.

Basic commands in Linux

  • pwd : To know which directory you are in, you can use the pwd command. It gives us the absolute path, which means the path that starts from the root.
  • pwd
  • ls : Use the "ls" command to know what files are in the directory you are in.
  • ls - l long list with timestamp, ownership, permissions
  • ls -la show the hidden files as well
  • .<filename or foldername> is used to hide the file or folder
  • ls -lh List Directory Contents In Human Readable Format
  • ls -lth Sort Files and Directories Based on Last Modified Time
  • ls -ltrh Sort Files and Directories Based on Last Modified Time in Reverse Order
  • ls --help or man ls List All Options for ls Command

The ls command output comes with seven fields

  • -rw-r--r-- 1 root root 59 Sep 12 17:20 1stfile

  • drwxr-xr-x 2 root root 4096 Sep 12 17:23 bountyadvice/

  • Field-1 (-rw-r--r--) : File Permissions

  • Field-2 (1) : The number of links or directories inside this directory.

  • Field-3 (root) : File owner name

  • Field-4 (root) : File group name

  • Field-5 (4096 ) : File size

  • Field-6 (Sep 12 17:23) : Last modification date and time of the file.

  • Field-7 (bountyadvice) : Name of the file.

  • Field-1 (-|rw-|r--|r--) : File Permissions :- The first character indicates the type of the file.

  • '-' : It indicates for normal file

  • d : It indicates for directory

  • l : It indicates for link file

  • s : It indicates for socket file

  • 2-4 characters indicates permissions on owner.

  • 5-7 characters indicates permissions on group.

  • 8-10 characters indicates permissions on others.

  • cd : Use the "cd" command to go to a directory.

  • cd .. Go to previous directory

  • cd Go to home directory

  • cd </path> Go to Specific Directory

  • mkdir : Use the mkdir command when you need to create a folder or a directory.

  • mkdir test Create directory with name test

  • mkdir .test Create hidden directory with name test

  • mkdir test1 test2 test3 Create multiple directory at once

  • rmdir : rmdir can only be used to delete an empty directory.

  • touch : The touch command is used to create a file. It can be anything, from an empty txt file to an empty zip file.
  • touch new.txt create new empty file named new.txt
  • touch newfile1 new2 new3 create multiple empty files

  • rm : Use the rm command to delete files and directories.
  • rm filename delete file
  • rm new* delete all files starting with new*----- **'*'** means all
  • rm * delete all files (use this with precaution)
  • rm -f delete forcefully
  • rm -rf bountyadvice delete folder recursively

  • cp : Use the cp command to copy files through the command line. It takes two arguments: The first is the location of the file to be copied, the second is where to copy.
  • cp <source> <destination>
  • cp file newfilemake a copy of newfile from file
  • cp -r bountyadvice /root/opt/ move folder bountyadvice to opt recursively

  • mv : Use the mv command to move files through the command line. We can also use the mv command to rename a file.
  • mv newfile newfile_rename rename newfile with newfile_rename
  • mv sourcefolder destinationfolder
  • mv file1 file2 file3 file3 destinationfolder move all multiple files into destinationfolder
  • mv *.txt *.json destinationfolder move all files with extension txt and json to destinationfolder
  • mv folder1 folder2 folder3 folder4 destinationfolder move multiple folders into destinationfolder

  • echo : The "echo" command helps us move some data, usually text into a file and is also used to print particular text.
  • echo "bountyadvice" it will display bountyadvice
  • echo "bountyadvice" > file.txt This write bountyadvice string into file.txt
  • **echo "This is the File name file3" > file3.txt** This will create a text file file3 and redirect the output to the new file.

  • cat : Use the cat command to display the contents of a file. It is usually used to easily view programs.
  • cat file1
  • cat file1 file2 file3
  • cat *.txt *.log

  • df : The df command (short for disk free), is used to display information related to file systems about total space and available space.

  • df -h This will display diskfree output into human readable (GB)

  • df -mThis will display diskfree output into human readable (MB)

  • du : It is used to check the information of disk usage of files and directories on a machine.

  • du -sc *

  • du -sch * disk usage output in human readable values

  • du

  • find : find is a command for recursively filtering objects in the file system based on a simple conditional mechanism. find <direcory/path> <search with name,size,perm,time> filename

    • find . -name : Search for files with name. (here . indicates current directory)
    • find . -size : search for files with size.
    • find . -perm : search for files with permission.
  • grep : The grep command is used to search text. It searches the given file for lines containing a match to the given strings or words.

    • grep -i : It is used to search text ignoring uppercase or lowercase.
    • grep <string> <filename> find the string inside the file
    • grep -i <string> * search into all the files
    • cat output.txt | grep -i errors
    • cat logs.txt | grep -i warning

  • ps : The ps (i.e., process status) command is used to provide information about the currently running processes.
    • ps -e : Provides us entire list of currently running process.
    • ps -f : Provides us full listing of running processes.Linux

For all commands above you can use commandname --helpto find detailed flags for e.g.

  • ls --help
  • grep --help

Continued.. (https://www.bountyadvice.com/blog/devops/linux-essentials-a-crash-course-for-new-users-part-2)