All you need to get started with Linux...
Tags: beginners, linux, ubuntu, devops
Published: 2022-03-14 13:25:25

**NOTE:** Everything in Linux is a file. For example, text documents, pictures, directories, and devices like printers, keyboards, USBs, CDs, etc.

So this article we will learn all the basics of Linux and commands to get us started to become a power-user of Linux.

### File Manipulation, moving to different folders and removing files commands

* `pwd`*(print working directory)* =&gt; Prints the current directory in which we are present onto the terminal.
    
* `cd [dir name]` =&gt; Change Directory means moving from the current directory to the `[dir name]` directory.
    
* `cd ..` =&gt; Move one level up or to the previous directory from the current directory.
    
* `mkdir [dir name]` =&gt; Make a directory of `[dir name]` in the current directory.
    
* `ls` =&gt; Lists all files and directories in the present working directory.
    
* `ls -R` =&gt; Lists files in sub-directories as well.
    
* `ls -al` =&gt; Lists files and directories with detailed information like permissions, size, owner, etc.
    
* `ls -a` =&gt; Shows all files & folders*(including hidden)*
    
* `touch [filename]` =&gt; creates \[filename\] with the provided extension.
    
* `rm [filename]` =&gt; Deletes \[filename\]
    
* `rmdir` or `rm -d` =&gt; Deletes a directory
    
    **NOTE:** Here `rm` commands delete the file permanently.
    
* `rm -r`*(recursively)* =&gt; Removes file or folder if it contains files inside it.
    

### Displaying contents of the file, moving/copying the file from one folder to another

* `cat [filename]` =&gt; Displays the file content.
    
* `cat file1 file2 > file3` =&gt; Joins two files *(file1, file2)* and stores the output in a new file *(file3).*
    
* `mv file "new file path"` =&gt; Moves the file to the new provided file location.
    
* `mv filename new_file_name` =&gt; Renames the file to a new filename.
    
* `cp -r [dirname] [new_filename]` =&gt; Copy `[dirname]` to `new_filename.`
    

### Superuser, manual, history and some common terminal commands

* `sudo` =&gt; Allows regular users to run programs with the security privileges of the superuser or root.
    
* `man` =&gt; Gives the whole documentation of commands
    
* `history` =&gt; Gives a list of all past commands typed in the current terminal session.
    
* `history [number]` =&gt; Gives the previous `[numbers]` of the command typed in the session.
    
* `clear` =&gt; Clears the terminal.
    
* `Ctrl + C` =&gt; Stops the current command completely instead of running in the background.
    
* `Ctrl + Shift + C` =&gt; Copies the selected text from the terminal.
    
* `Ctrl + Shift + V` =&gt; Pastes the copied text from other terminal session or browser.
    
* `Ctrl + R` =&gt; Search the last history of command.
    
* `uname -a` =&gt; Shows information about system and kernel.
    
* `lscpu` =&gt; Shows information about the CPU in the machine.
    
* `lsmem` =&gt; Shows information about memory in the machine.
    
* `su - [name of the user]` =&gt;Switchs the user to `[name of the user].`
    
* `cat /etc/os-release` =&gt; Gives information about distribution, version, etc.
    
* `init 0` =&gt; To shutdown/poweroff machine.
    
* `init 6` =&gt; To restart/reboot machine.
    

# Package Manager

In Windows, you download the installer and then installs it through the **installation wizard**. But in Linux, we don't use this way, we install most of the software/apps using the **package manager tool**.

### **What is a software package?**

A compressed archive, containing all required files like the apps usually have some dependencies or required some other softwares to run.

For example, Firefox Browser requires dependencies that are not packaged into the archive. These dependencies also need to be installed.

### **What is a package manager?**

Files are split across different folders. Not like Windows, where every program is installed in a **single** file in Program Files. In Windows, it is also easy to uninstall programs as they are in a single folder but in Linux, managing apps uninstalling everything completely is **more difficult***(as they are split)*.

So there are different package managers as per the Linux distros which

* downloads, installs, or updates existing software from a repository.
    
* ensures the integrity & authenticity of the package.
    
* manages & resolves all required dependencies.
    
* knows where to put all the files in the Linux file system.
    
* easy upgrading of the software.
    
    ![9451.1527705212.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647263055271/4-E-ot_fz.png)
    
    In Ubuntu, you have an **APT***(advance package tool)* package manager available.
    

### **Commands used in package manager(commands should be used with sudo)**

* `apt search [package_name]` : Search for a package of `package_name`.
    
* `apt install [package_name]` : Installs the package with `package_name`.
    
* `apt install [package_name1] [package_name2]` : Install multiple packages with one command.
    
* `apt remove [package_name]` : Completely removes installed package of that `package_name`.
    

The benefits of using a package manager are **one central place** to install, upgrade, configure and remove the software.

### Difference b/w APT & APT-GET

![download.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647263160057/dxmGIEPPg.png)

**APT:**

* more user-friendly, like it has a progress bar.
    
* fewer, but sufficient command options in a more organized way(Use apt because recommended by Linux distributions).
    

**APT-GET:**

* search command not available
    
* you can achieve the same if you use additional command options.
    

**Where do these Packages come from?**

Package Manager fetches the packages from the Ubuntu registered/validated repositories.

**Where do these files store?**

Repository*(storage location)* containing thousands of repositories of programs.

**Best practice**

Always update the package index before upgrading or installing new packages.

`apt update` :

* updates the package index
    
* pulls the latest changes from the APT repositories
    
* the APT package index is basically a database
    
* holding records of available packages from the repositories.
    

`add-apt-repository` :

* add the repository to the official list of repository
    
* add repository to APT sources (into /etc/apt/sources.list)
    

**Why add a repository?**

When installing relatively new applications which are not in the official repository yet.

### Repositories Types

Repositories are of type **PPA(Personal Package Archive)**

![what-is-ppa.webp](https://cdn.hashnode.com/res/hashnode/image/upload/v1647263601015/BPXntLhj0.webp)

PPA's are provided by the community. Anybody can create this PPA-private repository to distribute the software. Usually used by developers to provide updates more quickly than in the official Ubuntu repositories.

**Be Aware of possible risks before adding a PPA:**

* **no guarantee** of quality or security
    
* like any other **unofficial** software package it can cause **difficulties**, for example, when upgrading to new Ubuntu release.