Меню Рубрики

Cheat sheet linux commands

Cheat sheet linux commands

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio

Latest commit

Git stats


Failed to load latest commit information.


Click ⭐ if you like the project. Pull Request are highly appreciated. Follow me @SudheerJonna for technical updates.

who It is used to get information about currently logged in user on to system. If you don’t provide any option or arguments, the command displays the following information for each logged-in user.

  1. Login name of the user
  2. User terminal
  3. Date & Time of login
  4. Remote host name of the user

whoami: It display the system’s username

id: It display the user identification(the real and effective user and group IDs) information

groups: This command is used to display all the groups for which the user belongs to.

finger: Used to check the information of any currently logged in users. i.e, It displays users login time, tty (name), idle time, home directory, shell name etc.

This may not be available by default in many linux machines. In this case, you need to install it manually.

users: Displays usernames of all users currently logged on the system.

grep: It is a powerful pattern searching tool to find information about a specific user from the system accounts file: /etc/passwd.

W Command: It(W) is a command-line utility that displays information about currently logged in users and what each user is doing.

last or lastb: Displays a list of last logged in users on the system. You can pass user names to display their login and hostname details.

lastlog: The lastlog command is used to find the details of a recent login of all users or of a given user.

File and directory commands

pwd The pwd(Present Working Directory) command is used to print the name of the present/current working directory starting from the root.

mkdir The mkdir(make directory) command allows users to create directories or folders.

The option ‘-p’ is used to create multiple directories or parent directories at once.

rmdir: The rmdir(remove directories) is used to remove empty directories. Can be used to delete multiple empty directories as well. Safer to use compared to rm -r FolderName . This command can also be forced to delete non-empty directories.

  1. Remove entire directory tree. This command is similar to rmdir a/b/c a/b a :

rm: The rm(remove) command is used to remove objects such as files, directories, symbolic links etc from the file system.

  1. Remove file: The rm command is used to remove or delete a file
  1. Remove file forcefully: The rm command with -f option is used for removal of file without prompting for confirmation.
  1. Remove directory: The rm command with -r option is used to remove the directory and its contents recursively.
  1. Remove directory forcefully: The rm command with -rf option is used to forcefully remove directory recursively.

touch: The touch command is is used to create, change and modify timestamps of a file without any content.

Create a new file: You can create a single file at a time using touch command. The file created is an empty file.

Create multiple files: You can create the multiple numbers of files at the same time.

Change access time: The touch command with a option is used to change the access time of a file.

Change modification time: The touch command with m option is used to change the modified time.

Use timestamp of other file: The touch command with r option is used to get timestamp of another file.

In the above example, we get the timestamp of file1 for file2.

Create file with Specific time: The touch command with ‘t’ option is used to create a file with specified time.

cat: The cat command is used to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.

View file contents: You can view contents of a single or more files by mentioning the filenames.

Since Linux is a multi-user operating system, it is necessary to provide security to prevent people from accessing each other’s confidential files. So Linux divides authorization into 2 levels,

Ownership: Each file or directory has assigned with 3 types of owners i. User: Owner of the file who created it. ii. Group: Group of users with the same access permissions to the file or directory. iii. Other: Applies to all other users on the system

Permissions: Each file or directory has following permissions for the above 3 types of owners.

i. Read: Give you the authority to open and read a file and lists its content for a directory.

ii. Write: Give you the authority to modify the contents of a file and add, remove and rename files stored in the directory.

iii. Execute: Give you the authority to run the program in Unix/Linux.

The permissions are indicated with below characters,

The above authorization levels represented in a diagram

There is a need to restrict own file/directory access to others.

Change access: The chmod command is used to change the access mode of a file. This command is used to set permissions (read, write, execute) on a file/directory for the owner, group and the others group.

There are 2 ways to use this command,

Absolute mode: The file permissions will be represented in a three-digit octal number.

The possible permissions types represented in a number format as below.

Permission Type Number Symbol
No Permission 0
Execute 1 –x
Write 2 -w-
Execute + Write 3 -wx
Read 4 r–
Read + Execute 5 r-x
Read + Write 6 rw-
Read + Write + Execute 7 rwx

Let’s update the permissions in absolute mode with an example as below,

Symbolic mode: In the symbolic mode, you can modify permissions of a specific owner unlike absolute mode.

The owners are represented as below,

Owner Description
u user/owner
g group
o other
a all

and the list of mathematical symbols to modify the file permissions as follows,

Operator Description
+ Adds permission
Removes the permission
= Assign the permission

Changing Ownership and Group: It is possible to change the the ownership and group of a file/directory using chown command.

Change group-owner only: Sometimes you may need to change group owner only. In this case, chgrp command need to be used

  1. Display network information: ifconfig command is used to display all network information(ip address, ports etc)

Test connection to a remote machine: Send an echo request to test connection of a remote machine.

Show IP Address: Display ip address of a currennt machine

Active ports: Shows active or listening ports

Find information about domain: whois command is used to find out information about a domain, such as the owner of the domain, the owner’s contact information, and the nameservers used by domain.

  1. Package description: The info command is used to display brief details about a package.
  1. Uninstall package: The remove command is used to remove or uninstall package name.

It is also possible to install package from local file named package_name.rpm.

  1. Synopsis: du command is used to check the information of disk usage of files and directories on a machine
  1. Disk usage of a directory: To find out the disk usage summary of a /home/ directory tree and each of its sub directories
  1. Disk usage in human readable format: To find out the disk usage in human readable format
  1. Total disk usage of a directory: To find out the total disk usage
  1. Total disk usage of all files and directories: To find out the total disk usage of files and directories
  1. Total disk usage of all files and directories upto certain depth: print the total for a directory only if it is N or fewer levels below the command
  1. Total disk usage with excluded files: To find out the total disk usage of files and directories, but excludes the files that matches given pattern.

System and Hardware information

  1. Print all information: uname is mainly used to print system information.
  1. Pattern search: The grep command is used to search patterns in files.

The find command is used to find or search files and directories by file name, folder name, creation date, modification date, owner and permissions etc and perform subsequent operations on them.

i. Search file with name:

ii. Search file with pattern:

iii. Search file with executable action:

iv. Search for empty files or directories:

The find command is used to search all empty folders and files in the entered directory or sub-directories.

v. Search for files with permissions:

The find command is used to find all the files in the mentioned directory or sub-directory with the given permissions

vi. Search text within multiple files:

  1. Whereis to locate binary or source files for a command: The whereis command in Linux is used to locate the binary, source, and manual page files for a command. i.e, It is used to It is used to find executables of a program, its man pages and configuration files.
  1. Locate to find files: The locate command is used to find the files by name. This command is faster compared to find command because it searches database for the filename instead of searching your filesystem.

SSH (Secure Shell) is a network protocol that enables secure remote connections between two systems.

  1. Connect remote machine using IP address or machine name: The remote server can be connected with local user name using either host name or IP address
  1. Connect remote machine using username: It is also possible specify a user for an SSH connection.
  1. :Connect remote machine using custom port By default, the SSH server listens for a connection on port 22. But you can also specify the custom port.
  1. Generate SSH keys using keygen: SSH Keygen is used to generate a key pair which consists of public and private keys to improve the security of SSH connections.
  1. Copying SSH keys to servers: For SSH authentication, ssh-copy-id command will be used to copy public key(id_rsa.pub) to server.
  1. Copy a File Remotely over SSH: SCP tool is used to securely copy files over the SSH protocol.
  1. Edit SSH Config File SSH server options customized by editing the settings in sshd_config file.
  1. Run commands on a remote server SSH commands can be executed on remote machine using the local machine.
  1. Restart SSH service: You need to restart the service in Linux after making changes to SSH configuration.

Vi editor is the most popular text editor from the early days of Unix. Whereas Vim(Vi IMproved) is an improved version of vi editor to be used in CLI (command line interface) for mainly text editing tasks in many configuration files. Some of the other alternatives are Elvis, Nvi, Nano, Joe, and Vile. It has two main operation modes,

  1. Command Mode: It allows the entry of commands to manipulate text.
  2. Entry mode(Or Insert mode): It allows typed characters on the keyboard into the current file.

1. Start with Vi Editor

You can create a new file or open an existing file using vi filename command.

Let’s see how do you create file, enter the content and leave the CLI by saving the changes.

  1. Create a new file named first.txt
  2. Press i to enter the insert mode
  3. Enter the text “Hello World!”
  4. Save the text and exit by pressing :wq! command
  5. Check the entered text

You can use arrow keys(left, right, up and down) to move the cursor on the terminal. But you can also other keys for this behavior.

These commands used to jump one word at a time

Jump to start or end of a line or next line

These commands used to jump starting or ending of a line or a next line.

These commands used to moves all sides of the screen

Paging and Scrolling

Paging is used to moves the cursor up or down through the text a full screen at a time. Whereas Scrolling happens line by line.

These commands places vi in entry mode from command mode. First, you need to be in command mode to use the below commands.


Популярные записи