{"id":17790222,"url":"https://github.com/sudheerj/linux-cheat-sheet","last_synced_at":"2025-03-16T13:31:46.544Z","repository":{"id":37271107,"uuid":"200079756","full_name":"sudheerj/Linux-cheat-sheet","owner":"sudheerj","description":"List of Linux commands","archived":false,"fork":false,"pushed_at":"2024-09-18T11:56:29.000Z","size":173,"stargazers_count":552,"open_issues_count":0,"forks_count":245,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-16T03:04:12.272Z","etag":null,"topics":["cheatsheet","linux","linuxcommand","ubuntu","vim"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudheerj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["sudheerj"],"custom":"https://buymeacoffee.com/sudheerj"}},"created_at":"2019-08-01T15:54:47.000Z","updated_at":"2025-03-12T12:10:19.000Z","dependencies_parsed_at":"2023-12-26T01:38:21.077Z","dependency_job_id":"17f12b30-5db6-4f77-ae63-8a2c30b85d94","html_url":"https://github.com/sudheerj/Linux-cheat-sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2FLinux-cheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2FLinux-cheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2FLinux-cheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudheerj%2FLinux-cheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudheerj","download_url":"https://codeload.github.com/sudheerj/Linux-cheat-sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243875202,"owners_count":20361969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","linux","linuxcommand","ubuntu","vim"],"created_at":"2024-10-27T10:41:42.682Z","updated_at":"2025-03-16T13:31:46.203Z","avatar_url":"https://github.com/sudheerj.png","language":null,"readme":"# Linux-cheat-sheet\n\n\u003e Click :star:if you like the project. Pull Request are highly appreciated. Follow me [@SudheerJonna](https://twitter.com/SudheerJonna) for technical updates.\n\n### Table of Contents\n\n---\n\n| No. | Topic                                                                   |\n| --- | ----------------------------------------------------------------------- |\n| 1   | [**User information**](#user-information)                               |\n| 2   | [**File and directory commands**](#file-and-directory-commands)         |\n| 3   | [**File permissions**](#file-permissions)                               |\n| 4   | [**Networking**](#networking)                                           |\n| 5   | [**Installing packages**](#installing-packages)                         |\n| 6   | [**Disk usage**](#disk-usage)                                           |\n| 7   | [**System and Hardware information**](#system-and-hardware-information) |\n| 8   | [**Search Files**](#search-files)                                       |\n| 9   | [**SSH**](#ssh)                                                         |\n| 10  | [**Vi/Vim-commands**](#vi/vim-commands)                                 |\n| 11  | [**Top/TaskManager Command**](#Top-Command)                             |\n| 12  | [**Kill Command**](#Kill-Command)                                       |\n| 13  | [**History Command**](#History-Command)                                 |\n| 14  | [**Curl Command**](#Curl-Command)                                       |\n\n### User Information\n\n1. **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.\n\n    1. Login name of the user\n    2. User terminal\n    3. Date \u0026 Time of login\n    4. Remote host name of the user\n\n   ```bash\n   $ who\n   sudheer :0 2019-08-04 01:21 (:0)\n   ```\n\n2. **whoami:** It display the system’s username\n\n   ```bash\n   $ whoami\n   sudheer\n   ```\n\n3. **id:** It display the user identification(the real and effective user and group IDs) information\n\n   ```bash\n   $ id\n   uid=1000(sj) gid=1000(sj) groups=1000(sj),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare)\n   ```\n4. **groups:** This command is used to display all the groups for which the user belongs to.\n\n   ```bash\n   $ group\n   sj: sj, adm, cdrom, sudo, dip, plugdev, lpadmin, lxd, sambashare\n   ```\n\n5. **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.\n\n   ```bash\n   $ finger\n   Login     Name       Tty      Idle  Login Time   Office     Office Phone\n   sj        sj        *:0             Aug 28 01:27 (:0)\n   ```\n\n   This may not be available by default in many linux machines. In this case, you need to install it manually.\n\n   ```bash\n   $ sudo apt install finger\n   ```\n6. **users:** Displays usernames of all users currently logged on the system.\n\n   ```bash\n   $ users\n   sj\n   ```\n\n7. **grep:** It  is a powerful pattern searching tool to find information about a specific user from the system accounts file: /etc/passwd.\n\n    ```bash\n    $ grep -i sj /etc/passwd\n    sj:x:1000:1000:sj,,,:/home/sj:/bin/bash\n    ```\n\n8. **W Command:** It(W) is a command-line utility that displays information about currently logged in users and what each user is doing.\n\n    ```bash\n    w [OPTIONS] [USER]\n\n    Example:\n    w\n     18:45:04 up  2:09,  1 user,  load average: 0.09, 0.07, 0.02\n    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT\n    sj       :0       :0               01:27   ?xdm?   1:14   0.01s /usr/lib/gdm3/g\n    ```\n\n9. **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.\n\n    ```bash\n    last [options] [username...] [tty...]\n\n    Example:\n\n    last\n    sj       :0           :0               Fri Aug 28 01:27    gone - no logout\n    reboot   system boot  5.4.0-29-generic Fri Aug 28 01:27   still running\n    sj       :0           :0               Wed Jul 29 11:46 - crash (29+13:40)\n    reboot   system boot  5.4.0-29-generic Wed Jul 29 11:45   still running\n    sj       :0           :0               Thu May 14 21:04 - crash (75+14:41)\n    reboot   system boot  5.4.0-29-generic Thu May 14 21:03   still running\n\n    wtmp begins Thu May 14 21:03:56 2020\n    ```\n\n10. **lastlog:** The `lastlog` command is used to find the details of a recent login of all users or of a given user.\n\n    ```cmd\n    $ lastlog\n\n    Username         Port     From             Latest\n    root                                       **Never logged in**\n    daemon                                     **Never logged in**\n    bin                                        **Never logged in**\n    sys                                        **Never logged in**\n    sync                                       **Never logged in**\n    games                                      **Never logged in**\n    man                                        **Never logged in**\n    lp                                         **Never logged in**\n    mail                                       **Never logged in**\n    news                                       **Never logged in**\n    ```\n\n   **[⬆ Back to Top](#table-of-contents)**\n\n### File and directory commands\n\n1. **pwd** The pwd(Present Working Directory) command is used to print the name of the present/current working directory starting from the root.\n   ```bash\n   $ pwd\n   /home/sj/Desktop/Linux\n   ```\n\n2. **ls**: The `ls` command is used to list files or directories. It also accepts some flags or options that changes how files or directories are listed in your terminal.\n\n    ```bash\n     Syntax:\n     ls [flags] [directory]\n\n     Example:\n     $ ls\n     bin dev lib libx32 mnt  \n\n     //Listing files \u0026 directories with time in a rever order\n     $ ls -ltr\n     drwxr-xr-x 2 sj sj 4096 May 14  2020 Videos\n     drwxr-xr-x 2 sj sj 4096 May 14  2020 Templates\n     drwxr-xr-x 2 sj sj 4096 May 14  2020 Public\n\n     //Home directory\n     $ ls ~\n     Desktop    Downloads  Pictures  Sudheer    test   test.txt\n     Documents  Music      Public    Templates  test1  Videos\n    ```\n\n    Below are the list of possible options for `ls` command,\n\n    ```cmd\n    -a Show all (including hidden)\n    -R Recursive list\n    -r Reverse order\n    -t Sort by last modified\n    -S Sort by file size\n    -l Long listing format\n    -1 One file per line\n    -m Comma-­sep­arated output\n    -Q Quoted output\n    ```\n\n3. **mkdir** The mkdir(make directory) command allows users to create directories or folders.\n\n   ```bash\n   $ mkdir ubuntu\n   $ ls\n   ubuntu\n   ```\n\n   The option '-p' is used to create multiple directories or parent directories at once.\n\n   ```bash\n   $ mkdir -p dir1/dir2/dir3\n   $ cd dir1/dir2/dir3\n   ~/Desktop/Linux/dir1/dir2/dir3$\n   ```\n\n4. **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.\n\n   1. Remove empty directory:\n\n   ```bash\n   rmdir FolderName\n   ```\n\n   2. Remove multiple directories:\n\n   ```bash\n   rmdir FolderName1 FolderName2 FolderName3\n   ```\n\n   3. Remove non-empty directories:\n\n   ```bash\n   rmdir FolderName1 --ignore-fail-on-non-empty\n   ```\n\n   4. Remove entire directory tree. This command is similar to `rmdir a/b/c a/b a`:\n\n   ```bash\n   rmdir -p a/b/c\n   ```\n\n5. **rm**: The rm(remove) command is used to remove objects such as files, directories, symbolic links etc from the file system.\n   1. Remove file: The rm command is used to remove or delete a file\n   ```bash\n   rm file_name\n   ```\n   2. Remove file forcefully: The rm command with -f option is used for removal of file without prompting for confirmation.\n   ```bash\n   rm -f filename\n   ```\n   3. Remove directory: The rm command with -r option is used to remove the directory and its contents recursively.\n   ```bash\n   rm -r myDir\n   ```\n   4. Remove directory forcefully: The rm command with -rf option is used to forcefully remove directory recursively.\n   ```bash\n   rm -rf myDir\n   ```\n6. **touch**: The touch command is is used to create, change and modify timestamps of a file without any content.\n   1. **Create a new file:** You can create a single file at a time using touch command. The file created is an empty file.\n       ```bash\n       touch file_name\n       ```\n   2. **Create multiple files:** You can create the multiple numbers of files at the same time.\n       ```bash\n       touch file1_name file2_name file3_name\n       ```\n   3. **Change access time:** The touch command with `a` option is used to change the access time of a file.\n       ```bash\n       touch -a file_name\n       ```\n   4. **Change modification time:** The touch command with `m` option is used to change the modified time.\n       ```bash\n       touch -m file_name\n       ```\n   5. **Use timestamp of other file:** The touch command with `r` option is used to get timestamp of another file.\n       ```bash\n       touch -r file2 file1\n       ```\n\n       In the above example, we get the timestamp of file1 for file2.\n\n   6. **Create file with Specific time:** The touch command with 't' option is used to create a file with specified time.\n       ```bash\n       touch -t 1911010000 file_name\n       ```\n7. **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.\n     ```bash\n     $ cat [OPTION] [FILE]...\n     ```\n   1. **Create a file:** Used to create a file with specific name, content and press exit using `CTRL + D`\n       ```bash\n       cat \u003e file_name1.txt\n       Hello, How are you?\n       ```\n   2. **View file contents:** You can view contents of a single or more files by mentioning the filenames.\n\n       ```bash\n       cat file_name1 file_name2\n       ```\n   3. **More \u0026 Less options:** If a file having a large number of content that won’t fit in the output terminal then `more` \u0026 `less` options can be used to indiate additional content.\n\n       ```bash\n       cat file_name1.txt | more\n       cat file_name1.txt | less\n       ```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### File permissions\nSince Linux is a multi-user operating system, it is necessary to provide security to prevent people from accessing each other’s confidential files.\nSo Linux divides authorization into 2 levels,\n\n1. **Ownership:**\nEach file or directory has assigned with 3 types of owners\ni. **User:** Owner of the file who created it.\nii. **Group:** Group of users with the same access permissions to the file or directory.\niii. **Other:** Applies to all other users on the system\n\n2. **Permissions:**\nEach file or directory has following permissions for the above 3 types of owners.\n\n    i.   **Read:** Give you the authority to open and read a file and lists its content for a directory.\n\n    ii.  **Write:** Give you the authority to modify the contents of a file and add, remove and rename files stored in the directory.\n\n    iii. **Execute:** Give you the authority to run the program in Unix/Linux.\n\n     The permissions are indicated with below characters,\n\n         r = read permission\n\n         w = write permission\n\n         x = execute permission\n\n         \\- = no permission\n\n    The above authorization levels represented in a diagram\n\n\u003cimg src=\"https://github.com/sudheerj/Linux-cheat-sheet/blob/master/images/permissions.png\" width=\"600\" height=\"400\"\u003e\n\nThere is a need to restrict own file/directory access to others.\n\n**Change access:**\nThe `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.\n\n```cmd\nchmod [reference][operator][mode] file...\n\nExample\nchmod ugo-rwx test.txt\n```\n\nThere are 2 ways to use this command,\n\n1. **Absolute mode:**\nThe file permissions will be represented in a three-digit octal number.\n\n     The possible permissions types represented in a number format as below.\n\n     | Permission Type | Number |  Symbol |\n     | ------------- | ----- | ----- |\n     | No Permission | 0 | --- |\n     | Execute | 1 | --x |\n     | Write | 2 | -w- |\n     | Execute + Write | 3 | -wx |\n     | Read | 4 | r-- |\n     | Read + Execute | 5 | r-x |\n     | Read + Write | 6 | rw- |\n     | Read + Write + Execute | 7 | rwx |\n\n\nLet's update the permissions in absolute mode with an example as below,\n\n   ```cmd\n    chmode 764 test.txt\n   ```\n\n2. **Symbolic mode:**\nIn the symbolic mode, you can modify permissions of a specific owner unlike absolute mode.\n\n    The owners are represented as below,\n\n     | Owner | Description |\n     | ----- | ----- |\n     | u | user/owner |\n     | g | group |\n     | o | other |\n     | a | all |\n\n    and the list of mathematical symbols to modify the file permissions as follows,\n\n     | Operator | Description |\n     | ------------- | ----- |\n     | + | Adds permission |\n     | - | Removes the permission |\n     | = | Assign the permission |\n\n**Changing Ownership and Group:**\nIt is possible to change the the ownership and group of a file/directory using `chown` command.\n\n```cmd\nchown user filename\nchown user:group filename\n\nExample:\nchown John test.txt\nchown John:Admin test.txt\n```\n\n**Change group-owner only:**\nSometimes you may need to change group owner only. In this case, chgrp command need to be used\n\n```cmd\nchgrp group_name filename\n\nExample:\nsudo chgrp Administrator test.txt\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Networking\n\n1.  **Display network information:** `ifconfig` command is used to display all network information(ip address, ports etc)\n\n```cmd\nifconfig -a\n```\n\n2.  **Test connection to a remote machine:** Send an echo request to test connection of a remote machine.\n\n    ```cmd\n    ping \u003cip-address\u003e or hostname\n\n    Example:\n    ping 10.0.0.11\n    ```\n\n3.  **Show IP Address:** Display ip address of a currennt machine\n\n    ```cmd\n    hostname -I\n    (OR)\n    ip addr show\n    ```\n\n4.  **Active ports:** Shows active or listening ports\n\n     ```cmd\n     netstat -pnltu\n     ```\n\n5.  **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.\n\n    ```cmd\n    whois [domain]\n\n    Example:\n    whois google.com\n    ```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Installing packages\n\n1. **Install package:**\n\n```cmd\nyum install package_name\n```\n\n2. **Package description:**\nThe info command is used to display brief details about a package.\n\n```cmd\nyum info package_name\n```\n\n3. **Uninstall package:**\nThe remove command is used to remove or uninstall package name.\n```cmd\nyum remove package_name\n```\n4. **Install package from local file:**\n\nIt is also possible to install package from local file named package_name.rpm.\n\n```cmd\nrpm -i package_name.rpm\n```\n\n5. **Install from source code:**\n\n```cmd\ntar zxvf sourcecode.tar.gz\ncd sourcecode\n./configure\nmake\nmake install\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Disk usage\n\n1.  **Synopsis:** `du` command is used to check the information of disk usage of files and directories on a machine\n\n```cmd\ndu [OPTION]... [FILE]...\n```\n\n2.  **Disk usage of a directory:** To find out the disk usage summary of a /home/ directory tree and each of its sub directories\n\n```cmd\ndu  /home/\n```\n\n3.  **Disk usage in human readable format:** To find out the disk usage in human readable format\n\n```cmd\ndu  -h /home/\n```\n\n4.  **Total disk usage of a directory:** To find out the total disk usage\n\n```cmd\ndu  -sh /home/\n```\n\n5.  **Total disk usage of all files and directories:** To find out the total disk usage of files and directories\n\n```cmd\ndu  -ah /home/\n```\n\n6.  **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\n\n```cmd\ndu  -ah --max-depth 2 /home/\n```\n\n7.  **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.\n\n```cmd\ndu -ah --exclude=\"*.txt\" /home/\n```\n\n8.  **Help:** This command gives information about `du`\n\n```cmd\ndu  --help\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### System and Hardware information\n\n1.  **Print all information**: `uname` is mainly used to print system information.\n\n```bash\n$ uname -a\n```\n\n2.  **Print kernel name**:\n\n```bash\n$ uname -s\n```\n\n3.  **Print kernel release**:\n\n```bash\n$ uname -r\n```\n\n4.  **Print Architecture**:\n\n```bash\n$ uname -m\n```\n\n5.  **Print Operating System**:\n\n```bash\n$ uname -o\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Search Files\n\n1. **Pattern search:**\nThe `grep` command is used to search patterns in files.\n\n```cmd\ngrep pattern files\ngrep -i // Case sensitive\ngrep -r // Recursive\ngrep -v // Inverted search\n\nExample:\ngrep \"^hello\" test.txt // Hello John\ngrep -i \"hELLo\" text.txt // Hello John\n```\n\n2. **Find files and directories:**\n\nThe `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.\n\ni. **Search file with name:**\n\n```cmd\nfind ./directory_name -name file_name\n\nExample:\nfind ./test -name test.txt // ./test/test.txt\n```\n\nii. **Search file with pattern:**\n\n```cmd\nfind ./directory_name -name file_pattern\n\nExample:\nfind ./test -name *.txt // ./test/test.txt\n```\n\niii. **Search file with executable action:**\n\n```cmd\nfind ./directory_name -name file_name -exec command\n\nExample:\nfind ./test -name test.txt -exec rm -i {} \\; // Search file and delete it after confirmation\n```\n\niv. **Search for empty files or directories:**\n\nThe find command is used to search all empty folders and files in the entered directory or sub-directories.\n\n```cmd\nfind ./directory_name -empty\n\nExample:\nfind ./test -empty\n//./test/test1\n//./test/test2\n//./test/test1.txt\n```\n\nv. **Search for files with permissions:**\n\nThe find command is used to find all the files in the mentioned directory or sub-directory with the given permissions\n\n```cmd\nfind ./directory_name -perm permission_code\n\nExample:\nfind ./test -perm 664\n```\n\nvi. **Search text within multiple files:**\n\n```cmd\nfind ./ -type f -name file_pattern -exec grep some_text  {} \\;\n\nExample:\nfind ./ -type f -name \"*.txt\" -exec grep 'World'  {} \\; // Hello World\n```\n\n3. **Whereis to locate binary or source files for a command:**\nThe 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.\n\n```cmd\nwhereis command_name\n\nExample:\nwhereis netstat //netstat:  /bin/netstat /usr/share/man/man8/netstat.8.gz(i.e, executable and location of its man page)\n```\n\n4. **Locate to find files:**\nThe 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.\n\n```cmd\nlocate [OPTION] PATTERN\n\nExample:\nlocate \"*.txt\" -n 10 // 10 file search results ending with .txt extension\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### SSH\n\nSSH (Secure Shell) is a network protocol that enables secure remote connections between two systems.\n\n1.  **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\n\n```cmd\nssh \u003chost-name\u003e or \u003cip-address\u003e\n\nExample:\nssh 192.111.66.100\nssh test.remoteserver.com\n```\n\n2.  **Connect remote machine using username:** It is also possible specify a user for an SSH connection.\n\n```cmd\nssh username@hostname_or_ip-address\n\nExample:\nssh john@192.0.0.22\nssh john@test.remoteserver.com\n```\n\n3.  **: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.\n\n```cmd\nssh \u003chost-name\u003e or \u003cip-address\u003e -p port_number\n\nExample:\nssh test.remoteserver.com -p 3322\n```\n\n4.  **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.\n\n```cmd\nssh-keygen -t rsa\n```\n\n5.  **Copying SSH keys to servers:** For SSH authentication, `ssh-copy-id` command will be used to copy public key(id_rsa.pub) to server.\n\n```cmd\nssh-copy-id hostname_or_IP\n```\n\n6.  **Copy a File Remotely over SSH:** SCP tool is used to securely copy files over the SSH protocol.\n\n```cmd\nscp fileName user@remotehost:destinationPath\n\nExample:\nscp test.txt test@10.0.0.64:/home/john/Desktop\n```\n\n7.  **Edit SSH Config File** SSH server options customized by editing the settings in `sshd_config` file.\n\n```cmd\nsudo vim /etc/ssh/sshd_config\n```\n\n8.  **Run commands on a remote server** SSH commands can be executed on remote machine using the local machine.\n\n```cmd\nssh test.remoteserver.com mkdir NewDirectoryName // Creating directory on remote machine\n```\n\n9.  **Restart SSH service:** You need to restart the service in Linux after making changes to SSH configuration.\n\n```cmd\nsudo ssh service restart\n(or)\nsudo sshd service restart\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Vi/Vim-commands\n\nVi 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.\nIt has two main operation modes,\n\n1.  **Command Mode:** It allows the entry of commands to manipulate text.\n2.  **Entry mode(Or Insert mode):** It allows typed characters on the keyboard into the current file.\n\n#### 1. Start with Vi Editor\n\nYou can create a new file or open an existing file using `vi filename` command.\n\n```cmd\n vi \u003cfilename_NEW\u003e or \u003cfilename_EXISTING\u003e // Create a new file or open an existing file\n\n Example:\n vi first.txt\n```\n\nLet's see how do you create file, enter the content and leave the CLI by saving the changes.\n\n1.  Create a new file named `first.txt`\n2.  Press `i` to enter the insert mode\n3.  Enter the text \"Hello World!\"\n4.  Save the text and exit by pressing `:wq!` command\n5.  Check the entered text\n\n#### 2. Cursor movement\n\n    These commands will be used in Command mode.\n\n##### Move cursor\n\nYou 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.\n\n```cmd\n h        # Move left\n j        # Move down\n k        # Move up\n l        # Move right\n```\n\n##### Jump one word\n\nThese commands used to jump one word at a time\n\n```cmd\nw        # Jump forwards to the start of a word\nW        # Jump forwards to the start of a WORD\ne        # Jump forwards to the start of a word\nE        # Jump forwards to the start of a WORD\nb        # Jump backwords to the start of a word\nB        # Jump backwords to the start of a WORD\n```\n\n##### Jump to start or end of a line or next line\n\nThese commands used to jump starting or ending of a line or a next line.\n\n```cmd\n^        # Jump to the start of a current line\n$        # Jump to the end of a current line\nreturn   # Jump to the start of a next line\n```\n\n##### Move sides\n\nThese commands used to moves all sides of the screen\n\n```cmd\nBackspace # Move cursor one character to the left\nSpacebar  # Move cursor one character to the right\nH(High)   # Move cursor to the top of the screen\nM(Middle) # Move cursor to the middle of the screen\nL(Low)    # Move cursor to the bottom of the screen\n```\n\n##### Paging and Scrolling\n\nPaging is used to moves the cursor up or down through the text a full screen at a time. Whereas Scrolling happens line by line.\n\n```cmd\nCtrl + f     # move forward one full screen\nCtrl + b     # move backward one full screen\nCtrl + d     # move forward half a screen\nCtrl + u     # move backward half a screen\n```\n\n##### Inserting Text\n\nThese commands places vi in entry mode from command mode. First, you need to be in command mode to use the below commands.\n\n###### Insert\n\n```cmd\ni    # Insert text to the left of the cursor\nI    # Insert text at the beginning of a line\nESC  # Exit insert mode\n```\n\n###### Append\n\n```cmd\na    # Insert(or Append) text to the right of the cursor\nA    # Insert(or Append) text at the end of a line\n```\n\n###### Open a line\n\n```cmd\no    # Open a line below the current cursor position\nO    # open a line above the current cursor position\n```\n\n##### Editing Text\n\n1. **Change word:** Change word/part of word to right of cursor\n\n    ```cmd\n    cw\n    ```\n\n2. **Change line** Change entire line\n\n    ```cmd\n    cc\n    ```\n\n3. **Change line from specific character** Change from cursor to end of line\n\n    ```cmd\n    C\n    ```\n\n##### Deleting Text\n\n1. **Deleting One Character:** Position the cursor over the character to be deleted and type x\n\n    ```cmd\n    x\n    X       //To delete one character before the cursor\n    ```\n2. **Deleting a Word:** Position the cursor at the beginning of the word and type dw\n\n    ```cmd\n    dw\n    ```\n3. **Deleting a Line:** Position the cursor anywhere on the line and type dd.\n\n    ```cmd\n    dd\n    ```\n\n##### Cut, Copy \u0026 Paste\n\n   Copy, Cut and Paste operations can be done in either Normal or visual Mode.\n\n1. **Normal mode:** This mode appears on click of `Esc` key.\n\n   **Copy** There are various copy or yank commands based on amount of text to be copied. The `y` character is used to perform this operation.\n\n   i. Copy an entire line: Just place the cursor at the beginning of the line and type `yy`\n\n   ```cmd\n   yy\n   ```\n\n   ii.Copy three lines: Just place the cursor from where to start copying and type `3yy`\n\n   ```cmd\n   3yy\n   ```\n\n   iii. Copy word with trailing whitespace: Place the cursor at the beginning of the word and type `yaw`\n\n   ```cmd\n   yaw\n   ```\n\n   iv. Copy word without trailing whitespace: Place the cursor at the beginning of the word and type `yiw`.\n\n   ```cmd\n   yiw\n   ```\n\n   v. Copy right of the cursor: Copy text right of the cursor to the end of line using `y$` command\n\n   ```cmd\n   y$\n   ```\n\n   vi.Copy left of the cursor: Copy text left of the cursor to the end of line using `y^` command\n\n   ```cmd\n   y^\n   ```\n\n   vii. Copy text between the cursor and character: Copy text between the cursor and specified character.\n\n   ```cmd\n   ytx(Copy until x and x is excluded)\n   yfx(Copy until x and x is included)\n   ```\n\n   **Cut** There are various cutting or deleting commands based on amount of text to be deleted. The `d` character is used to perform this operation.\n\n   i. Cut entire line: Cut the entire line where the cursor is located\n\n   ```cmd\n   dd\n   ```\n\n   ii.Cut three lines: Cut the three lines starting from the place where cursor is located\n\n   ```cmd\n   3dd\n   ```\n\n   iii.Cut right of the cursor: Cut the text from the right of the cursor till the end of line\n\n   ```cmd\n   d$\n   ```\n\n   iii.Cut left of the cursor: Cut the text from the left of the cursor till the beginning of line\n\n   ```cmd\n   d^\n   ```\n\n   **Paste** This operation is performed using `p` command to paste the selected text\n\n   ```cmd\n   p\n   ```\n\n2. **Visual Mode** In this mode, first select the text using below keys\n\n    1. v (lowercase): To select individual characters\n    2. V (uppercase): To select the entire line\n    3. Ctrl+v: To select by block\n\n    and perform copy, cut and paste operations using y,d and p commands\n\n##### Exiting\n\n    These commands are used to exit from the file.\n    ```cmd\n    :w\t    # Write (save) the file, but don't exit\n    :wq\t    # Write (save) and quit\n    :wq!\t# Force write (save) and quit\n    :q\t    # Quit, but it fails if anything has changed\n    :q!\t    # Quit and throw away for any changes\n    ```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n\n### Top/TaskManager Command\n\ntop: The `top` command provides dynamic real-time viewing of the running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.\n\n#### options\n| Option | Description                              |\n|--------|------------------------------------------|\n| -b     | Batch mode                               |\n| -n     | Number of iterations                     |\n| -s     | Sec delay between updates                |\n| -d     | Delay time in seconds                    |\n| -p     | Monitor process ID                       |\n\n```cmd\ntop [options]\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Kill Command\nkill: The kill command sends a signal to a process. Useful when trying to terminate a hung process.\n\n**options:**\n| Option | Description                                   |\n|--------|-----------------------------------------------|\n| -s     | Specify the signal to send (e.g., -s SIGTERM) |\n| -l     | List available signals                        |\n| -n     | Process group ID                              |\n| -signal| Specify the signal using signal name or number|\n| -p     | Specify the process ID to be signaled         |\n\n#### kill Command Options\n\n1. -s Option\n Specifies the signal to send to the process. Use in the format -s SIGNAL. For example:\n\n```cmd\nkill -s SIGTERM \u003cprocess_id\u003e\n```\n\n2. -l Option\nLists available signals that can be used with the kill command. This option does not send any signal; it only displays a list of signals.\n\n```cmd\nkill -l\n```\n3. -n Option\nSpecifies the process group ID. This option allows you to send a signal to a process group rather than an individual process.\n\n```cmd\nkill -n \u003cprocess_group_id\u003e\n```\n4. -signal Option\nSpecifies the signal to send using either the signal name or number directly.\n\n```cmd\nkill -TERM \u003cprocess_id\u003e\n```\n5. -p Option\nSpecifies the process ID to be signaled. Use in the format -p \u003cprocess_id\u003e.\n\n```cmd\nkill -p \u003cprocess_id\u003e\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### History Command Options\nThe history command shows a list of previously issued commands.\n\n#### history Command Options\n| Option         | Description                                                 |\n|----------------|-------------------------------------------------------------|\n| `-c`           | Clears the entire command history.                          |\n| `-d offset`    | Deletes the history entry at the specified offset.          |\n| `-a`           | Appends the current session's history to the history file.  |\n| `-r`           | Reads the history file and appends entries to the session.  |\n| `-n`           | Prevents command numbers from being displayed.              |\n| `-w`           | Writes the current session's history to the history file.   |\n| `-s \"\u003ccommand\u003e\"| Appends the specified entry to the end of the history list. |\n| `-p offset`    | Prints the history entry at the specified offset.           |\n| `-f file`      | Reads history entries from the specified file.              |\n\n1. -c Option\nClears the entire command history.\n```cmd\nhistory -c\n```\n\n2. -d offset Option\nDeletes the history entry at the specified offset.\n\n```cmd\nhistory -d \u003coffset\u003e\n```\n\n3. -a Option\nAppends the current session's history to the history file.\n\n```cmd\nhistory -a\n```\n\n4. -r Option\nReads the history file and appends the entries to the current session's history.\n\n```cmd\nhistory -r\n```\n\n5. -n Option\nPrevents command numbers from being displayed when using the history command.\n\n```cmd\nhistory -n\n```\n6. -w Option\nWrites the current session's history to the history file.\n\n```cmd\nhistory -w\n```\n\n7. -s Option\nAppends the specified entry to the end of the history list.\n\n```cmd\nhistory -s \"\u003ccommand\u003e\"\n```\n\n8. -p Option\nPrints the history entry at the specified offset.\n\n```cmd\nhistory -p \u003coffset\u003e\n```\n\n9. -f file Option\nReads history entries from the specified file and appends them to the history list.\n\n```cmd\nhistory -f \u003cfile\u003e\n```\n\n\n**[⬆ Back to Top](#table-of-contents)**\n\n### Curl Command\n\nCurl: The curl command transfers data to or from a server. It supports dozens of protocols, including HTTP, HTTPS, FTP, SFTP, Telnet, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3, RTSP and RTMP.\n\n**Options**\n\n| Option                     | Description                                             |\n|----------------------------|---------------------------------------------------------|\n| `-X, --request \u003ccommand\u003e`  | Specify the HTTP request method (GET, POST, etc.).      |\n| `-H, --header \u003cheader\u003e`    | Pass custom headers to the request.                     |\n| `--data \u003cdata\u003e`            | HTTP POST data.                                         |\n| `--data-urlencode \u003cdata\u003e`  | URL encode the POST data.                               |\n| `--form \u003cname=content\u003e`    | Specify multipart/form-data POST data.                  |\n| `-d, --data-raw \u003cdata\u003e`    | Send data as-is without any encoding.                   |\n| `-i, --include`            | Include HTTP headers in the output.                     |\n| `--url \u003curl\u003e`              | Specify the URL to send the request to.                 |\n| `-o, --output \u003cfile\u003e`      | Write output to a file instead of stdout.               |\n| `-O, --remote-name`        | Save the file with the same name as in the URL.         |\n| `-L, --location`           | Follow redirects.                                       |\n| `--user \u003cuser:password\u003e`   | Specify the user and password for server authentication.|\n| `-u, --user-agent \u003cagent\u003e` | Set the user-agent string.                              |\n| `--cookie \u003cdata\u003e`          | Send cookies from string/file.                          |\n| `--cookie-jar \u003cfile\u003e`      | Save cookies to a file after receiving them.            |\n| `--compressed`             | Request compressed response.                            |\n| `-v, --verbose`            | Make the operation more talkative for debugging.        |\n| `-h, --help`               | Display help information.                               |\n\n1. Basic GET Request:\nSends a simple GET request to the specified URL.\n\n```cmd\ncurl http://example.com\n```\n\n2. Specify Request Method:\nSpecifies a request method other than the default GET.\n\n```cmd\ncurl -X POST http://example.com\n```\n3. Include Headers:\n\nIncludes custom headers in the request.\n\n```cmd\ncurl -H \"Content-Type: application/json\" http://example.com\n```\n4. Send POST Data:\nSends data as POST request payload.\n\n```cmd\ncurl -X POST --data \"key1=value1\u0026key2=value2\" http://example.com\n```\n\n5. Save Output to File:\nWrites the output to a specified file.\n\n```cmd\ncurl -o output.html http://example.com\n```\n6. Download File:\nDownloads a file and saves it with the same name as in the URL.\n\n```cmd\ncurl -O http://example.com/file.zip\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n","funding_links":["https://github.com/sponsors/sudheerj","https://buymeacoffee.com/sudheerj"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudheerj%2Flinux-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudheerj%2Flinux-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudheerj%2Flinux-cheat-sheet/lists"}