Linux Commands Cheat Sheet

Linux Commands Cheat Sheet

Welcome Note:

As a DevOps Engineer Linux is a very basic requirement that is demanded by the organizations. So before deep diving into bunch of Linux commands let's just start with the most common question what and why Linux ?! . Some says it's an OS where as some says it's a Kernel . So without further due let's understand our first question:

What is and Why Linux?

Linux is an open-source Operating System based on the Linux kernel. Open source simply means anyone can contribute to it , can modify it and can even rebrand it. An OS is nothing but an agent that sits between application and hardware. Linux is used for computers, servers, mainframes, mobile devices, and embedded devices. As it supports every major computer architecture such as x86, ARM, and SPARC it most widely supported OS.

What is Kernel?

The kernel is the main component of any operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible. You find in every mobile phone's about section that says based on Linux kernel. 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.

As we got to know the definitions above, let's just how can we interact with Linux. There are two ways through which we can make the best out of Linux which are:

Linux GUI (Graphical User Interface) : The graphical user interface is that enables an user to interact with the system with a proper look and feel. It is like any other Operating system available in the market as Windows or Mac.

Linux CLI (Command Line Interface) : Whereas in Command Line Interface the UI part is completely eliminated. There is no visual representation as Windows or Mac. The CLI is more efficient, time-effective, and easy to use only when you have enough knowledge on the Linux commands for perform several operations in the OS.

CLI from DevOps Prospective

CLI commands enable you to streamline your tasks with a faster and more flexible interactive canvas, bypassing user interface workflows. Whether it's AWS devops or Azure devops every provider has their CLIs. So, the bottom line is in order to interact with any Linux environment we need to be fluent enough in a bunch of Linux commands which we are going to see below.

User Information commands:

  • who : Login name of the user and date time of login remote hostname.

  • id : It displays user identification it gives uid, gid, and context.

  • passwd: Initiates password change.

  • groups: This command is used to display the groups that the user belongs to.

  • lastlog : It is used to find the details of recent login activities of all users or the services accessed by users.

  • sudo adduser username : It is used to create a normal user.

  • su username : It is used to come back to normal users.

  • userdel -r username : It is used to delete the user.

  • sudo usermod -a -G GROUPNAME USERNAME : To add a user to a group.

  • sudo deluser USER GROUPNAME : To remove a user from a group.

  • finger : Shows information of all the users logged in

  • finger username : Gives information of a particular user

File and Directory Commands

  • pwd: it displays the present working directory.

  • ls : It shows the list of the directories.

  • mkdir: Creates a directory or folder.

  • rmdir directoryName: it removes a desired directory.

  • rmdir -p: It removes the directory along with it's ancestors.

  • -v : verbose will give output for the processed directory.

  • touch: It creates any file.

  • cat fileName : Used to see the content of the file on terminal itslef without opening it using VIM of nano.

  • ls -l fileName: To know the permission.

  • cd ~: will take you to the home directory.

  • rn fileName: Used to remove the file.

  • ls -l: To know the permission.

  • r: Read permission.

  • w: Write permission.

  • x: Execute permission.

  • cd /: It changes the directory from user to "/"

  • cd .. : It takes us to Previous directory

  • ls -al : It lists out all the files and configuration present in current as well as other directories .

  • mkdir dirName1 dirName2 dirName3 : It creates multiple directories at the same time

  • mkdir /home/user/Mydirectory : It creates a directory at a particular location.

  • mkdir -p A/B/C/D : It creates directory inside directory(Nested Directory). With the help of mkdir -p command, you can create sub-directories of a directory.

Commands for Installation of Packages

  • yum install packageName: This command helps to install the package.

  • yum info packageName: It displays brief details about the package.

  • yum remove packageName: It's going to remove the package

Disk Usage Commands

  • du : It gives details of disk usage.

  • **du pathOfDirectory ** : It gives disk usage in a particular directory.

  • **du -h /home ** : It brings the details into human readable format.

  • **du -sh /home ** : It is used to find out total disk usage in brief.

System & Hardware Information

  • **uname -a ** : It give the system details along with timestamp.

  • **usname -s ** : To know the kernel name.

  • **uname -r ** : To know the release version of the kernel.

  • **uname -m ** : It gives the architecture of the OS.

  • **uname -o ** : To know the name of the Operating system.

  • **chmod permissionDigits fileName ** : Used to give permission.

VIM Editing Commands

  • i : Insert at cursor (goes into insert mode).

  • a : Write after cursor (goes into insert mode).

  • A : Write at the end of line (goes into insert mode).

  • ESC : Terminate insert mode.

  • u : Undo last change.

  • U : Undo all changes to the entire line.

  • o : Open a new line (goes into insert mode).

  • dd : Delete line.

  • 3dd : Delete 3 lines.

  • D : Delete contents of line after the cursor.

  • C : Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.

  • dw : Delete word.

  • 4dw : Delete 4 words.

  • cw : Change word.

  • x : Delete character at the cursor.

  • r : Replace character.

  • R : Overwrite characters from cursor onward.

  • s : Substitute one character under the cursor and continue to insert.

  • S : Substitute entire line and begin to insert at the beginning of the line.

  • ~ : Change case of individual character.

> Networking command

  • SSH username@ip-address or hostname : login into a remote Linux machine using SSH.

  • Ping hostname="" or ="" : To ping and Analyzing network and host connections.

  • dir : Display files in the current directory of a remote computer.

  • cd "dirname" : change directory to “dirname” on a remote computer.

  • put file : upload ‘file’ from local to remote computer.

  • get file : Download ‘file’ from remote to local computer.

  • shutdown : shutdowns the system.

  • reboot : Restarts the system.

  • quit : Logout.

> Process commands

  • bg : To send a process to the background.

  • fg : To run a stopped process in the foreground.

  • top : Details on all Active Processes.

  • ps : Give the status of processes running for a user.

  • ps PID : Gives the status of a particular process.

  • pidof : Gives the Process ID (PID) of a process.

  • kill PID : Kills a process.

  • nice : Starts a process with a given priority.

  • renice : Changes the priority of an already running process.

  • df : Gives free hard disk space on your system.

  • free : Gives free RAM on your system.

Above I have consolidated around 50+ most used Linux commands that's going to be really helpful for a beginners as well as experienced personals . Hope it helps.