DEV Community

Cover image for All you need to get started with Linux...
Dipanshu Torawane for Kubernetes Community Days Chennai

Posted on • Edited on

All you need to get started with Linux...

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) => Prints the current directory in which we are present onto the terminal.

  • cd [dir name] => Change Directory means moving from the current directory to the [dir name] directory.

  • cd .. => Move one level up or to the previous directory from the current directory.

  • mkdir [dir name] => Make a directory of [dir name] in the current directory.

  • ls => Lists all files and directories in the present working directory.

  • ls -R => Lists files in sub-directories as well.

  • ls -al => Lists files and directories with detailed information like permissions, size, owner, etc.

  • ls -a => Shows all files & folders*(including hidden)*

  • touch [filename] => creates [filename] with the provided extension.

  • rm [filename] => Deletes [filename]

  • rmdir or rm -d => Deletes a directory

    NOTE: Here rm commands delete the file permanently.

  • rm -r(recursively) => 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] => Displays the file content.

  • cat file1 file2 > file3 => Joins two files (file1, file2) and stores the output in a new file (file3).

  • mv file "new file path" => Moves the file to the new provided file location.

  • mv filename new_file_name => Renames the file to a new filename.

  • cp -r [dirname] [new_filename] => Copy [dirname] to new_filename.

Superuser, manual, history and some common terminal commands

  • sudo => Allows regular users to run programs with the security privileges of the superuser or root.

  • man => Gives the whole documentation of commands

  • history => Gives a list of all past commands typed in the current terminal session.

  • history [number] => Gives the previous [numbers] of the command typed in the session.

  • clear => Clears the terminal.

  • Ctrl + C => Stops the current command completely instead of running in the background.

  • Ctrl + Shift + C => Copies the selected text from the terminal.

  • Ctrl + Shift + V => Pastes the copied text from other terminal session or browser.

  • Ctrl + R => Search the last history of command.

  • uname -a => Shows information about system and kernel.

  • lscpu => Shows information about the CPU in the machine.

  • lsmem => Shows information about memory in the machine.

  • su - [name of the user] =>Switchs the user to [name of the user].

  • cat /etc/os-release => Gives information about distribution, version, etc.

  • init 0 => To shutdown/poweroff machine.

  • init 6 => 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

    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

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

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.

Top comments (1)

Collapse
 
iacillodev profile image
João Iacillo

Pretty good introduction to basic linux commands and Ubuntu environment