└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # All Useful Linux Commands In One Place 2 | 3 | This whole repository is created to track all the useful linux commands in one place. Created for my own use but you can also star this repository to keep a track on this. 4 | 5 | ### Table of Contents 6 | 7 | --- 8 | 9 | | No. | Topic | 10 | | --- | ----------------------------------------------------------------------- | 11 | | 1 | [**General Commands**](#General-commands) | 12 | | 2 | [**File Management Commands**](#File-management-commands) | 13 | | 3 | [**Text Processing**](#Text-processing) | 14 | | 4 | [**Permission Based Commands**](#Permission-commands) | 15 | | 5 | [**Networking Commands**](#Networking-commands) | 16 | | 6 | [**Package Management Commands**](#managing-packages) | 17 | | 7 | [**Memory Usage Commands**](#Memory-usage) | 18 | | 8 | [**System and Hardware information**](#system-and-hardware-information) | 19 | | 9 | [**System**](#system) | 20 | 21 | ### General Commands 22 | 23 | 1. **w:** w displays information about currently logged in users and what each user is doing. 24 | 25 | ```bash 26 | $ w 27 | 23:35:01 up 2:29, 1 user, load average: 0.72, 1.07, 1.04 28 | USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT 29 | nirjas :1 :1 21:04 ?xdm? 34:58 0.01s /usr/lib 30 | ``` 31 | 32 | 2. **who** Shows information about currently logged in user. 33 | 34 | ```bash 35 | $ who 36 | nirjas :1 2021-11-01 21:04 (:1) 37 | ``` 38 | 39 | Here, from left, 40 | nirjas - Login Name of the User
41 | :1 - User terminal
42 | 2021-11-01 21:04 - Date & Time of login
43 | 44 | 3. **whoami:** Shows the system’s username 45 | 46 | ```bash 47 | $ whoami 48 | nirjas 49 | ``` 50 | 51 | 4. **id:** This command is used to find out user and group names and numeric ID's (UID or group ID) of the current user or any other user in the server. 52 | 53 | ```bash 54 | $ id 55 | uid=1000(nirjas) gid=1000(nirjas) groups=1000(nirjas),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),132(lxd),133(sambashare) 56 | ``` 57 | 58 | 5. **groups:** This command is used to display all the groups for which the user belongs to. 59 | 60 | ```bash 61 | $ groups 62 | nirjas adm cdrom sudo dip plugdev lpadmin lxd sambashare 63 | ``` 64 | 65 | 6. **users:** Displays usernames of all users currently logged on the system. 66 | 67 | ```bash 68 | $ users 69 | nirjas 70 | ``` 71 | 72 | 7. **last:** Displays a list of all last logged in users. The list can be huge according to the number of user logins. 73 | 74 | ```bash 75 | $ last 76 | nirjas :1 :1 Mon Nov 1 21:04 gone - no logout 77 | reboot system boot 5.13.0-20-generi Mon Nov 1 15:06 still running 78 | nirjas :1 :1 Mon Nov 1 20:30 - crash (-5:24) 79 | reboot system boot 5.13.0-20-generi Mon Nov 1 20:30 still running 80 | nirjas :1 :1 Mon Nov 1 23:53 - down (-3:24) 81 | reboot system boot 5.13.0-20-generi Mon Nov 1 23:53 - 20:29 (-3:23) 82 | nirjas :1 :1 Sun Oct 31 23:31 - down (01:56) 83 | reboot system boot 5.13.0-20-generi Sun Oct 31 23:30 - 01:27 (01:56) 84 | ``` 85 | 86 | 8. **lastlog:** This command is used to find the details of a recent login of all users or a particular user pass through as a flag. 87 | 88 | ```bash 89 | $ lastlog 90 | Username Port From Latest 91 | root **Never logged in** 92 | daemon **Never logged in** 93 | bin **Never logged in** 94 | sys **Never logged in** 95 | sync **Never logged in** 96 | games **Never logged in** 97 | man **Never logged in** 98 | lp **Never logged in** 99 | mail **Never logged in** 100 | news **Never logged in** 101 | ``` 102 | 103 | 9. **Man:** This command shows the documentation of every command of linux. 104 | 105 | ```bash 106 | $ man ls 107 | ``` 108 | 109 | 10. **Date:** Shows date 110 | 111 | ```bash 112 | $ date 113 | Mon Nov 1 11:57:01 PM +06 2021 114 | ``` 115 | 116 | 11. **History:** History command shows all the previously used terminal commands in a list. 117 | 118 | ```bash 119 | $ history 120 | 1 ls 121 | 2 lspci 122 | 3 lsusb 123 | 4 sudo lspci 124 | 5 sudo apt-get update 125 | 6 sudo apt-get upgrade 126 | 7 lspci 127 | ``` 128 | 129 | 12. **whatis:** Whatis shows a short particular information about a command. 130 | 131 | ```bash 132 | $ whatis wget 133 | wget (1) - The non-interactive network downloader. 134 | ``` 135 | 136 | 13. **whereis:** Shows the location of binary, source and manual files for commands. 137 | 138 | ```bash 139 | $ whereis ls 140 | ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz 141 | ``` 142 | 143 | 14. **alias:** Rename a long repitive command with a short name. For example you can make the command ls -la to any of your suitable name like below example. Then you can use that name to use the command. 144 | 145 | ```bash 146 | $ ls -la 147 | drwxr-xr-x 8 nirjas nirjas 4096 Nov 2 11:25 . 148 | drwxr-xr-x 4 nirjas nirjas 4096 Nov 2 10:58 .. 149 | -rw------- 1 nirjas nirjas 765 Nov 2 13:26 .bash_history 150 | -rw-r--r-- 1 nirjas nirjas 220 Apr 18 2019 .bash_logout 151 | -rw-r--r-- 1 nirjas nirjas 3564 Oct 27 16:56 .bashrc 152 | 153 | $ alias nr="ls -la" 154 | $ nr 155 | drwxr-xr-x 8 nirjas nirjas 4096 Nov 2 11:25 . 156 | drwxr-xr-x 4 nirjas nirjas 4096 Nov 2 10:58 .. 157 | -rw------- 1 nirjas nirjas 765 Nov 2 13:26 .bash_history 158 | -rw-r--r-- 1 nirjas nirjas 220 Apr 18 2019 .bash_logout 159 | -rw-r--r-- 1 nirjas nirjas 3564 Oct 27 16:56 .bashrc 160 | ``` 161 | 162 | To unalias type, 163 | 164 | `unalias ` 165 | 166 | ```bash 167 | $ unalias nr 168 | ``` 169 | 170 | 15. **clear:** Clears the terminal 171 | 172 | ```bash 173 | $ clear 174 | ``` 175 | 176 | **[⬆ Back to Top](#table-of-contents)** 177 | 178 | ### File Management Commands 179 | 180 | 1. **pwd** The pwd(Present Working Directory) command is used to show current working directory. 181 | 182 | ```bash 183 | $ pwd 184 | /home/nirjas 185 | ``` 186 | 187 | 2. **ls**: The ls command is used to list directories and files. 188 | 189 | 1. Basic command to list files and directories exclusing hidden files: 190 | 191 | ```bash 192 | $ ls 193 | ``` 194 | 195 | 2. List all the files with hidden files and directories that will be denoted as . at the start of the file or directory names.: 196 | 197 | ```bash 198 | $ ls -a 199 | ``` 200 | 201 | 3. Use -la flag to list all the files with their permission details: 202 | 203 | ```bash 204 | $ ls -la 205 | ``` 206 | 207 | 3. **mkdir** The mkdir (make directory) command allows users to create directories or folders. 208 | 209 | ```bash 210 | $ mkdir mydir 211 | $ ls 212 | mydir 213 | ``` 214 | 215 | The flag '-p' is used to create multiple directories or parent directories at once. 216 | 217 | ```bash 218 | $ mkdir -p dir1/dir2/dir3 219 | $ cd dir1/dir2/dir3 220 | ~/home/nirjas/dir1/dir2/dir3$ 221 | ``` 222 | 223 | 4. **rmdir**: The rmdir (remove directories) is used to remove empty directories. To delete directories that contains files and fodlers refer to `rm -r directoryName`. 224 | 225 | 1. Remove empty directory: 226 | 227 | ```bash 228 | $ rmdir directoryName 229 | ``` 230 | 231 | 2. Remove multiple directories: 232 | 233 | ```bash 234 | $ rmdir dir1 dir2 dir3 235 | ``` 236 | 237 | 3. Remove entire directory tree. This command is similar to `rmdir a/b/c a/b a`: 238 | 239 | ```bash 240 | $ rmdir -p a/b/c 241 | ``` 242 | 243 | 5. **rm**: The rm (remove) command is used to remove files, directories, symbolic links etc from the file system. 244 | 245 | 1. Remove file: The rm command is used to remove or delete a file. 246 | 247 | ```bash 248 | $ rm or 249 | ``` 250 | 251 | 2. Remove file forcefully: The rm command with -f option is used to remove file without prompting for confirmation. 252 | 253 | ```bash 254 | $ rm -f filename 255 | ``` 256 | 257 | 3. Remove directory: The rm command with -r option is used to remove the directories that contains files. The -r flag is used to delete the contents recursively. 258 | 259 | ```bash 260 | $ rm -r directoryName 261 | ``` 262 | 263 | 4. Remove directory forcefully: The rm command with -rf option is used to forcefully remove directory recursively. 264 | 265 | ```bash 266 | rm -rf directoryName 267 | ``` 268 | 269 | 6. **touch**: The touch command is used to create new empty files. Touch is also used to change timestamps on existing files and directories. 270 | 271 | 1. **Create a file:** You can create a single empty file using touch command. 272 | 273 | ```bash 274 | $ touch file1.txt 275 | ``` 276 | 277 | The above command will create a file titled file1.txt. 278 | 279 | 2. **Create multiple files:** You can create the multiple numbers of files at the same time. 280 | 281 | ```bash 282 | $ touch file1 file2 file3 283 | ``` 284 | 285 | 3. **Change access time:** The touch command with `-a` option is used to change the access time of a file. 286 | 287 | ```bash 288 | $ touch -a file1.txt 289 | ``` 290 | 291 | 4. **Change modification time:** The touch command with `-m` option is used to change the modified time. 292 | 293 | ```bash 294 | $ touch -m file_name 295 | ``` 296 | 297 | 5. **Use timestamp of other file:** The touch command with `r` option is used to get timestamp of another file. 298 | 299 | ```bash 300 | $ touch -r file2 file1 301 | ``` 302 | 303 | The above command will get the timestamp of file1 and will assign it to file2. 304 | 305 | 6. **Create file with Specific time:** The touch command with '-t' option is used to create a file with specified time. 306 | 307 | ```bash 308 | $ touch -t 1911010000 file_name 309 | ``` 310 | 311 | 7. **cp**: The cp (copy) command is used to copy files and directories from one location to another location of the system. 312 | 313 | 1. Copy file: The cp command is used to copy a file. 314 | 315 | ```bash 316 | $ cp file1 /home/nirjas/files 317 | ``` 318 | 319 | In this example file1 will be copied to the files directory which is at "/home/nirjas/files" path. 320 | 321 | 2. Copy directory: The cp command with -r option is used to copy whole directory with its files recursively. 322 | 323 | ```bash 324 | $ cp -r directory1 /home/nirjas/myfiles 325 | ``` 326 | 327 | In this example the whole directory1 will be copied to myfiles directory. 328 | 329 | 3. Copy files inside directory: 330 | 331 | ```bash 332 | $ cp -r dir1/* /home/nirjas/myfiles 333 | ``` 334 | 335 | In the above example, all the files inside dir1 will be copied myfiles folder. The dir1 will not be copied. Only the files inside it will be copied. You can also specify which files to copy by the following example. 336 | 337 | ```bash 338 | $ cp -r dir1/*.txt /home/nirjas/myfiles 339 | ``` 340 | 341 | The above example will copy only text files. 342 | 343 | 4. Copy files without overriding: The cp command with -i will show you interactive prompt to replace if the destination directory already has the file. 344 | 345 | ```bash 346 | $ cp -i myfile /home/nirjas/files 347 | ``` 348 | 349 | 8. **mv**: The mv (copy) command usage is almost similar to the cp command and it is used to move or rename files or folders. 350 | 351 | 1. Rename files: mv command is also used to rename files in the following way. 352 | 353 | ```bash 354 | $ mv oldname newname 355 | ``` 356 | 357 | In this example file1 will be copied to the files directory which is at "/home/nirjas/files" path. 358 | 359 | 2. Move files: 360 | 361 | ```bash 362 | $ mv file.txt /home/nirjas/myfiles 363 | ``` 364 | 365 | You can also move mutiple files in one command. 366 | 367 | ```bash 368 | $ mv file1 file2 file3 /home/nirjas/myfiles 369 | ``` 370 | 371 | 3. Move Directories: 372 | 373 | ```bash 374 | $ mv dir1 /home/nirjas/myfiles 375 | ``` 376 | 377 | 4. Move files without overriding: 378 | 379 | ```bash 380 | $ mv -i myfile /home/nirjas/files 381 | ``` 382 | 383 | 9. **cat**: The cat command is used to view contents of single or multiple files, concatenate files and redirect output in terminal or files. 384 | 385 | ```bash 386 | $ cat file1 file2 387 | ``` 388 | 389 | 10. **file**: The file command is used to know the file type. 390 | 391 | ```bash 392 | $ file file1.txt 393 | 394 | file1.txt: ASCII text 395 | ``` 396 | 397 | **[⬆ Back to Top](#table-of-contents)** 398 | 399 | ### Text Processing 400 | 401 | 1. **cut**: The cut command is used to extract portion of texts from a file. 402 | 403 | ```bash 404 | $ cut -c 4 file.txt 405 | ``` 406 | 407 | This will show 4th character from each line of that file. You can also modify it in the follwing way to specify 408 | your range. 409 | 410 | ```bash 411 | $ cut -c 4-10 file.txt 412 | ``` 413 | 414 | Here the character range is 4-10. 415 | To cut off according to fields, -f option is used. 416 | 417 | ```bash 418 | $ cut -f 2 file.txt 419 | ``` 420 | By default it uses TABs as the delimiter. so everything separated by a TAB is considered a field. 421 | 422 | 2. **paste**: The paste command is almost similar to cat command. But instead of just showing the text of the file 423 | it merges the lines of the file in one line. For example suppose `file1.txt` has the below text. 424 | 425 | ``` 426 | Terminal 427 | is 428 | awesome 429 | ``` 430 | 431 | Now apply the following command on the text file. 432 | 433 | ```bash 434 | $ paste -s file1.txt 435 | ``` 436 | 437 | The output will be 'Terminal is awesome'. By default it is using TABs as the delimiter. 438 | But you can set custom delimiter as the following example. 439 | 440 | ```bash 441 | $ paste -d ' ' -s file1.txt 442 | ``` 443 | 444 | The above example will use spaces the delimiter. 445 | 446 | 3. **head**: the head command is used the view the first 10 lines of a text file. It's very useful the see the contents of 447 | a huge log files. 448 | 449 | ```bash 450 | $ head /var/log/syslog 451 | ``` 452 | 453 | You can also define how many lines you want to view by the -n option. 454 | 455 | ```bash 456 | $ head -n 20 /var/log/syslog 457 | ``` 458 | 459 | 4. **tail**: The tail command is almost similar to the head command. But instead of showing the first 10 lines, 460 | it will show you the last 10 lines as default. 461 | 462 | ```bash 463 | $ tail /var/log/syslog 464 | ``` 465 | 466 | 5. **less**: When browsing the long log files you can use another very useful command which is called `less`. If a file content is very large then less is used to view the file contents as a paged manner. 467 | 468 | ```bash 469 | $ less /var/log/syslog 470 | ``` 471 | 472 | Use the following command to navigate through less:
473 | q - Used to quit out of less and go back to your shell.
474 | Page up, Page down, Up and Down - Navigate using the arrow keys and page keys.
475 | g - Moves to beginning of the text file.
476 | G - Moves to the end of the text file.
477 | /search - You can search for specific text inside the text document. Prefacing the words you want to search with /
478 | h - If you need a little help about how to use less while you’re in less, use help. 479 | 480 | 6. **expand and unexpand**: expand is used to convert all the TABs in a text file to spaces. 481 | 482 | ```bash 483 | $ expand file1.txt 484 | ``` 485 | 486 | To convert the spaces back to TABs. Use the unexpand command. 487 | 488 | ```bash 489 | $ unexpand -a file1.txt 490 | ``` 491 | 7. **sort**: The sort command is used to sort the lines in a text file. 492 | 493 | ```bash 494 | $ sort file1.txt 495 | ``` 496 | 497 | To do a reverse sort the -r option is used. 498 | 499 | ```bash 500 | $ sort -r file1.txt 501 | ``` 502 | 503 | 8. **tr**: the tr (translate) command is used to translate a set of character to another one. 504 | The following example will convert all lowercase character to uppercase one. 505 | 506 | ```bash 507 | $ tr a-z A-Z 508 | terminal 509 | TERMINAL 510 | ``` 511 | 512 | 9. **uniq**: Just as the name says it it, the uniq (Unique) command is used to remove all the duplicate texts from a file. 513 | 514 | ```bash 515 | $ uniq file1.txt 516 | ``` 517 | 10. **wc**: The wc command is used to show count of words, lines and bytes from file respectively. 518 | 519 | ```bash 520 | $ wc file1.txt 521 | ``` 522 | 523 | To see only the line counts use the following. 524 | 525 | ```bash 526 | $ wc -l file1.txt 527 | ``` 528 | Similarly, -w, -c can be used to show only count of words and bytes respectively. 529 | 530 | 11. **grep**: When it comes to text processing or filtering results of other commands, grep is probably the most used 531 | command in such cases. The main syntax is following. 532 | 533 | ```bash 534 | $ grep pattern file 535 | ``` 536 | 537 | You can also defines the patterns that are case sensitive by -i flag. 538 | 539 | ```bash 540 | $ grep -i pattern file 541 | ``` 542 | 543 | Grep can also be used with commands as a pipeline. 544 | 545 | ```bash 546 | $ ls /nirjas/home | grep -i file1 547 | ``` 548 | 549 | The above command will show the file1 from /nirjas/home directory. 550 | To search for the lines which doesn't contain the particular keyword use the -v option. 551 | 552 | ```bash 553 | $ ps aux | grep -v grep 554 | ``` 555 | 556 | The above example will ignore all the grep processes and shows the others. 557 | 558 | Grep can also be used with regular expressions. 559 | 560 | ```bash 561 | $ grep "one$" file1.txt 562 | ``` 563 | 564 | The above command will show the lines which are ending the word `one`. 565 | Some other useful regular expressions with grep are as follows. 566 | 567 | 1. Matching any character: To match any character with a particular word the period (.) is used. 568 | 569 | ```bash 570 | $ grep "..rent" file.txt 571 | ``` 572 | 573 | The above command will match anything that has two characters and then the string `rent` 574 | 575 | 2. Bracket Expressions: You can also specify mutiple words with a particular character by enclosing them 576 | with a bracket. 577 | 578 | ```bash 579 | $ grep "swe[ea]t" file.txt 580 | ``` 581 | 582 | The above command will match this two words `sweet` and `sweat` 583 | 584 | To find every line which starts with a capital letter, 585 | 586 | ```bash 587 | $ grep "^[A-Z]" file.txt 588 | ``` 589 | 590 | Instead of using character ranges POSIX classes can also be used for the above example, 591 | 592 | ```bash 593 | $ grep "^[[:upper:]]" file.txt 594 | ``` 595 | 596 | To find each line that contains an opening and closing parenthesis, with only letters and single spaces in between, the following expression can be used, 597 | 598 | ```bash 599 | $ grep "([A-Za-z ]*)" file.txt 600 | ``` 601 | 602 | To escape meta characters, the backslash character (\) in front of the characters are used. 603 | 604 | ```bash 605 | $ grep "^[A-Z].*\.$" file.txt 606 | ``` 607 | 608 | The above example will find any line that begins with a capital letter and ends with a period. But it escapes the ending period so that it represents a literal period. 609 | 610 | 3. Extended Regex: To use extended regular expression the -E option is used. 611 | To group multiple expressions, enclose them in a paratheses. 612 | 613 | ```bash 614 | $ grep -E "(Color|Colour)" file.txt 615 | ``` 616 | 617 | The above example will find either `Color` or `Colour` from the text. 618 | 619 | To find any words between chracter range, enclose the range with `{ }` brackets. 620 | 621 | ```bash 622 | $ grep -E "[[:alpha:]]{5,10}" 623 | ``` 624 | The above command will find all words that have between 5-10 characters. 625 | 626 | To ignore any lines that are commented or blank use the following grep command, 627 | 628 | ```bash 629 | $ sudo grep -vE '^(#|$)' 630 | ``` 631 | 632 | It's very useful to find lines in a big configuration file. 633 | 634 | 635 | ### Permission Commands 636 | 637 | Linux has four types of permissions. 638 | 639 | r = read 640 | 641 | w = write 642 | 643 | x = execute 644 | 645 | \- = no permission 646 | 647 | Each file and directory has three types of owners. 648 | i. **User:** Owner of the file who created it. 649 | ii. **Group:** Group of users with the same access permissions to the file or directory. 650 | iii. **Other:** Applies to all other users on the system 651 | 652 | **Changing Permission:** 653 | 654 | The `chmod` command is used to change file or directory permissions. There are two types of usage of this command. 655 | 656 | 1. **Absolute mode:** In this mode file permission is represented by an octal value. 657 | The numeric representation of the values are the following. 658 | - 4: read permission 659 | - 2: write permission 660 | - 1: execute permission 661 | 662 | ```bash 663 | $ sudo chmod 755 myfile 664 | ``` 665 | 666 | The above commands means the following. 667 | 7 = 4 + 2 + 1, 7 is the user permissions and it has read, write and execute permissions 668 | 669 | 5 = 4 + 1, the group has read and execute permission 670 | 671 | 5 = 4 + 1, and all other users have read and execute permissions 672 | 673 | 2. **Symbolic mode:** In this mode permissions can be changed for specific owners. 674 | The owners are represented in below table. 675 | 676 | | Owner | Description | 677 | | ----- | ----- | 678 | | u | user/owner | 679 | | g | group | 680 | | o | other | 681 | | a | all | 682 | 683 | The permissions can be add, remove and assign by using mathematical symbols like as below. 684 | 685 | - `+` : Add permission 686 | - `-` : remove permission 687 | - `=` : Assign permission 688 | 689 | ```bash 690 | $ chmod u+x file 691 | ``` 692 | 693 | The above command will add execute permission to user. Similarly, You can add or remove permission like below examples. 694 | 695 | ```bash 696 | $ chmod u-x file 697 | ``` 698 | 699 | Removes execute permission from user. 700 | 701 | ```bash 702 | $ chmod ug+x file 703 | ``` 704 | 705 | Adds execute permission to both user and group. 706 | 707 | ```bash 708 | $ chmod g-w file 709 | ``` 710 | 711 | Removes write permission from group. 712 | 713 | ```bash 714 | $ chmod o+r file 715 | ``` 716 | 717 | Add read permission to others. 718 | 719 | **Changing Ownership:** 720 | 721 | **1. User ownership:** User ownership can be updated by using the `chown` command. 722 | 723 | ```bash 724 | $ chown user file 725 | ``` 726 | 727 | or, 728 | 729 | ```bash 730 | $ chown username:groupname file 731 | ``` 732 | 733 | **2. Group ownership:** Group ownership can be modified by using the `chgrp` command. 734 | 735 | ```bash 736 | $ chgrp groupname file 737 | ``` 738 | 739 | **[⬆ Back to Top](#table-of-contents)** 740 | 741 | 742 | ### Networking Commands 743 | 744 | 1. **ifconfig:** The `ifconfig` command is used to display and configure all network interfaces. 745 | 746 | ```bash 747 | $ ifconfig -a 748 | ``` 749 | 750 | To create an interface and bring it up use the following command. 751 | 752 | ```bash 753 | $ ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up 754 | ``` 755 | 756 | 2. **ifup and ifdown:** 757 | 758 | ```bash 759 | $ ifup eth0 760 | $ ifdown eth0 761 | ``` 762 | 763 | ifup is to enable a network device and ifdown will disable it. 764 | 765 | 3. **ip command:** the `ip` command is a versatile command and is the replacement for both `ifconfig` command 766 | and `route` command. It can be used for mutiple puposes. 767 | 768 | 1. **Showing interfaces:** Equavalent to `ifconfig` command. 769 | 770 | ```bash 771 | $ ip link show 772 | ``` 773 | 774 | 2. **Showing interface statistics:** 775 | 776 | ```bash 777 | $ ip -s link show eth0 778 | ``` 779 | 780 | 3. **Showing ip address assigned to interfaces:** 781 | 782 | ```bash 783 | $ ip address show 784 | ``` 785 | or, 786 | 787 | ```bash 788 | $ ip addr show 789 | ``` 790 | 791 | 4. **To bring interfaces up and down:** Equlavalent to `ifup` and `ifdown` command 792 | 793 | ```bash 794 | $ ip link set eth0 up 795 | $ ip link set eth0 down 796 | ``` 797 | 798 | 5. **Add an IP address to an interface:** 799 | 800 | ```bash 801 | $ ip address add 192.168.0.1/24 dev eth0 802 | ``` 803 | 804 | 6. **Showing routing table:** Equavalent to `route` command. 805 | 806 | ```bash 807 | $ ip route list 808 | ``` 809 | 810 | 7. **Add a route:** Equavalent to `route add` command. 811 | 812 | ```bash 813 | $ ip route add 192.168.0.1/24 via 10.10.12.3 814 | ``` 815 | 816 | 8. **Remove a route:** Equavalent to `route del` command. 817 | 818 | ```bash 819 | $ ip route delete 192.168.0.1/24 820 | ``` 821 | 822 | 4. **route command:** The `route` command is used to command is used to show, add or delete routes. 823 | 824 | 1. **Showing routing table:** Equavalent to `route` command. 825 | 826 | ```bash 827 | $ sudo route -n 828 | ``` 829 | 830 | 2. **Add a route:** Equavalent to `ip route add` command. 831 | 832 | ```bash 833 | $ sudo route add -net 192.168.0.1/24 gw 10.10.12.3 834 | ``` 835 | 836 | 3. **Remove a route:** Equavalent to `ip route delete` command. 837 | 838 | ```bash 839 | $ sudo route del -net 192.168.0.1/24 840 | ``` 841 | 842 | 5. **ping:** the `ping` command is used to check whether a packet can reach to the destination host or not. 843 | 844 | ```bash 845 | $ ping google.com 846 | ``` 847 | 848 | 6. **whois:** The `Whois` command is used to get whois information of a domain. 849 | 850 | ```bash 851 | $ whois google.com 852 | ``` 853 | 854 | 7. **traceroute:** The `traceroute` command is used to see how packets are getting routed. 855 | 856 | ```bash 857 | $ traceroute google.com 858 | ``` 859 | 860 | 8. **netstat:** The `netstat` command is used to show the detailed information about the network. 861 | for more info run `man netstat` command on terminal. 862 | 863 | ```bash 864 | $ netstat -at 865 | ``` 866 | 867 | To view the active ports of the device use the following command. 868 | 869 | ```bash 870 | $ netstat -pnltu 871 | ``` 872 | 873 | 9. **tcpdump:** The `tcpdump` is to monitor packet activities. It will not be available by default in the operating 874 | system. It can be installed by `sudo apt install tcpdump` command. 875 | 876 | ```bash 877 | $ sudo tcpdump -i wlan0 878 | ``` 879 | 880 | 10. **dig:** The `dig` command is used to view the DNS information. It is equavalent to `nslookup` command. 881 | 882 | ```bash 883 | $ dig www.google.com 884 | ``` 885 | 886 | 11. **nslookup:** The `nslookup` command can be also useful in case of DNS information. It is equavalent to `dig` command. 887 | 888 | ```bash 889 | $ nslookup www.google.com 890 | ``` 891 | 892 | 12. **nmcli:** `nmcli` command allows one to control and modify NetworkManager. 893 | 894 | 1. **Overall status of Networkmanager:** To check overall status of the networkmanager. use the following command. 895 | 896 | ```bash 897 | $ sudo nmcli general status 898 | ``` 899 | 900 | 2. **Viewing all connections:** To view all connections of the PC. 901 | 902 | ```bash 903 | $ sudo nmcli connection show 904 | ``` 905 | 906 | 3. **Detailed information about a connection:** To view detail information about a connection 907 | 908 | ```bash 909 | $ sudo nmcli -p connection show connection-name 910 | ``` 911 | 912 | 4. **Adding an interface:** To add an interface device type the following command. 913 | 914 | ```bash 915 | $ sudo nmcli connection add ifname type con-name ipv4.addresses ipv4.gateway ipv4.dns ipv4.method 916 | ``` 917 | 918 | For example to set e static IP we will use the following command. 919 | 920 | ```bash 921 | $ sudo nmcli connection add ifname enmp0s3 type ethernet con-name enp0s3 ipv4.addresses 192.168.0.108/24 ipv4.gateway 192.168.0.1 ipv4.dns 8.8.8.8 ipv4.method manual 922 | ``` 923 | 924 | 5. **Modifying an interface:** To modify an interface use the following command. 925 | 926 | ```bash 927 | $ sudo nmcli connection modify enp0s3 ipv4.addresses 192.168.0.110/24 928 | ``` 929 | 930 | 6. **Changing wifi on or off:** Turning wifi on or off. 931 | 932 | ```bash 933 | $ sudo nmcli radio wifi (on or off ) 934 | ``` 935 | 936 | 7. **Up or Down a connection:** To enable or disable a connection. 937 | 938 | ```bash 939 | $ sudo nmcli connection up connection-name 940 | ``` 941 | 942 | ```bash 943 | $ sudo nmcli connection down connection-name 944 | ``` 945 | 946 | 8. **Viewing list of wifi connections:** To view the list of all nearby wifi connections. 947 | 948 | ```bash 949 | $ sudo nmcli device wifi list 950 | ``` 951 | 952 | 9. **Viewing connected WiFi Password:** To view the stored password of an active wifi connection. 953 | 954 | ```bash 955 | $ sudo nmcli device wifi show-password 956 | ``` 957 | 958 | Nmcli is a most versatile terminal command and the most useful also. For more usage information use `man nmcli` command. 959 | 960 | 13. **dhclient:** The `dhclient` command is used to obtain a fresh IP from the DHCP server. 961 | 962 | ```bash 963 | $ sudo dhclient 964 | ``` 965 | 966 | 14. **arp:** The `arp` command is used to show the arp cache of your device. 967 | 968 | ```bash 969 | $ arp -a 970 | ``` 971 | 972 | 15. **hostname:** `hostname` command can be usedful to view the device IP. 973 | 974 | ```bash 975 | $ hostname -I 976 | ``` 977 | 978 | 16. **nmap:** The `nmap` command is used to scan open services and ports of a server. 979 | 980 | ```bash 981 | $ nmap -A www.nirzash.me 982 | ``` 983 | To view the firewall setting with all information use the following command. 984 | 985 | ```bash 986 | $ nmap -sA www.nirzash.me 987 | ``` 988 | 989 | **[⬆ Back to Top](#table-of-contents)** 990 | 991 | ### Managing packages 992 | 993 | 1. **Install package:** 994 | 995 | ```bash 996 | $ sudo yum install package_name 997 | ``` 998 | 999 | 2. **Package description:** 1000 | The info command is used to display brief details about a package. 1001 | 1002 | ```bash 1003 | $ yum info package_name 1004 | ``` 1005 | 1006 | 3. **Uninstall package:** 1007 | The remove command is used to remove or uninstall package name. 1008 | ```bash 1009 | $ sudo yum remove package_name 1010 | ``` 1011 | 1012 | 4. **Package dependencies:** 1013 | The deplist command is used to display the dependencies of a package. 1014 | 1015 | ```bash 1016 | $ yum deplist package_name 1017 | ``` 1018 | 1019 | 5. **Search for packages:** 1020 | To search for packgaes use the following command. 1021 | 1022 | ```bash 1023 | $ yum search keyword 1024 | ``` 1025 | 1026 | 6. **Updating all packages:** 1027 | The following command will check for updates for the installed packages. 1028 | 1029 | ```bash 1030 | $ yum check-update 1031 | ``` 1032 | 1033 | To download and install the updates run the following command. 1034 | 1035 | ```bash 1036 | $ sudo yum update 1037 | ``` 1038 | 1039 | 7. **Clean the packages:** 1040 | 1041 | ```bash 1042 | $ sudo yum clean packages 1043 | ``` 1044 | 1045 | To clean the metadata of the packages 1046 | 1047 | ```bash 1048 | $ sudo yum clean metadata 1049 | ``` 1050 | 1051 | To clean the dbcache of the packages 1052 | 1053 | ```bash 1054 | $ sudo yum clean dbcache 1055 | ``` 1056 | 1057 | To rebuild the cache again use the following command. 1058 | 1059 | ```bash 1060 | $ sudo yum makecache 1061 | ``` 1062 | 1063 | 8. **Install package from local file:** 1064 | 1065 | It is also possible to install package from local file named package_name.rpm. 1066 | 1067 | ```bash 1068 | $ sudo rpm -i package_name.rpm 1069 | ``` 1070 | 1071 | 9. **Check if a package is installed or not:** 1072 | 1073 | To check if a package is installed or not use the following command. 1074 | 1075 | ```bash 1076 | $ sudo rpm -qa | grep package_name 1077 | ``` 1078 | 1079 | 10. **Removing installed packages using RPM:** 1080 | 1081 | ```bash 1082 | $ sudo rpm -e package_name 1083 | ``` 1084 | 1085 | 11. **Install package from source code:** 1086 | 1087 | ```bash 1088 | $ tar zxvf sourcecode.tar.gz 1089 | $ cd sourcecode 1090 | $ ./configure 1091 | $ make 1092 | $ make install 1093 | ``` 1094 | 1095 | **[⬆ Back to Top](#table-of-contents)** 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | --------------------------------------------------------------------------------