├── CONTRIBUTING.md ├── LICENSE └── README.md /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | [Md. Maruf Sarker](https://github.com/mdmarufsarker/) 2 |
3 | [Md Mahabub Alam](https://github.com/0xMahabub/) 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Md. Maruf Sarker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linux-cheatsheet 2 | 3 | A Beginners guide for Linux users 4 | 5 | [Bash Related Commands](#bash-related-commands) 6 | 7 | [System Related Commands](#system-related-commands) 8 | 9 | [Hardware Related Commands](#hardware-related-commands) 10 | 11 | [File / Directory Related Commands](#file--directory-related-commands) 12 | 13 | ## Bash Related Commands 14 | 15 | - Clear the terminal 16 | 17 | clear / ctrl + l 18 | 19 | - Close the terminal 20 | 21 | exit / ctrl + d 22 | 23 | - Reset the terminal 24 | 25 | reset 26 | 27 | - Stop any program 28 | 29 | ctrl + c 30 | 31 | - Sleep any program 32 | 33 | ctrl + z 34 | 35 | - Check the history 36 | 37 | ctrl + r / history 38 | 39 | - Check last 30 commands 40 | 41 | history | tail -30 42 | 43 | - Autocomplete Filename or Folder name 44 | 45 | Tab 46 | 47 | - Autocomplete command 48 | 49 | Tab twice 50 | 51 | - Autocomplete command with options 52 | 53 | Tab three times 54 | 55 | ## System Related Commands 56 | 57 | ### Dabian Based Systems 58 | 59 | - Update the system 60 | 61 | sudo apt update 62 | # for some older packages 63 | sudo apt-get update 64 | 65 | - Upgrade the system 66 | 67 | sudo apt upgrade 68 | # for some older packages 69 | sudo apt-get upgrade 70 | 71 | - Install a package 72 | 73 | sudo apt install package_name 74 | # for some older packages 75 | sudo apt-get install package_name 76 | 77 | - Remove a package 78 | 79 | sudo apt remove package_name 80 | # for some older packages 81 | sudo apt-get remove package_name 82 | 83 | - Remove a package and its dependencies 84 | 85 | sudo apt autoremove package_name 86 | # for some older packages 87 | sudo apt autoremove package_name 88 | 89 | - Search for a package 90 | 91 | apt search package_name 92 | 93 | - List all installed packages 94 | 95 | apt list --installed 96 | 97 | - List all available packages 98 | 99 | apt list 100 | 101 | - List all available packages with version 102 | 103 | apt list --all-versions 104 | 105 | ### Arch Based Systems 106 | 107 | - Update the system 108 | 109 | sudo pacman -Syyu 110 | 111 | - Install a package 112 | 113 | sudo pacman -S package_name 114 | 115 | - Remove a package 116 | 117 | sudo pacman -R package_name 118 | 119 | - Search for a package 120 | 121 | pacman -Ss package_name 122 | 123 | - List all installed packages 124 | 125 | pacman -Q 126 | 127 | - List all available packages 128 | 129 | pacman -Ss 130 | 131 | ## More to come 132 | 133 | - Check the internet is working 134 | 135 | ping google.com 136 | 137 | - Check System and Kernel version 138 | 139 | uname -a 140 | 141 | - Check System version 142 | 143 | cat /etc/os-release 144 | 145 | - Check Kernel 146 | 147 | uname -r 148 | 149 | - Check hostname 150 | 151 | hostname 152 | 153 | - Check IP address 154 | 155 | ip addr 156 | 157 | - Check IP address (short) 158 | 159 | ip a 160 | 161 | - Check IP address (long) 162 | 163 | ip address 164 | 165 | - See user logged in 166 | 167 | who 168 | 169 | - See username 170 | 171 | whoami 172 | 173 | - Short information of logged in user 174 | 175 | users 176 | 177 | - See all users 178 | 179 | cat /etc/passwd 180 | 181 | - See all groups 182 | 183 | cat /etc/group 184 | 185 | - See all groups of a user 186 | 187 | groups username 188 | 189 | - See all users of a group 190 | 191 | getent group groupname 192 | 193 | - Reboot the system 194 | 195 | sudo reboot 196 | 197 | - Shutdown the system 198 | 199 | sudo shutdown -h now / sudo poweroff / sudo halt / sudo init 0 / sudo systemctl poweroff 200 | 201 | - Check the current date and time 202 | 203 | date 204 | 205 | - Check the current user 206 | 207 | whoami 208 | 209 | - Check the current user's home directory 210 | 211 | echo $HOME 212 | 213 | - Check the current user's shell 214 | 215 | echo $SHELL 216 | 217 | - Check the current user's path / executable paths of system 218 | 219 | echo $PATH 220 | 221 | - Check the current user's environment variables 222 | 223 | env 224 | 225 | - Check the current user's environment variables with values 226 | 227 | env | grep -i "variable_name" 228 | 229 | - Check the current user's environment variables with values in a file 230 | 231 | env > env.txt 232 | 233 | - Check the current user's environment variables with values in a file with root access 234 | 235 | sudo env > env.txt 236 | 237 | - See the top 10 processes 238 | 239 | top 240 | 241 | - See the top 10 processes with root access and sorted by memory usage 242 | 243 | sudo top -o %MEM 244 | 245 | - See the top 10 processes with root access and sorted by cpu usage 246 | 247 | sudo top -o %CPU 248 | 249 | - See the top 10 processes with root access and sorted by cpu usage and memory usage 250 | 251 | sudo top -o %CPU,%MEM 252 | 253 | - See the top 10 processes with root access and sorted by cpu usage and memory usage and show only the process id and the process name 254 | 255 | sudo top -o %CPU,%MEM -p -c 256 | 257 | - See the current running processes 258 | 259 | ps 260 | 261 | - See the current running processes in a tree format 262 | 263 | pstree 264 | 265 | - Kill a specific process 266 | 267 | killall ProcessName 268 | 269 | - See the system uptime 270 | 271 | uptime 272 | 273 | - See the system uptime in a specific format 274 | 275 | uptime -p 276 | 277 | - See the system monitor 278 | 279 | htop 280 | 281 | - See the system monitor with root access and sorted by memory usage 282 | 283 | sudo htop -o %MEM 284 | 285 | - See the system monitor with root access and sorted by cpu usage 286 | 287 | sudo htop -o %CPU 288 | 289 | - See the system monitor with root access and sorted by cpu usage and memory usage 290 | 291 | sudo htop -o %CPU,%MEM 292 | 293 | - See the system monitor with root access and sorted by cpu usage and memory usage and show only the process id and the process name 294 | 295 | sudo htop -o %CPU,%MEM -p -c 296 | 297 | - See the system monitor with root access and sorted by cpu usage and memory usage and show only the process id and the process name and show the process tree 298 | 299 | sudo htop -o %CPU,%MEM -p -c -t 300 | 301 | ## Hardware Related Commands 302 | 303 | - See the system's hardware information 304 | 305 | sudo lshw 306 | 307 | - See the system's hardware information in a specific format 308 | 309 | sudo lshw -short 310 | 311 | - See the system's hardware information in a specific format and show only the network devices 312 | 313 | sudo lshw -short -C network 314 | 315 | - See the system's hardware information in a specific format and show only the network devices and show the network devices in a tree format 316 | 317 | sudo lshw -short -C network -class network -tree 318 | 319 | - Check the system's memory usage 320 | 321 | free -h 322 | 323 | - Check CPU information 324 | 325 | lscpu 326 | 327 | - Check Memory information 328 | 329 | sudo dmidecode -t memory 330 | 331 | - Check Disk information 332 | 333 | sudo dmidecode -t memory 334 | 335 | - Check USB information 336 | 337 | lsusb 338 | 339 | - Check PCI information 340 | 341 | lspci 342 | 343 | - Check Partitions 344 | 345 | lsblk 346 | 347 | - Check Partitions with root access 348 | 349 | sudo lsblk 350 | 351 | - Check Partitions with root access and show only the partitions 352 | 353 | sudo lsblk -p 354 | 355 | - Check Partitions with root access and show only the partitions and show the partitions in a tree format 356 | 357 | sudo lsblk -p -t 358 | 359 | - Mount a partition 360 | 361 | sudo mount /dev/sda1 /mnt 362 | 363 | - Unmount a partition 364 | 365 | sudo umount /dev/sda1 366 | 367 | - Mount a partition with root access and show only the partitions and show the partitions in a tree format 368 | 369 | sudo lsblk -p -t 370 | 371 | - Read Write Mount a partition 372 | 373 | sudo mount -o rw /dev/sda1 /mnt 374 | 375 | ## File / Directory Related Commands 376 | 377 | - Create a new directory 378 | 379 | mkdir directory-name 380 | 381 | - Create a new file 382 | 383 | touch file-name 384 | 385 | - Create multiple directories at a time 386 | 387 | mkdir dir1 dir2 dir3 dir4 dir5 388 | 389 | - Create multiple files at a time 390 | 391 | touch index.html style.css script.js 392 | 393 | - Delete a directory with all it's child 394 | 395 | rm -rf directory-name 396 | 397 | - Delete a file 398 | 399 | rm filename 400 | 401 | - List down all the files and directories 402 | 403 | ls 404 | 405 | - List down all the files and directories with all the details 406 | 407 | ls -l 408 | 409 | - List down all the files and directories with all the details and hidden files 410 | 411 | ls -la 412 | 413 | - List down all the files and directories with all the details and hidden files and sort by size 414 | 415 | ls -lS 416 | 417 | - List down all the files and directories with all the details and hidden files and sort by time 418 | 419 | ls -lt 420 | 421 | - List down all the files and directories with all the details and hidden files and sort by time and reverse 422 | 423 | ls -ltr 424 | 425 | - List down all the files and directories with all the details and hidden files and sort by time and reverse and show only 10 files 426 | 427 | ls -ltr | head -10 428 | 429 | - Open a file 430 | 431 | cat filename 432 | 433 | - Open a file with line numbers 434 | 435 | cat -n filename 436 | 437 | - Open a file with line numbers and show only 10 lines 438 | 439 | cat -n filename | head -10 440 | 441 | - Open a file using vim 442 | 443 | vim filename 444 | 445 | - Open a file using vim and show only 10 lines 446 | 447 | vim +10 filename 448 | 449 | - Open a file using nano 450 | 451 | nano filename 452 | 453 | - Open a file using nano and show only 10 lines 454 | 455 | nano +10 filename 456 | 457 | - Open a file using gedit 458 | 459 | gedit filename 460 | 461 | - Count the number of lines in a file 462 | 463 | wc -l filename 464 | 465 | - Print the current working directory 466 | 467 | pwd 468 | 469 | - Change the current working directory 470 | 471 | cd directory-name 472 | 473 | - Change the current working directory to the home directory 474 | 475 | cd ~ 476 | 477 | - Change the current working directory to the parent directory 478 | 479 | cd .. 480 | 481 | - Change the current working directory to the root directory 482 | 483 | cd / 484 | 485 | - Copy a file 486 | 487 | cp filename newfilename 488 | 489 | - Copy a file to a directory 490 | 491 | cp filename directory-name 492 | 493 | - Copy a directory 494 | 495 | cp -r directory-name newdirectory-name 496 | 497 | - Copy a directory to a directory 498 | 499 | cp -r directory-name directory-name 500 | 501 | - Move a file 502 | 503 | mv filename newfilename 504 | 505 | - Move a file to a directory 506 | 507 | mv filename directory-name 508 | 509 | - Move a directory 510 | 511 | mv -r directory-name newdirectory-name 512 | 513 | - Move a directory to a directory 514 | 515 | mv -r directory-name directory-name 516 | 517 | - Rename a file 518 | 519 | mv filename newfilename 520 | 521 | - Rename a directory 522 | 523 | mv directory-name newdirectory-name 524 | 525 | - Create a symbolic link 526 | 527 | ln -s filename linkname 528 | 529 | - Create a hard link 530 | 531 | ln filename linkname 532 | 533 | - Create a hard link to a directory 534 | 535 | ln -r directory-name linkname 536 | 537 | - Create a symbolic link to a directory 538 | 539 | ln -sr directory-name linkname 540 | 541 | - Create a file with content 542 | 543 | echo "Hello World" > filename 544 | 545 | - Append content to a file 546 | 547 | echo "Hello World" >> filename 548 | 549 | - Create a file with content and open it using vim 550 | 551 | echo "Hello World" > filename && vim filename 552 | 553 | - Create a file with content and open it using nano 554 | 555 | echo "Hello World" > filename && nano filename 556 | 557 | - Create a file with content and open it using gedit 558 | 559 | echo "Hello World" > filename && gedit filename 560 | 561 | - Create a file with content and open it using cat 562 | 563 | echo "Hello World" > filename && cat filename 564 | 565 | - Create a .tar file 566 | 567 | tar -cvf filename.tar directory-name 568 | 569 | - Create a .tar.gz file 570 | 571 | tar -cvzf filename.tar.gz directory-name 572 | 573 | - Create a .zip file 574 | 575 | zip -r filename.zip directory-name 576 | 577 | - Extract a .tar file 578 | 579 | tar -xvf filename.tar 580 | 581 | - Extract a .tar.gz file 582 | 583 | tar -xvzf filename.tar.gz 584 | 585 | - Extract a .zip file 586 | 587 | unzip filename.zip 588 | 589 | - Find a file 590 | 591 | find . -name filename 592 | --------------------------------------------------------------------------------