├── README.md ├── cut-cheatsheet.md ├── emac-and-vi-mode.md ├── find-cheatsheet.md ├── linux-command-line.md ├── nmap-cheatsheet.md ├── ssh-cheatsheet.md └── vim-cheatsheet.md /README.md: -------------------------------------------------------------------------------- 1 | ![visitor badge](https://visitor-badge.glitch.me/badge?page_id=shreyaschavhan.linux-commands-cheatsheet&left_text=Views) 2 | 3 | # ⁍ 𝐋𝐢𝐧𝐮𝐱 𝐂𝐨𝐦𝐦𝐚𝐧𝐝𝐬 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭 4 | 5 | - `gnome-control-center` : open system settings from terminal 6 | - `xclip -selection clipboard` : to copy output directly to clipboard 7 | 8 | Command | Usage 9 | :-: | --- 10 | `ssh` | ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. 11 | `ls` | List information about the FILEs (the current directory by default). 12 | `cd` | Change Directory 13 | `cat` | Concatenate files and print on the standard output 14 | `file` | determine file type 15 | `du` | estimate file space usage 16 | `find`| search for files in a directory hierarchy 17 | `grep` | print lines that match patterns 18 | `sort` | sort lines of text files 19 | `uniq` | report or omit repeated lines 20 | `strings` | print the sequences of printable characters in files 21 | `base64` | base64 encode/decode data and print to standard output 22 | `tr` | Translate, squeeze, and/or delete characters from standard input, writing to standard output. 23 | `tar` | an archiving utility 24 | `gzip` | compress or expand files 25 | `bzip2` | a block-sorting file compressor 26 | `xxd` | make a hexdump or do the reverse. 27 | `mkdir` | make directories 28 | `cp` | copy files and directories 29 | `mv` | move files and directories 30 | `telnet` | The telnet command is used for interactive communication with another host using the TELNET protocol 31 | `nc` | netcat is a simple unix utility which reads and writes data across network connections, using TCP or UDP protocol. 32 | `openssl` | OpenSSL command line tool 33 | `s_client` | The s_client command implements a generic SSL/TLS client which connects to a remote host using SSL/TLS. It is a very useful diagnostic tool for SSL servers. 34 | `nmap` | Network exploration tool and security / port scanner 35 | `diff` | compare files line by line 36 | `bash` | Bash is an sh-compatible command language interpreter 37 | `screen` | Screen is a full-screen window manager that multiplexes a physical terminal between several processes 38 | `tmux` | tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. 39 | `bg` | background a process 40 | `fg` | foreground a process 41 | `jobs` | list processes running in background 42 | `&` | run a command in background 43 | `cron` | daemon to execute scheduled commands 44 | `crontab` | maintain crontab files for individual users 45 | `crontab(5)` | tables for driving cron 46 | `more` | file perusal filter for crt viewing 47 | `less` | opposite of more 48 | `vi` | vim - Vi IMproved, a programmer's text editor 49 | `id` | print real and effective user and group IDs 50 | `pwd` | print working directory 51 | `git` | the stupid content tracker 52 | `locate` | find files by name, quickly 53 | `man` | an interface to the system reference manuals 54 | `which` | locate a command 55 | `type` | lets you query the type of each command. 56 | `ps` | report a snapshot of the current processes. 57 | `kill` | send a signal to a process 58 | `uname` | print system information 59 | `chmod` | change file mode bits 60 | `chown` | change file owner and group 61 | `chgrp` | change group ownership 62 | `tail` | output the last part of files 63 | `ln` | make link between files 64 | 65 | --- 66 | 67 | > - `cat ./-` (./ - stands for current directory) : cat a file with name "-" 68 | > - `cat ./-filename` : cat a file whose name starts with "-" 69 | > - `cat \spaces \in \this \filename.txt` (Original filename: `spaces in this filename.txt` ) - cat a file name with spaces 70 | > - `base64 -d data.txt` - base64 decode a file 71 | > - `strings filename` - output human readable text from non-humanreadable file: 72 | > - `echo "acbdlksjfla KHLKJfdlsfasd" | tr 'A-Za-z' 'N-ZA-Mn-za-m'` - rotate a text with all lowercase and uppercase by 13 positions: 73 | > - `openssl s_client -connect :` : connect a host with ssl encryption 74 | > - `diff fileone filetwo` : check difference 75 | > - `tail -n ` : print last n lines of a file 76 | > - `ln -s tmp/files/take-the-command-challenge take-the-command-challenge` : Create a symbolic link named take-the-command-challenge that points to the file tmp/files/take-the-command-challenge. 77 | > - `find . -delete` : Delete all of the files in this challenge directory including all subdirectories and their contents. 78 | > - `grep -rl 500`: `-r` for Recursive, read all files in given directory and subdirectories & `-l` for Print the name of each file which contains a match. 79 | > 80 | 81 | ----- 82 | 83 | `Note: These are my notes for personal reference!` 84 | 85 | 86 | 87 | ## 𝐁𝐚𝐬𝐢𝐜 88 | 89 | - `date` : displays the current time and date 90 | ``` 91 | ┌──(shreyas㉿kali)-[~] 92 | └─$ date 93 | Tuesday 04 January 2022 03:39:43 PM IST 94 | ``` 95 | 96 | --- 97 | 98 | - `cal` : displays a calendar of the current month 99 | ``` 100 | ┌──(shreyas㉿kali)-[~] 101 | └─$ cal 102 | January 2022 103 | Su Mo Tu We Th Fr Sa 104 | 1 105 | 2 3 4 5 6 7 8 106 | 9 10 11 12 13 14 15 107 | 16 17 18 19 20 21 22 108 | 23 24 25 26 27 28 29 109 | 30 31 110 | 111 | ``` 112 | --- 113 | 114 | - `df` : the current amount of free space on our disk drives 115 | ``` 116 | ┌──(shreyas㉿kali)-[~] 117 | └─$ df 118 | Filesystem 1K-blocks Used Available Use% Mounted on 119 | udev 1953436 0 1953436 0% /dev 120 | tmpfs 399160 1168 397992 1% /run 121 | /dev/sda1 130538556 11247868 112613492 10% / 122 | tmpfs 1995784 0 1995784 0% /dev/shm 123 | tmpfs 5120 0 5120 0% /run/lock 124 | tmpfs 399156 68 399088 1% /run/user/1000 125 | 126 | ``` 127 | --- 128 | - `free` : display the amount of free memory 129 | ``` 130 | ┌──(shreyas㉿kali)-[~] 131 | └─$ free 132 | total used free shared buff/cache available 133 | Mem: 3991568 672232 2753624 8864 565712 3079888 134 | Swap: 998396 0 998396 135 | 136 | ``` 137 | --- 138 | 139 | ## 𝐍𝐚𝐯𝐢𝐠𝐚𝐭𝐢𝐨𝐧 140 | 141 | - `pwd` : print working directory 142 | ``` 143 | ┌──(shreyas㉿kali)-[~] 144 | └─$ pwd 145 | /home/shreyas 146 | 147 | ``` 148 | --- 149 | 150 | - `cd` : change directory 151 | ``` 152 | ┌──(shreyas㉿kali)-[~] 153 | └─$ cd practise 154 | 155 | ┌──(shreyas㉿kali)-[~/practise] 156 | └─$ pwd 157 | /home/shreyas/practise 158 | 159 | ┌──(shreyas㉿kali)-[~/practise] 160 | └─$ ls 161 | hackthebox 162 | 163 | ``` 164 | --- 165 | 166 | - `cd` shortcuts 167 | 168 | Shortcut | Result 169 | ---|--- 170 | cd | Changes the working directory to your home directory. 171 | cd - | Changes the working directory to the previous working directory. 172 | cd ~user_name | Changes the working directory to the home directory of user_name. For example, typing cd ~bob will change the directory to the home directory of user “bob.” 173 | 174 | --- 175 | 176 | - `ls` : List directory contents 177 | > - `ls -l`: output in long format 178 | > - `ls -t`: the t option to sort the result by the file’s modification time. 179 | > - `ls -lt --reverse`: --reverse to reverse the order of the sort. 180 | ``` 181 | ┌──(shreyas㉿kali)-[~] 182 | └─$ ls 183 | BugBounty Documents Music practise Templates 184 | Desktop Downloads Pictures Public Videos 185 | 186 | ┌──(shreyas㉿kali)-[~] 187 | └─$ ls /usr 188 | bin games include lib lib32 lib64 libexec libx32 local sbin share src 189 | 190 | ┌──(shreyas㉿kali)-[~] 191 | └─$ ls practise /usr 192 | practise: 193 | hackthebox 194 | 195 | /usr: 196 | bin games include lib lib32 lib64 libexec libx32 local sbin share src 197 | 198 | ┌──(shreyas㉿kali)-[~] 199 | └─$ ls -l 200 | total 176 201 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 202 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 203 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 204 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 205 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 206 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 207 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 208 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 209 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 210 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 211 | 212 | 213 | ┌──(shreyas㉿kali)-[~] 214 | └─$ ls -lt 215 | total 40 216 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 217 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 218 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 219 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 220 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 221 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 222 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 223 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 224 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 225 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 226 | 227 | 228 | ┌──(shreyas㉿kali)-[~] 229 | └─$ ls -lt --reverse 2 ⨯ 230 | total 40 231 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 232 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 233 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 234 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 235 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 236 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 237 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 238 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 239 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 240 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 241 | 242 | ``` 243 | --- 244 | 245 | - `file filename` : the file command will print a brief description of the file’s contents 246 | ``` 247 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 248 | └─$ file flag.txt 249 | flag.txt: ASCII text, with no line terminators 250 | 251 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 252 | └─$ file pack.ovpn 253 | pack.ovpn: ASCII text 254 | 255 | ``` 256 | --- 257 | 258 | - `less` : allows us to scroll forward and backward through a text file. 259 | - `Note: less is more. Means both commands are same` 260 | ``` 261 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 262 | └─$ cat example | less 263 | 264 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 265 | └─$ less example 266 | ``` 267 | 268 | Command | Action 269 | --- | --- 270 | `PAGE UP` or `b` | Scroll back one page 271 | `PAGE DOWN` or `space` | Scroll forward one page 272 | `Up arrow` | Scroll up one line 273 | `Down arrow` | Scroll down one line 274 | `G` | Move to the end of the text file 275 | `1G` or `g` | Move to the beginning of the text file 276 | `/characters` | Search forward to the next occurrence of characters 277 | `n` | Search for the next occurrence of the previous search 278 | `h` | Display help screen 279 | `q` | Quit less 280 | 281 | 282 | --- 283 | 284 | ## 𝐌𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐧𝐠 𝐟𝐢𝐥𝐞𝐬 𝐚𝐧𝐝 𝐝𝐢𝐫𝐞𝐜𝐭𝐨𝐫𝐢𝐞𝐬 285 | 286 | - Wildcards: 287 | 288 | Wildcards | Meaning 289 | --- | --- 290 | `*` | Matches any character 291 | `?` | Matches any single character 292 | `[characters]` | Matches any character that is a member of the set characters 293 | `[!characters]` | Matches any character that is not a member of the set characters 294 | `[:class:]]` | Matches any character that is member of the specified class 295 | 296 | - List of most commonly used character classes 297 | 298 | Character class | Meaning 299 | --- | --- 300 | `[:alnum:]` | Matches any alphanumeric character 301 | `[:alpha:]` | Matches any alphabetic characters 302 | `[:digit:]` | Matches any numerical 303 | `[:lower:]` | Matches any lowercase letter 304 | `[:upper:]` | Matches any uppercase 305 | 306 | 307 | - Wildcard examples: 308 | 309 | Pattern | Matches 310 | --- | --- 311 | `*` | All files 312 | `g*` | Any file beginning with g 313 | `b*.txt` | Any file beginning with b followed by any characters and ending with .txt 314 | `Data???` | Any file beginning with Data followed by exactly three characters 315 | `[abc]*` | Any file beginning with either an a, a b, or a c 316 | `BACKUP.[0-9][0-9][0-9]` | Any file beginning with BACKUP. followed by exactly three numerals 317 | `[[:upper:]]*` | Any file beginning with an uppercase letter 318 | `[![:digit:]]*` | Any file not beginning with a numeral 319 | `*[[:lower:]123]` | Any file ending with a lowercase letter or the numerals 1, 2, or 3 320 | 321 | - `Wildcards can be used with any command that accepts filenames as arguments` 322 | 323 | --- 324 | 325 | - `mkdir` - make directory 326 | - `mkdir dir` - single directory 327 | - `mkdir dir1 dir2 dir3` - multiple directories 328 | 329 | 330 | ``` 331 | ┌──(shreyas㉿kali)-[~/practise] 332 | └─$ mkdir commandline 333 | 334 | ┌──(shreyas㉿kali)-[~/practise] 335 | └─$ ls 336 | commandline hackthebox 337 | 338 | ┌──(shreyas㉿kali)-[~/practise/commandline] 339 | └─$ mkdir dir1 dir2 dir3 340 | 341 | ┌──(shreyas㉿kali)-[~/practise/commandline] 342 | └─$ ls 343 | dir1 dir2 dir3 344 | 345 | ``` 346 | --- 347 | 348 | - `cp` - copy files and directories 349 | - `cp item1 item2` : copy single file item1 into item2 350 | - `cp item... directory` : copies multiple items (either files or directories) into a directory. 351 | 352 | Option | Meaning 353 | --- | --- 354 | `-a`,`--archive` | Copy the files and directories and all of their attributes, including ownerships and permissions. 355 | `-i`, `--interactive` | Before overwriting an existing file, prompt the user for confirmation. 356 | `-r`, `--recursive` | Recursively copy directories and their contents. This option (or the -a option) is required when copying directories. 357 | `-u`, `--update` | When copying files from one directory to another, only copy files that either don’t exist or are newer than the existing corresponding files in the destination directory. This is useful when copying large numbers of files as it skips files that don’t need to be copied 358 | `-v`, `--verbose` | Display informative messages as the copy is performed. 359 | 360 | - `mv` is same as `cp` 361 | 362 | --- 363 | 364 | - `rm file` : remove files and directories 365 | 366 | 367 | Option | Meaning 368 | --- | --- 369 | `-i`, `--interactive` | Before deleting an existing file, prompt the user for confirmation. 370 | `-r`, `--recursive` | Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified. 371 | `-f`, `--force` | Ignore nonexistent files and do not prompt. This overrides the --interactive option. 372 | `-v`, `--verbose` | Display informative messages as the deletion is performed. 373 | 374 | --- 375 | 376 | - `ln` : create links 377 | - `ln file link` : create a hard link 378 | - `ln -s item link` : creates a symbolic link 379 | 380 | --- 381 | 382 | ## 𝐖𝐨𝐫𝐤𝐢𝐧𝐠 𝐰𝐢𝐭𝐡 𝐜𝐨𝐦𝐦𝐚𝐧𝐝𝐬 383 | 384 | - `type`: is a shell builtin that displays the kind of command the shell will execute 385 | 386 | ``` 387 | ┌──(shreyas㉿kali)-[~/practise/commandline] 388 | └─$ type ls 389 | ls is an alias for ls --color=auto 390 | 391 | ┌──(shreyas㉿kali)-[~/practise/commandline] 392 | └─$ type ssh 393 | ssh is /usr/bin/ssh 394 | 395 | ┌──(shreyas㉿kali)-[~/practise/commandline] 396 | └─$ type cd 397 | cd is a shell builtin 398 | 399 | ``` 400 | --- 401 | 402 | - `which` : Display an Executable’s Location 403 | 404 | ``` 405 | ┌──(shreyas㉿kali)-[~/practise/commandline] 406 | └─$ which ls 407 | ls: aliased to ls --color=auto 408 | 409 | ┌──(shreyas㉿kali)-[~/practise/commandline] 410 | └─$ which pwd 411 | pwd: shell built-in command 412 | 413 | ┌──(shreyas㉿kali)-[~/practise/commandline] 414 | └─$ which cd 415 | cd: shell built-in command 416 | 417 | ┌──(shreyas㉿kali)-[~/practise/commandline] 418 | └─$ which gedit 419 | /usr/bin/gedit 420 | 421 | ┌──(shreyas㉿kali)-[~/practise/commandline] 422 | └─$ which firefox 423 | /usr/bin/firefox 424 | 425 | ``` 426 | 427 | --- 428 | 429 | - `man` : Display a Program’s Manual Page 430 | 431 | ``` 432 | ┌──(shreyas㉿kali)-[~/practise/commandline] 433 | └─$ man ls 434 | ``` 435 | 436 | ``` 437 | LS(1) User Commands LS(1) 438 | 439 | NAME 440 | ls - list directory contents 441 | 442 | SYNOPSIS 443 | ls [OPTION]... [FILE]... 444 | 445 | DESCRIPTION 446 | List information about the FILEs (the current directory by default). Sort 447 | entries alphabetically if none of -cftuvSUX nor --sort is specified. 448 | 449 | Mandatory arguments to long options are mandatory for short options too. 450 | 451 | -a, --all 452 | do not ignore entries starting with . 453 | 454 | -A, --almost-all 455 | do not list implied . and .. 456 | 457 | --author 458 | with -l, print the author of each file 459 | 460 | Manual page ls(1) line 1 (press h for help or q to quit) 461 | 462 | ``` 463 | 464 | --- 465 | 466 | - `apropos` - Display Appropriate Commands 467 | 468 | ``` 469 | ┌──(shreyas㉿kali)-[~/practise/commandline] 470 | └─$ apropos copy 471 | cifsdd (8) - convert and copy a file over SMB 472 | COPY (7) - copy data between a file and a table 473 | cp (1) - copy files and directories 474 | cpgr (8) - copy with locking the given file to the password or group file 475 | cpio (1) - copy files to and from archives 476 | cppw (8) - copy with locking the given file to the password or group file 477 | dd (1) - convert and copy a file 478 | debconf-copydb (1) - copy a debconf database 479 | git-checkout-index (1) - Copy files from the index to the working tree 480 | gvfs-copy (1) - Deprecated equivalent of gio copy 481 | install (1) - copy files and set attributes 482 | mariadb-hotcopy (1) - a database backup program 483 | mysqlhotcopy (1) - a database backup program 484 | ntfscp (8) - copy file to an NTFS volume. 485 | objcopy (1) - copy and translate object files 486 | ptrepack (1) - Copy any PyTables Leaf, Group or complete subtree into anothe... 487 | rcp (1) - OpenSSH secure file copy 488 | rsync (1) - a fast, versatile, remote (and local) file-copying tool 489 | scp (1) - OpenSSH secure file copy 490 | ssh-copy-id (1) - use locally available keys to authorise logins on a remote ma... 491 | svnversion (1) - Produce a compact version identifier for a working copy. 492 | vfs_shadow_copy (8) - Expose snapshots to Windows clients as shadow copies. 493 | vfs_shadow_copy2 (8) - Expose snapshots to Windows clients as shadow copies. 494 | x86_64-linux-gnu-objcopy (1) - copy and translate object files 495 | 496 | ``` 497 | 498 | --- 499 | 500 | - `whatis` : Display One-line Manual Page Descriptions 501 | 502 | ``` 503 | ┌──(shreyas㉿kali)-[~/practise/commandline] 504 | └─$ whatis rm 505 | rm (1) - remove files or directories 506 | 507 | ┌──(shreyas㉿kali)-[~/practise/commandline] 508 | └─$ whatis ls 509 | ls (1) - list directory contents 510 | 511 | ┌──(shreyas㉿kali)-[~/practise/commandline] 512 | └─$ whatis sudo 513 | sudo (8) - execute a command as another user 514 | 515 | ``` 516 | 517 | --- 518 | 519 | - `info` : Display a Program’s Info Entry 520 | 521 | ``` 522 | 523 | ┌──(shreyas㉿kali)-[~/practise/commandline] 524 | └─$ info ls 525 | 526 | ``` 527 | 528 | ``` 529 | Next: dir invocation, Up: Directory listing 530 | 531 | 10.1 ‘ls’: List directory contents 532 | ================================== 533 | 534 | The ‘ls’ program lists information about files (of any type, including 535 | directories). Options and file arguments can be intermixed arbitrarily, 536 | as usual. 537 | 538 | For non-option command-line arguments that are directories, by 539 | default ‘ls’ lists the contents of directories, not recursively, and 540 | omitting files with names beginning with ‘.’. For other non-option 541 | arguments, by default ‘ls’ lists just the file name. If no non-option 542 | argument is specified, ‘ls’ operates on the current directory, acting as 543 | if it had been invoked with a single argument of ‘.’. 544 | 545 | By default, the output is sorted alphabetically, according to the 546 | locale settings in effect.(1) If standard output is a terminal, the 547 | output is in columns (sorted vertically) and control characters are 548 | output as question marks; otherwise, the output is listed one per line 549 | and control characters are output as-is. 550 | 551 | -----Info: (coreutils)ls invocation, 56 lines --Top------------------------------------ 552 | Follow xref: gument is specified, ‘ls’ operates on the current directory, acting asif 553 | ``` 554 | 555 | --- 556 | 557 | - `alias` : Creating Our Own Commands with alias 558 | - `trick: It’s possible to put more than one command on a line by separating each command with a semicolon` 559 | - `command1; command2; command3...` 560 | 561 | ``` 562 | [me@linuxbox ~]$ cd /usr; ls; cd - 563 | bin games include lib local sbin share src 564 | /home/me 565 | [me@linuxbox ~]$ 566 | ``` 567 | ``` 568 | [me@linuxbox ~]$ type foo 569 | bash: type: foo: not found 570 | ``` 571 | ``` 572 | [me@linuxbox ~]$ alias foo='cd /usr; ls; cd -' 573 | [me@linuxbox ~]$ foo 574 | bin games include lib local sbin share src 575 | /home/me 576 | [me@linuxbox ~]$ 577 | [me@linuxbox ~]$ type foo 578 | foo is aliased to `cd /usr; ls; cd -' 579 | ``` 580 | ``` 581 | [me@linuxbox ~]$ unalias foo 582 | [me@linuxbox ~]$ type foo 583 | bash: type: foo: not found 584 | ``` 585 | 586 | --- 587 | 588 | ## 𝐑𝐞𝐝𝐢𝐫𝐞𝐜𝐭𝐢𝐨𝐧 589 | 590 | - ` > ` : Redirecting Standard Output 591 | 592 | ``` 593 | ┌──(shreyas㉿kali)-[~/practise/commandline] 594 | └─$ ls -l /usr/bin > ls-output.txt 595 | 596 | ┌──(shreyas㉿kali)-[~/practise/commandline] 597 | └─$ ls -l 598 | total 180 599 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir1 600 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir2 601 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir3 602 | -rw-r--r-- 1 shreyas shreyas 171639 Jan 4 18:21 ls-output.txt 603 | 604 | ``` 605 | 606 | --- 607 | 608 | - `command >> file` - append redirected output to a file instead of overwriting the file 609 | 610 | ``` 611 | [me@linuxbox ~]$ ls -l /usr/bin >> ls-output.txt 612 | ``` 613 | 614 | --- 615 | 616 | - `0>` OR `<` : redirecting standard input 617 | - `>` : redirecting standard output 618 | - `2>` : redirecting standard error 619 | 620 | ``` 621 | [me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt 622 | ``` 623 | 624 | --- 625 | 626 | - `ls -l /bin/usr > ls-output.txt 2>&1` OR ` ls -l /bin/usr &> ls-output.txt`: Redirecting Standard Output and Standard Error to One File 627 | - `ls -l /bin/usr 2> /dev/null` : Disposing unwanted output 628 | 629 | --- 630 | 631 | - `command1 | command2` : Pipeline 632 | - `wc` : Print line, Word, and Byte counts 633 | - `grep` : print line matching pattern 634 | - `head -n ls-output.txt` : print initial lines of file 635 | - `tail -n ls-output.txt` : print last lines of files 636 | - `tee` : Read from Stdin and Output to Stdout and Files 637 | - 638 | 639 | ``` 640 | ┌──(shreyas㉿kali)-[~/practise/commandline] 641 | └─$ wc ls-output.txt 642 | 2557 24294 171639 ls-output.txt 643 | 644 | ``` 645 | ``` 646 | [me@linuxbox ~]$ head -n 5 ls-output.txt 647 | total 343496 648 | -rwxr-xr-x 1 root root 31316 2017-12-05 08:58 [ 649 | -rwxr-xr-x 1 root root 8240 2017-12-09 13:39 411toppm 650 | -rwxr-xr-x 1 root root 111276 2017-11-26 14:27 a2p 651 | -rwxr-xr-x 1 root root 25368 2016-10-06 20:16 a52dec 652 | [me@linuxbox ~]$ tail -n 5 ls-output.txt 653 | -rwxr-xr-x 1 root root 5234 2017-06-27 10:56 znew 654 | -rwxr-xr-x 1 root root 691 2015-09-10 04:21 zonetab2pot.py 655 | -rw-r--r-- 1 root root 930 2017-11-01 12:23 zonetab2pot.pyc 656 | -rw-r--r-- 1 root root 930 2017-11-01 12:23 zonetab2pot.pyo 657 | lrwxrwxrwx 1 root root 6 2016-01-31 05:22 zsoelim -> soelim 658 | ``` 659 | 660 | --- 661 | 662 | ## 𝐒𝐞𝐞𝐢𝐧𝐠 𝐭𝐡𝐞 𝐰𝐨𝐫𝐥𝐝 𝐚𝐬 𝐭𝐡𝐞 𝐬𝐡𝐞𝐥𝐥 𝐬𝐞𝐞𝐬 𝐢𝐭 663 | 664 | - `echo` : Display a line of text 665 | - `echo *` : works same as `ls` 666 | - `echo D*` : Display files/directories which starts with D 667 | - `echo *s` : Display files/drectories which ends with s 668 | - `echo [[:upper:]]*` : Display files/directories that starts with uppercase letters 669 | - `echo /usr/*/share` : display all directories between /usr/ & /share 670 | - `echo ~` : tilde expansion 671 | 672 | ``` 673 | ┌──(shreyas㉿kali)-[~] 674 | └─$ echo hello there my name is shreyas 675 | hello there my name is shreyas 676 | 677 | ┌──(shreyas㉿kali)-[~] 678 | └─$ echo * 679 | BugBounty Desktop Documents Downloads Music Pictures practise Public Templates Videos 680 | 681 | ┌──(shreyas㉿kali)-[~] 682 | └─$ echo D* 683 | Desktop Documents Downloads 684 | 685 | ┌──(shreyas㉿kali)-[~] 686 | └─$ echo *s 687 | Documents Downloads Pictures Templates Videos 688 | 689 | ┌──(shreyas㉿kali)-[~] 690 | └─$ echo [[:upper:]]* 691 | BugBounty Desktop Documents Downloads Music Pictures Public Templates Videos 692 | 693 | ┌──(shreyas㉿kali)-[~] 694 | └─$ echo /usr/*/share 695 | /usr/local/share 696 | 697 | ┌──(shreyas㉿kali)-[~] 698 | └─$ echo ~ 699 | /home/shreyas 700 | 701 | 702 | ``` 703 | 704 | - Arithmetic Expansion: 705 | - `$((expression))` 706 | 707 | ``` 708 | ┌──(shreyas㉿kali)-[~] 709 | └─$ echo $((2 + 2)) 710 | 4 711 | 712 | ┌──(shreyas㉿kali)-[~] 713 | └─$ echo $(($((5**2)) * 3)) 714 | 75 715 | 716 | ``` 717 | 718 | Operator | Description 719 | --- | --- 720 | `+` | Addition 721 | `-` | Subtraction 722 | `*` | Multiplication 723 | `/` | Division (but remember, since expansion supports only integer arithmetic, results are integers) 724 | `%` | Modulo, which simply means “remainder” 725 | `**` | Exponentiation 726 | 727 | - Brace Expansion: create multiple text strings from a pattern containing braces 728 | 729 | ``` 730 | ┌──(shreyas㉿kali)-[~] 731 | └─$ echo Front-{A,B,C}-Back 732 | Front-A-Back Front-B-Back Front-C-Back 733 | 734 | ┌──(shreyas㉿kali)-[~] 735 | └─$ echo Number_{1..5} 736 | Number_1 Number_2 Number_3 Number_4 Number_5 737 | 738 | ┌──(shreyas㉿kali)-[~] 739 | └─$ echo {01..15} 740 | 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 741 | 742 | ┌──(shreyas㉿kali)-[~] 743 | └─$ echo a{A{1,2},B{3,4}}b 744 | aA1b aA2b aB3b aB4b 745 | 746 | ``` 747 | 748 | - Parameter expansion: `echo $var` 749 | - Command Substitution 750 | - `echo $(ls)` 751 | - `ls -l $(which cp)` 752 | - `file $(ls -d /usr/bin/* | grep zip)` 753 | 754 | --- 755 | 756 | - Quoting: 757 | - Double Quotes: If we place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are $ (dollar sign), \ (backslash), and ` (backtick). 758 | - Single Quotes: If we need to suppress all expansions, we use single quotes. 759 | - Escaping Characters: 760 | - `\` : is used for escaping 761 | - Backslash Escape Situation: 762 | 763 | Escape Sequence | Meaning 764 | --- | --- 765 | `\a` | Bell (an alert that causes the computer to beep) 766 | `\b` | Backspace 767 | `\n` | Newline; on Unix-like systems, this produces a line feed 768 | `\r` | Carriage return 769 | `\t` | tab 770 | 771 | ``` 772 | ┌──(shreyas㉿kali)-[~] 773 | └─$ sleep 10; echo -e "Time's up\a" 774 | Time's up 775 | 776 | ``` 777 | --- 778 | 779 | ## 𝐀𝐝𝐯𝐚𝐧𝐜𝐞𝐝 𝐊𝐞𝐲𝐛𝐨𝐚𝐫𝐝 𝐓𝐫𝐢𝐜𝐤𝐬 780 | 781 | - `clear` : Clear the terminal screen 782 | - `history` : Display or manipulate the history list 783 | 784 | - Cursor Movement: 785 | 786 | Key | Action 787 | --- | --- 788 | `CTRL-A` | Move the cursor to the beginning of line 789 | `CTRL-E` | Move cursor to the end of the line 790 | `CTRL-F` | Move cursor forward one character; same as the right arrow key 791 | `CTRL-B` | Move cursor backward one character; same as the left arrow key 792 | `ALT-F` | Move cursor one word forward 793 | `ALT-B` | Move cursor backward one word 794 | `CTRL-L` | Clear screen and move the cursor to the top left corner. Same as `clear` command 795 | 796 | --- 797 | - Modifying Text 798 | 799 | 800 | Key | Action 801 | --- | --- 802 | `CTRL-D` | Delete the character at the cursor location 803 | `CTRL-T` | Transpose the character at the cursor location 804 | `ALT-T` | Transpose the word at the cursor location with the one preceding it. 805 | `ALT-L` | Convert the characters from the cursor location to the end of the word to lowercase. 806 | `ALT-U` | Convert the characters from the cursor location to the end of the word to uppercase. 807 | 808 | --- 809 | 810 | - History Expansion 811 | 812 | Sequence | Action 813 | --- | --- 814 | `!!` | Repeat the last command. It is probably easier to press the up arrow and ENTER 815 | `!number` | Repeat history list item `number`. 816 | `!string` | Repeat last history list item starting with `string` 817 | `!?string` | Repeat last history list item containing `string` 818 | 819 | 820 | --- 821 | 822 | ## 𝐏𝐞𝐫𝐦𝐢𝐬𝐬𝐢𝐨𝐧𝐬 823 | 824 | - `id` : Display user identity 825 | - `chmod` : Change a file’s mode 826 | - `umask` : Set the default file permissions 827 | - `su` : Run a shell as another user 828 | - `sudo` : Execute a command as another user 829 | - `chown`: Change a file’s owner 830 | - `chgrp`: Change a file’s group ownership 831 | - `passwd`: Change a user’s password 832 | 833 | - Permission attribute Examples: 834 | 835 | File Attributes | Meaning 836 | --- | --- 837 | `-rwx------` | A regular file that is readable, writable, and executable by the file’s owner. No one else has any access. 838 | `-rw-------` | A regular file that is readable and writable by the file’s owner. No one else has any access. 839 | `-rw-r--r--` | A regular file that is readable and writable by the file’s owner. Members of the file’s owner group may read the file. The file is world-readable. 840 | `-rwxr-xr-x` | A regular file that is readable, writable, and executable by the file’s owner. The file may be read and executed by everybody else. 841 | `-rw-rw----` | A regular file that is readable and writable by the file’s owner and members of the file’s group owner only. 842 | `lrwxrwxrwx` | A symbolic link. All symbolic links have “dummy” permissions. The real permissions are kept with the actual file pointed to by the symbolic link. 843 | `drwxrwx---` | A directory. The owner and the members of the owner group may enter the directory and create, rename, and remove files within the directory. 844 | `drwxr-x---` | A directory. The owner may enter the directory and create, rename, and delete files within the directory. Members of the owner group may enter the directory but cannot create, delete, or rename files. 845 | 846 | --- 847 | 848 | - `chmod` : Change File Mode 849 | - 6(rw-) 850 | - 7(rwx) 851 | - 5(r-x) 852 | - 4(r--) 853 | - 0(---) 854 | 855 | Symbol | Meaning 856 | --- | --- 857 | `u` | Short for "user" but means the file or directory owner. 858 | `g` | Group owner 859 | `o` | Short for "others" but means world 860 | `a` | Short for "all". This is a combination of `u`, `g`, and `o`. 861 | 862 | - If no character is specified, “all” will be assumed. The operation may be a + indicating that a permission is to be added, a - indicating that a permission is to be taken away, or a = indicating that only the specified permissions are to be applied and that all others are to be removed. 863 | 864 | Notation | Meaning 865 | --- | --- 866 | `u+x` | Add execute permission for the owner. 867 | `u-x` | Remove execute permission from the owner. 868 | `+x` | Add execute permission for the owner, group, and world. This is equivalent to a+x. 869 | `o-rw` | Remove the read and write permissions from anyone besides the owner and group owner. 870 | `go=rw` | Set the group owner and anyone besides the owner to have read and write permissions. If either the group owner or the world previously had execute permission, it is removed. 871 | `u+x,go=rx` | Add execute permission for the owner and set the permissions for the group and others to read and execute. Multiple specifications may be separated by commas. 872 | 873 | --- 874 | 875 | ## 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐞𝐬 876 | 877 | - `ps` : Report a snapshot of current processes 878 | - `top` : Display tasks 879 | - `jobs` : List active jobs 880 | - `bg` : Place a job in the background 881 | - `fg` : Place a job in the foreground 882 | - `kill` : Send a signal to a process 883 | - `killall` : Kill process by name 884 | - `shutdown` : Shut down or reboot the system 885 | 886 | 887 | 888 | --- 889 | 890 | ## 𝐍𝐞𝐭𝐰𝐨𝐫𝐤𝐢𝐧𝐠 891 | 892 | - `ping` : Checks if a network is reachable, `ping` command sends a special network packet called an `ICMP ECHO_REQUEST` to a specified host. Most network devices receiving this packet will reply to it, allowing the network connection to be verified. 893 | 894 | ``` 895 | ┌──(shreyas㉿kali)-[~] 896 | └─$ ping youtube.com 897 | PING youtube.com (142.250.204.46) 56(84) bytes of data. 898 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=1 ttl=128 time=149 ms 899 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=2 ttl=128 time=151 ms 900 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=3 ttl=128 time=188 ms 901 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=4 ttl=128 time=140 ms 902 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=5 ttl=128 time=139 ms 903 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=6 ttl=128 time=120 ms 904 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=7 ttl=128 time=131 ms 905 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=8 ttl=128 time=148 ms 906 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=9 ttl=128 time=137 ms 907 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=10 ttl=128 time=132 ms 908 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=11 ttl=128 time=144 ms 909 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=12 ttl=128 time=128 ms 910 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=13 ttl=128 time=128 ms 911 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=14 ttl=128 time=141 ms 912 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=15 ttl=128 time=135 ms 913 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=16 ttl=128 time=130 ms 914 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=17 ttl=128 time=133 ms 915 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=18 ttl=128 time=142 ms 916 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=19 ttl=128 time=134 ms 917 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=20 ttl=128 time=137 ms 918 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=21 ttl=128 time=139 ms 919 | ^C64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=22 ttl=128 time=140 ms 920 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=23 ttl=128 time=121 ms 921 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=24 ttl=128 time=146 ms 922 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=25 ttl=128 time=136 ms 923 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=26 ttl=128 time=165 ms 924 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=27 ttl=128 time=176 ms 925 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=28 ttl=128 time=132 ms 926 | ^C 927 | --- youtube.com ping statistics --- 928 | 28 packets transmitted, 28 received, 0% packet loss, time 27045ms 929 | rtt min/avg/max/mdev = 120.372/140.817/187.758/14.526 ms 930 | 931 | ``` 932 | 933 | --- 934 | 935 | - `traceroute` : lists all the “hops” network traffic takes to get from the local system to a specified host. 936 | 937 | ``` 938 | ┌──(shreyas㉿kali)-[~] 939 | └─$ traceroute google.com 940 | traceroute to google.com (142.250.204.110), 30 hops max, 60 byte packets 941 | 1 192.168.29.2 (192.168.29.2) 0.227 ms 0.099 ms 0.175 ms 942 | 2 * * * 943 | 3 * * * 944 | 4 * * * 945 | 5 * * * 946 | 6 * * * 947 | 7 * * * 948 | 8 * * * 949 | 9 * * * 950 | 10 * * * 951 | 11 * * * 952 | 12 * * * 953 | 13 * * * 954 | 955 | ``` 956 | 957 | --- 958 | 959 | - `ip a` : It replaces the earlier and now deprecated `ifconfig` program. 960 | 961 | ``` 962 | ┌──(shreyas㉿kali)-[~] 963 | └─$ ip a 964 | 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 965 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 966 | inet 127.0.0.1/8 scope host lo 967 | valid_lft forever preferred_lft forever 968 | inet6 ::1/128 scope host 969 | valid_lft forever preferred_lft forever 970 | 2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 971 | link/ether 00:0c:29:c5:88:a0 brd ff:ff:ff:ff:ff:ff 972 | inet 192.168.x.x/24 brd 192.168.x.x scope global dynamic noprefixroute eth0 973 | valid_lft 1630sec preferred_lft 1630sec 974 | inet6 fe80::20c:29ff:x:x/64 scope link noprefixroute 975 | valid_lft forever preferred_lft forever 976 | 977 | ``` 978 | 979 | --- 980 | 981 | - `netstat` : The netstat program is used to examine various network settings and statistics. 982 | - `-r` option will display the kernel’s network routing table 983 | - `ie` : we can examine the network interfaces in our system 984 | 985 | ``` 986 | ┌──(shreyas㉿kali)-[~] 987 | └─$ netstat -ie 988 | Kernel Interface table 989 | eth0: flags=4163 mtu 1500 990 | inet 192.168.x.x netmask 255.255.255.0 broadcast 192.168.29.255 991 | inet6 fe80::20c:29ff:x:x prefixlen 64 scopeid 0x20 992 | ether 00:0c:29:c5:88:a0 txqueuelen 1000 (Ethernet) 993 | RX packets 102 bytes 11285 (11.0 KiB) 994 | RX errors 0 dropped 0 overruns 0 frame 0 995 | TX packets 207 bytes 17053 (16.6 KiB) 996 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 997 | 998 | lo: flags=73 mtu 65536 999 | inet 127.0.0.1 netmask 255.0.0.0 1000 | inet6 ::1 prefixlen 128 scopeid 0x10 1001 | loop txqueuelen 1000 (Local Loopback) 1002 | RX packets 8 bytes 400 (400.0 B) 1003 | RX errors 0 dropped 0 overruns 0 frame 0 1004 | TX packets 8 bytes 400 (400.0 B) 1005 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 1006 | 1007 | 1008 | ┌──(shreyas㉿kali)-[~] 1009 | └─$ netstat -r 1010 | Kernel IP routing table 1011 | Destination Gateway Genmask Flags MSS Window irtt Iface 1012 | default 192.168.29.2 0.0.0.0 UG 0 0 0 eth0 1013 | 192.168.29.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 1014 | 1015 | 1016 | ``` 1017 | 1018 | --- 1019 | 1020 | Transporting Files over a Network 1021 | 1022 | - `ftp` : `ftp` is used to communicate with FTP servers, machines that contain files that can be uploaded and downloaded over a network. `FTP` (in its original form) is not secure because it sends account names and passwords in cleartext. 1023 | 1024 | ``` 1025 | [me@linuxbox ~]$ ftp fileserver 1026 | Connected to fileserver.localdomain. 1027 | 220 (vsFTPd 2.0.1) 1028 | Name (fileserver:me): anonymous 1029 | 331 Please specify the password. 1030 | Password: 1031 | 230 Login successful. 1032 | Remote system type is UNIX. 1033 | Using binary mode to transfer files. 1034 | ftp> cd pub/cd_images/ubuntu-18.04 1035 | 250 Directory successfully changed. 1036 | ftp> ls 1037 | 200 PORT command successful. Consider using PASV. 1038 | 150 Here comes the directory listing. 1039 | -rw-rw-r-- 1 500 500 733079552 Apr 25 03:53 ubuntu-18.04-desktop-amd64.iso 1040 | 226 Directory send OK. 1041 | ftp> lcd Desktop 1042 | Local directory now /home/me/Desktop 1043 | ftp> get ubuntu-18.04-desktop-amd64.iso 1044 | local: ubuntu-18.04-desktop-amd64.iso remote: ubuntu-18.04-desktop-amd64.iso 1045 | 200 PORT command successful. Consider using PASV. 1046 | 150 Opening BINARY mode data connection for ubuntu-18.04-desktop-amd64.iso (733079552 bytes). 1047 | 226 File send OK. 1048 | 733079552 bytes received in 68.56 secs (10441.5 kB/s) 1049 | ftp> bye 1050 | ``` 1051 | 1052 | Command | Meaning 1053 | --- | --- 1054 | `ftp fileserver` | Invoke the `ftp` program and have it connect the FTP server `fileserver` 1055 | `anonymous` | Login name. After the login prompt, a password prompt will appear. Some servers will accept a blank password; others will require a password in the form of an email address. In that case, try something like user@example. 1056 | `cd` | change directory 1057 | `ls` | list directory 1058 | `lcd Desktop` | Change the directory on the local system to ~/Desktop. In the example, the ftp program was invoked when the working directory was ~. This command changes the working directory to ~/Desktop. 1059 | `get` | transfer file from remote server to local system 1060 | `bye` | Log off the remote server and end the ftp program session. The commands quit and exit may also be used. 1061 | 1062 | - `lftp` is a Better ftp 1063 | 1064 | --- 1065 | 1066 | - `wget` : It is useful for downloading content from both web and FTP sites. Single files, multiple files, and even entire sites can be downloaded. 1067 | 1068 | ``` 1069 | [me@linuxbox ~]$ wget http://linuxcommand.org/index.php 1070 | --11:02:51-- http://linuxcommand.org/index.php 1071 | => `index.php' 1072 | Resolving linuxcommand.org... 66.35.250.210 1073 | Connecting to linuxcommand.org|66.35.250.210|:80... connected. 1074 | HTTP request sent, awaiting response... 200 OK 1075 | Length: unspecified [text/html] 1076 | 1077 | [ <=> ] 3,120 --.--K/s 1078 | 1079 | 11:02:51 (161.75 MB/s) - `index.php' saved [3120] 1080 | ``` 1081 | 1082 | --- 1083 | 1084 | - `ssh` : SSH solves the two basic problems of secure communication with a remote host. 1085 | - It authenticates that the remote host is who it says it is (thus preventing so-called man-in-the-middle attacks). 1086 | - It encrypts all of the communications between the local and remote hosts. 1087 | - `ssh remote-sys` : To connect to a remote host named remote-sys 1088 | - `ssh username@remote-sys` : login with specific username 1089 | - `ssh remote-sys `: to execute just a single command 1090 | 1091 | 1092 | 1093 | ``` 1094 | [me@linuxbox ~]$ ssh remote-sys 1095 | The authenticity of host 'remote-sys (192.168.1.4)' can't be established. 1096 | RSA key fingerprint is 41:ed:7a:df:23:19:bf:3c:a5:17:bc:61:b3:7f:d9:bb. 1097 | Are you sure you want to continue connecting (yes/no)? 1098 | ``` 1099 | 1100 | --- 1101 | 1102 | - `scp` - (secure copy). copy files from local host to remote host 1103 | 1104 | ``` 1105 | [me@linuxbox ~]$ scp remote-sys:document.txt . 1106 | me@remote-sys's password: 1107 | document.txt 100% 5581 5.5KB/s 00:00 1108 | [me@linuxbox ~]$ 1109 | ``` 1110 | 1111 | - `sftp` : SSH file-copying program 1112 | 1113 | ``` 1114 | [me@linuxbox ~]$ sftp remote-sys 1115 | Connecting to remote-sys... 1116 | me@remote-sys's password: 1117 | sftp> ls 1118 | ubuntu-8.04-desktop-i386.iso 1119 | sftp> lcd Desktop 1120 | sftp> get ubuntu-8.04-desktop-i386.iso 1121 | Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04-desktop-i386.iso 1122 | /home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB 7.4MB/s 01:35 1123 | sftp> bye 1124 | ``` 1125 | 1126 | --- 1127 | 1128 | 1129 | ## 𝐒𝐞𝐚𝐫𝐜𝐡𝐢𝐧𝐠 𝐟𝐨𝐫 𝐟𝐢𝐥𝐞𝐬 1130 | 1131 | - `locate` : Find files by name 1132 | - `find` : Search for files in a directory hierarchy 1133 | - `xargs ` : Build and execute command lines from standard input 1134 | - `touch` : Change file times 1135 | - `stat`: Display file or file system status 1136 | 1137 | --- 1138 | 1139 | - `find` : find files the hard way 1140 | - `find ~` : to produce a listing of our home directory 1141 | - `find ~ | wc -l` : to count the number of files. 1142 | - `find ~ -type d | wc -l` : `-type d` limit the search to directories 1143 | - `find ~ -type f | wc -l` : `-type f` limit the search to regular files 1144 | - `find ~ -type f -name "*.JPG" -size +1M | wc -l`: all the regular files that match the wildcard pattern *.JPG and are larger than one megabyte 1145 | 1146 | File type | Description 1147 | --- | --- 1148 | `b` | Block special device file 1149 | `c` | Character special device file 1150 | `d` | Directory 1151 | `f` | Regular file 1152 | `l` | Symbolic link 1153 | 1154 | 1155 | - find size units 1156 | 1157 | Character | Unit 1158 | --- | --- 1159 | `b` | 512-byte blocks. This is default if no unit is specified. 1160 | `c` | Bytes 1161 | `w` | 2-byte words 1162 | `k` | Kilobytes (units of 1,024 bytes) 1163 | `M` | Megabytes (units of 1,048,576 bytes) 1164 | `c` | Gigabytes (units of 1,073,741,824 bytes) 1165 | 1166 | - More about `find` options: [Find cheatsheet](https://github.com/shreyaschavhan/linux-commands-cheatsheet/blob/main/find-cheatsheet.md) 1167 | 1168 | --- 1169 | 1170 | - `xargs` - It accepts input from standard input and converts it into an argument list for a specified command 1171 | 1172 | ``` 1173 | find ~ -type f -name 'foo*' -print | xargs ls -l 1174 | -rwxr-xr-x 1 me me 224 2007-10-29 18:44 /home/me/bin/foo 1175 | -rw-r--r-- 1 me me 0 2016-09-19 12:53 /home/me/foo.txt 1176 | ``` 1177 | 1178 | --- 1179 | 1180 | Remaining: 1181 | - archiving and backup 1182 | - regular expressions 1183 | - text processing 1184 | - compiling programs 1185 | - that's enough for now i guess 1186 | 1187 | -------------------------------------------------------------------------------- /cut-cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## 𝐂𝐮𝐭 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭 2 | 3 | Command | Explanation 4 | :-:|--- 5 | `cut -c 3` | display `3rd character` from each line of text 6 | `cut -c 2,7` | display the `2nd and 7th character` from each line of text 7 | `cut -c 2-7` | display a range of characters starting at the `2nd position` of a string and ending at the `7th position`(both positions included) 8 | `cut -c -4` | display the `first four` characters from each line of text 9 | `cut -d $'\t' -f -3` | display `first three` fields of a `tab delimited` file 10 | `cut -c 13-` | display the characters from `13th` position to the `end` 11 | `cut -d ' ' -f 4` | display `4th word` with space `' '` as a delimiter 12 | `cut -d ' ' -f -3` | display `first three words` with space `' '` used as a delimiter 13 | `cut -d $'\t' -f 2-` | given a `tab` delimited file, display the fields from `second fields to last field` 14 | 15 | 16 | -------------------------------------------------------------------------------- /emac-and-vi-mode.md: -------------------------------------------------------------------------------- 1 | ## 𝐄𝐦𝐚𝐜𝐬 𝐚𝐧𝐝 𝐕𝐢 𝐦𝐨𝐝𝐞𝐬 𝐢𝐧 𝐁𝐚𝐬𝐡 2 | 3 | 4 | - Emacs Mode 5 | > - This is usually the default editing mode when in the bash environment and means that you are able to use commands like those in Emacs (defined in the Readline library) to move the cursor, cut and paste text, or undo editing. 6 | ``` 7 | $ set -o emacs 8 | ``` 9 | 10 | > - Keyboard shortcuts: 11 | 12 | ``` 13 | ctrl-a Move cursor to beginning of line 14 | ctrl-e Move cursor to end of line 15 | meta-b Move cursor back one word 16 | meta-f Move cursor forward one word 17 | ctrl-w Cut the last word 18 | ctrl-u Cut everything before the cursor 19 | ctrl-k Cut everything after the cursor 20 | ctrl-y Paste the last thing to be cut 21 | ctrl-_ Undo 22 | NOTE: ctrl- = hold control, meta- = hold meta (where meta is usually the alt or escape key). 23 | A combination of ctrl-u to cut the line combined with ctrl-y can be very helpful. If you are in middle of typing a command and need to return to the prompt to retrieve more information you can use ctrl-u to save what you have typed in and after you retrieve the needed information ctrl-y will recover what was cut. 24 | 25 | ``` 26 | 27 | --- 28 | 29 | - Vi Mode 30 | > - Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you into command mode. 31 | 32 | ``` 33 | $ set -o vi 34 | ``` 35 | > - Keyboard Shortcuts: 36 | 37 | ``` 38 | h Move cursor left 39 | l Move cursor right 40 | A Move cursor to end of line and put in insert mode 41 | 0 (zero) Move cursor to beginning of line (doesn't put in insert mode) 42 | i Put into insert mode at current position 43 | a Put into insert mode after current position 44 | dd Delete line (saved for pasting) 45 | D Delete text after current cursor position (saved for pasting) 46 | p Paste text that was deleted 47 | j Move up through history commands 48 | k Move down through history commands 49 | u Undo 50 | ``` 51 | 52 | --- 53 | > - Suggested by: [GoldenCeks](https://www.reddit.com/r/HowToHack/comments/y0cu5t/comment/irtehdm/?utm_source=share&utm_medium=web2x&context=3) 54 | > - Reference: [set-o-vi-emacs](https://mywiki.wooledge.org/set-o-vi-emacs) 55 | > - Done 56 | -------------------------------------------------------------------------------- /find-cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## 𝐅𝐢𝐧𝐝 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭 2 | 3 | - Usage: 4 | ``` 5 | find 6 | ``` 7 | 8 | - Access time conditions: 9 | ``` 10 | -atime 0 # Last accessed between now and 24 hours ago 11 | -atime +0 # Accessed more than 24 hours ago 12 | -atime 1 # Accessed between 24 and 48 hours ago 13 | -atime +1 # Accessed more than 48 hours ago 14 | -atime -1 # Accessed less than 24 hours ago (same a 0) 15 | -ctime -6h30m # File status changed within the last 6 hours and 30 minutes 16 | -mtime +1w # Last modified more than 1 week ago 17 | ``` 18 | 19 | - Conditions: 20 | ``` 21 | -name "*.c" 22 | ``` 23 | ``` 24 | -user jonathan 25 | -nouser 26 | ``` 27 | ``` 28 | -type f # File 29 | -type d # Directory 30 | -type l # Symlink 31 | ``` 32 | ``` 33 | -depth 2 # At least 3 levels deep 34 | -regex PATTERN 35 | ``` 36 | ``` 37 | -size 8 # Exactly 8 512-bit blocks 38 | -size -128c # Smaller than 128 bytes 39 | -size 1440k # Exactly 1440KiB 40 | -size +10M # Larger than 10MiB 41 | -size +2G # Larger than 2GiB 42 | ``` 43 | ``` 44 | -newer file.txt 45 | -newerm file.txt # modified newer than file.txt 46 | -newerX file.txt # [c]hange, [m]odified, [B]create 47 | -newerXt "1 hour ago" # [t]imestamp 48 | ``` 49 | 50 | --- 51 | - Example: 52 | - find a file where: 53 | - owned by user bandit7 54 | - owned by group bandit6 55 | - 33 bytes in size 56 | ``` 57 | find / -user bandit7 -group bandit6 -size 33c 58 | ``` 59 | -------------------------------------------------------------------------------- /linux-command-line.md: -------------------------------------------------------------------------------- 1 | `Note: These are my notes for personal reference!` 2 | 3 | 4 | 5 | ## 𝐁𝐚𝐬𝐢𝐜 6 | 7 | - `date` : displays the current time and date 8 | ``` 9 | ┌──(shreyas㉿kali)-[~] 10 | └─$ date 11 | Tuesday 04 January 2022 03:39:43 PM IST 12 | ``` 13 | 14 | --- 15 | 16 | - `cal` : displays a calendar of the current month 17 | ``` 18 | ┌──(shreyas㉿kali)-[~] 19 | └─$ cal 20 | January 2022 21 | Su Mo Tu We Th Fr Sa 22 | 1 23 | 2 3 4 5 6 7 8 24 | 9 10 11 12 13 14 15 25 | 16 17 18 19 20 21 22 26 | 23 24 25 26 27 28 29 27 | 30 31 28 | 29 | ``` 30 | --- 31 | 32 | - `df` : the current amount of free space on our disk drives 33 | ``` 34 | ┌──(shreyas㉿kali)-[~] 35 | └─$ df 36 | Filesystem 1K-blocks Used Available Use% Mounted on 37 | udev 1953436 0 1953436 0% /dev 38 | tmpfs 399160 1168 397992 1% /run 39 | /dev/sda1 130538556 11247868 112613492 10% / 40 | tmpfs 1995784 0 1995784 0% /dev/shm 41 | tmpfs 5120 0 5120 0% /run/lock 42 | tmpfs 399156 68 399088 1% /run/user/1000 43 | 44 | ``` 45 | --- 46 | - `free` : display the amount of free memory 47 | ``` 48 | ┌──(shreyas㉿kali)-[~] 49 | └─$ free 50 | total used free shared buff/cache available 51 | Mem: 3991568 672232 2753624 8864 565712 3079888 52 | Swap: 998396 0 998396 53 | 54 | ``` 55 | --- 56 | 57 | ## 𝐍𝐚𝐯𝐢𝐠𝐚𝐭𝐢𝐨𝐧 58 | 59 | - `pwd` : print working directory 60 | ``` 61 | ┌──(shreyas㉿kali)-[~] 62 | └─$ pwd 63 | /home/shreyas 64 | 65 | ``` 66 | --- 67 | 68 | - `cd` : change directory 69 | ``` 70 | ┌──(shreyas㉿kali)-[~] 71 | └─$ cd practise 72 | 73 | ┌──(shreyas㉿kali)-[~/practise] 74 | └─$ pwd 75 | /home/shreyas/practise 76 | 77 | ┌──(shreyas㉿kali)-[~/practise] 78 | └─$ ls 79 | hackthebox 80 | 81 | ``` 82 | --- 83 | 84 | - `cd` shortcuts 85 | 86 | Shortcut | Result 87 | ---|--- 88 | cd | Changes the working directory to your home directory. 89 | cd - | Changes the working directory to the previous working directory. 90 | cd ~user_name | Changes the working directory to the home directory of user_name. For example, typing cd ~bob will change the directory to the home directory of user “bob.” 91 | 92 | --- 93 | 94 | - `ls` : List directory contents 95 | > - `ls -l`: output in long format 96 | > - `ls -t`: the t option to sort the result by the file’s modification time. 97 | > - `ls -lt --reverse`: --reverse to reverse the order of the sort. 98 | ``` 99 | ┌──(shreyas㉿kali)-[~] 100 | └─$ ls 101 | BugBounty Documents Music practise Templates 102 | Desktop Downloads Pictures Public Videos 103 | 104 | ┌──(shreyas㉿kali)-[~] 105 | └─$ ls /usr 106 | bin games include lib lib32 lib64 libexec libx32 local sbin share src 107 | 108 | ┌──(shreyas㉿kali)-[~] 109 | └─$ ls practise /usr 110 | practise: 111 | hackthebox 112 | 113 | /usr: 114 | bin games include lib lib32 lib64 libexec libx32 local sbin share src 115 | 116 | ┌──(shreyas㉿kali)-[~] 117 | └─$ ls -l 118 | total 176 119 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 120 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 121 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 122 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 123 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 124 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 125 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 126 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 127 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 128 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 129 | 130 | 131 | ┌──(shreyas㉿kali)-[~] 132 | └─$ ls -lt 133 | total 40 134 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 135 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 136 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 137 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 138 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 139 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 140 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 141 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 142 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 143 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 144 | 145 | 146 | ┌──(shreyas㉿kali)-[~] 147 | └─$ ls -lt --reverse 2 ⨯ 148 | total 40 149 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Videos 150 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Templates 151 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Public 152 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Pictures 153 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Music 154 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Documents 155 | drwxr-xr-x 2 shreyas shreyas 4096 Dec 14 19:34 Desktop 156 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 26 21:40 practise 157 | drwxr-xr-x 3 shreyas shreyas 4096 Dec 29 15:32 Downloads 158 | drwxr-xr-x 3 shreyas shreyas 4096 Jan 1 17:38 BugBounty 159 | 160 | ``` 161 | --- 162 | 163 | - `file filename` : the file command will print a brief description of the file’s contents 164 | ``` 165 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 166 | └─$ file flag.txt 167 | flag.txt: ASCII text, with no line terminators 168 | 169 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 170 | └─$ file pack.ovpn 171 | pack.ovpn: ASCII text 172 | 173 | ``` 174 | --- 175 | 176 | - `less` : allows us to scroll forward and backward through a text file. 177 | - `Note: less is more. Means both commands are same` 178 | ``` 179 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 180 | └─$ cat example | less 181 | 182 | ┌──(shreyas㉿kali)-[~/practise/hackthebox] 183 | └─$ less example 184 | ``` 185 | 186 | Command | Action 187 | --- | --- 188 | `PAGE UP` or `b` | Scroll back one page 189 | `PAGE DOWN` or `space` | Scroll forward one page 190 | `Up arrow` | Scroll up one line 191 | `Down arrow` | Scroll down one line 192 | `G` | Move to the end of the text file 193 | `1G` or `g` | Move to the beginning of the text file 194 | `/characters` | Search forward to the next occurrence of characters 195 | `n` | Search for the next occurrence of the previous search 196 | `h` | Display help screen 197 | `q` | Quit less 198 | 199 | 200 | --- 201 | 202 | ## 𝐌𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐧𝐠 𝐟𝐢𝐥𝐞𝐬 𝐚𝐧𝐝 𝐝𝐢𝐫𝐞𝐜𝐭𝐨𝐫𝐢𝐞𝐬 203 | 204 | - Wildcards: 205 | 206 | Wildcards | Meaning 207 | --- | --- 208 | `*` | Matches any character 209 | `?` | Matches any single character 210 | `[characters]` | Matches any character that is a member of the set characters 211 | `[!characters]` | Matches any character that is not a member of the set characters 212 | `[:class:]]` | Matches any character that is member of the specified class 213 | 214 | - List of most commonly used character classes 215 | 216 | Character class | Meaning 217 | --- | --- 218 | `[:alnum:]` | Matches any alphanumeric character 219 | `[:alpha:]` | Matches any alphabetic characters 220 | `[:digit:]` | Matches any numerical 221 | `[:lower:]` | Matches any lowercase letter 222 | `[:upper:]` | Matches any uppercase 223 | 224 | 225 | - Wildcard examples: 226 | 227 | Pattern | Matches 228 | --- | --- 229 | `*` | All files 230 | `g*` | Any file beginning with g 231 | `b*.txt` | Any file beginning with b followed by any characters and ending with .txt 232 | `Data???` | Any file beginning with Data followed by exactly three characters 233 | `[abc]*` | Any file beginning with either an a, a b, or a c 234 | `BACKUP.[0-9][0-9][0-9]` | Any file beginning with BACKUP. followed by exactly three numerals 235 | `[[:upper:]]*` | Any file beginning with an uppercase letter 236 | `[![:digit:]]*` | Any file not beginning with a numeral 237 | `*[[:lower:]123]` | Any file ending with a lowercase letter or the numerals 1, 2, or 3 238 | 239 | - `Wildcards can be used with any command that accepts filenames as arguments` 240 | 241 | --- 242 | 243 | - `mkdir` - make directory 244 | - `mkdir dir` - single directory 245 | - `mkdir dir1 dir2 dir3` - multiple directories 246 | 247 | 248 | ``` 249 | ┌──(shreyas㉿kali)-[~/practise] 250 | └─$ mkdir commandline 251 | 252 | ┌──(shreyas㉿kali)-[~/practise] 253 | └─$ ls 254 | commandline hackthebox 255 | 256 | ┌──(shreyas㉿kali)-[~/practise/commandline] 257 | └─$ mkdir dir1 dir2 dir3 258 | 259 | ┌──(shreyas㉿kali)-[~/practise/commandline] 260 | └─$ ls 261 | dir1 dir2 dir3 262 | 263 | ``` 264 | --- 265 | 266 | - `cp` - copy files and directories 267 | - `cp item1 item2` : copy single file item1 into item2 268 | - `cp item... directory` : copies multiple items (either files or directories) into a directory. 269 | 270 | Option | Meaning 271 | --- | --- 272 | `-a`,`--archive` | Copy the files and directories and all of their attributes, including ownerships and permissions. 273 | `-i`, `--interactive` | Before overwriting an existing file, prompt the user for confirmation. 274 | `-r`, `--recursive` | Recursively copy directories and their contents. This option (or the -a option) is required when copying directories. 275 | `-u`, `--update` | When copying files from one directory to another, only copy files that either don’t exist or are newer than the existing corresponding files in the destination directory. This is useful when copying large numbers of files as it skips files that don’t need to be copied 276 | `-v`, `--verbose` | Display informative messages as the copy is performed. 277 | 278 | - `mv` is same as `cp` 279 | 280 | --- 281 | 282 | - `rm file` : remove files and directories 283 | 284 | 285 | Option | Meaning 286 | --- | --- 287 | `-i`, `--interactive` | Before deleting an existing file, prompt the user for confirmation. 288 | `-r`, `--recursive` | Recursively delete directories. This means that if a directory being deleted has subdirectories, delete them too. To delete a directory, this option must be specified. 289 | `-f`, `--force` | Ignore nonexistent files and do not prompt. This overrides the --interactive option. 290 | `-v`, `--verbose` | Display informative messages as the deletion is performed. 291 | 292 | --- 293 | 294 | - `ln` : create links 295 | - `ln file link` : create a hard link 296 | - `ln -s item link` : creates a symbolic link 297 | 298 | --- 299 | 300 | ## 𝐖𝐨𝐫𝐤𝐢𝐧𝐠 𝐰𝐢𝐭𝐡 𝐜𝐨𝐦𝐦𝐚𝐧𝐝𝐬 301 | 302 | - `type`: is a shell builtin that displays the kind of command the shell will execute 303 | 304 | ``` 305 | ┌──(shreyas㉿kali)-[~/practise/commandline] 306 | └─$ type ls 307 | ls is an alias for ls --color=auto 308 | 309 | ┌──(shreyas㉿kali)-[~/practise/commandline] 310 | └─$ type ssh 311 | ssh is /usr/bin/ssh 312 | 313 | ┌──(shreyas㉿kali)-[~/practise/commandline] 314 | └─$ type cd 315 | cd is a shell builtin 316 | 317 | ``` 318 | --- 319 | 320 | - `which` : Display an Executable’s Location 321 | 322 | ``` 323 | ┌──(shreyas㉿kali)-[~/practise/commandline] 324 | └─$ which ls 325 | ls: aliased to ls --color=auto 326 | 327 | ┌──(shreyas㉿kali)-[~/practise/commandline] 328 | └─$ which pwd 329 | pwd: shell built-in command 330 | 331 | ┌──(shreyas㉿kali)-[~/practise/commandline] 332 | └─$ which cd 333 | cd: shell built-in command 334 | 335 | ┌──(shreyas㉿kali)-[~/practise/commandline] 336 | └─$ which gedit 337 | /usr/bin/gedit 338 | 339 | ┌──(shreyas㉿kali)-[~/practise/commandline] 340 | └─$ which firefox 341 | /usr/bin/firefox 342 | 343 | ``` 344 | 345 | --- 346 | 347 | - `man` : Display a Program’s Manual Page 348 | 349 | ``` 350 | ┌──(shreyas㉿kali)-[~/practise/commandline] 351 | └─$ man ls 352 | ``` 353 | 354 | ``` 355 | LS(1) User Commands LS(1) 356 | 357 | NAME 358 | ls - list directory contents 359 | 360 | SYNOPSIS 361 | ls [OPTION]... [FILE]... 362 | 363 | DESCRIPTION 364 | List information about the FILEs (the current directory by default). Sort 365 | entries alphabetically if none of -cftuvSUX nor --sort is specified. 366 | 367 | Mandatory arguments to long options are mandatory for short options too. 368 | 369 | -a, --all 370 | do not ignore entries starting with . 371 | 372 | -A, --almost-all 373 | do not list implied . and .. 374 | 375 | --author 376 | with -l, print the author of each file 377 | 378 | Manual page ls(1) line 1 (press h for help or q to quit) 379 | 380 | ``` 381 | 382 | --- 383 | 384 | - `apropos` - Display Appropriate Commands 385 | 386 | ``` 387 | ┌──(shreyas㉿kali)-[~/practise/commandline] 388 | └─$ apropos copy 389 | cifsdd (8) - convert and copy a file over SMB 390 | COPY (7) - copy data between a file and a table 391 | cp (1) - copy files and directories 392 | cpgr (8) - copy with locking the given file to the password or group file 393 | cpio (1) - copy files to and from archives 394 | cppw (8) - copy with locking the given file to the password or group file 395 | dd (1) - convert and copy a file 396 | debconf-copydb (1) - copy a debconf database 397 | git-checkout-index (1) - Copy files from the index to the working tree 398 | gvfs-copy (1) - Deprecated equivalent of gio copy 399 | install (1) - copy files and set attributes 400 | mariadb-hotcopy (1) - a database backup program 401 | mysqlhotcopy (1) - a database backup program 402 | ntfscp (8) - copy file to an NTFS volume. 403 | objcopy (1) - copy and translate object files 404 | ptrepack (1) - Copy any PyTables Leaf, Group or complete subtree into anothe... 405 | rcp (1) - OpenSSH secure file copy 406 | rsync (1) - a fast, versatile, remote (and local) file-copying tool 407 | scp (1) - OpenSSH secure file copy 408 | ssh-copy-id (1) - use locally available keys to authorise logins on a remote ma... 409 | svnversion (1) - Produce a compact version identifier for a working copy. 410 | vfs_shadow_copy (8) - Expose snapshots to Windows clients as shadow copies. 411 | vfs_shadow_copy2 (8) - Expose snapshots to Windows clients as shadow copies. 412 | x86_64-linux-gnu-objcopy (1) - copy and translate object files 413 | 414 | ``` 415 | 416 | --- 417 | 418 | - `whatis` : Display One-line Manual Page Descriptions 419 | 420 | ``` 421 | ┌──(shreyas㉿kali)-[~/practise/commandline] 422 | └─$ whatis rm 423 | rm (1) - remove files or directories 424 | 425 | ┌──(shreyas㉿kali)-[~/practise/commandline] 426 | └─$ whatis ls 427 | ls (1) - list directory contents 428 | 429 | ┌──(shreyas㉿kali)-[~/practise/commandline] 430 | └─$ whatis sudo 431 | sudo (8) - execute a command as another user 432 | 433 | ``` 434 | 435 | --- 436 | 437 | - `info` : Display a Program’s Info Entry 438 | 439 | ``` 440 | 441 | ┌──(shreyas㉿kali)-[~/practise/commandline] 442 | └─$ info ls 443 | 444 | ``` 445 | 446 | ``` 447 | Next: dir invocation, Up: Directory listing 448 | 449 | 10.1 ‘ls’: List directory contents 450 | ================================== 451 | 452 | The ‘ls’ program lists information about files (of any type, including 453 | directories). Options and file arguments can be intermixed arbitrarily, 454 | as usual. 455 | 456 | For non-option command-line arguments that are directories, by 457 | default ‘ls’ lists the contents of directories, not recursively, and 458 | omitting files with names beginning with ‘.’. For other non-option 459 | arguments, by default ‘ls’ lists just the file name. If no non-option 460 | argument is specified, ‘ls’ operates on the current directory, acting as 461 | if it had been invoked with a single argument of ‘.’. 462 | 463 | By default, the output is sorted alphabetically, according to the 464 | locale settings in effect.(1) If standard output is a terminal, the 465 | output is in columns (sorted vertically) and control characters are 466 | output as question marks; otherwise, the output is listed one per line 467 | and control characters are output as-is. 468 | 469 | -----Info: (coreutils)ls invocation, 56 lines --Top------------------------------------ 470 | Follow xref: gument is specified, ‘ls’ operates on the current directory, acting asif 471 | ``` 472 | 473 | --- 474 | 475 | - `alias` : Creating Our Own Commands with alias 476 | - `trick: It’s possible to put more than one command on a line by separating each command with a semicolon` 477 | - `command1; command2; command3...` 478 | 479 | ``` 480 | [me@linuxbox ~]$ cd /usr; ls; cd - 481 | bin games include lib local sbin share src 482 | /home/me 483 | [me@linuxbox ~]$ 484 | ``` 485 | ``` 486 | [me@linuxbox ~]$ type foo 487 | bash: type: foo: not found 488 | ``` 489 | ``` 490 | [me@linuxbox ~]$ alias foo='cd /usr; ls; cd -' 491 | [me@linuxbox ~]$ foo 492 | bin games include lib local sbin share src 493 | /home/me 494 | [me@linuxbox ~]$ 495 | [me@linuxbox ~]$ type foo 496 | foo is aliased to `cd /usr; ls; cd -' 497 | ``` 498 | ``` 499 | [me@linuxbox ~]$ unalias foo 500 | [me@linuxbox ~]$ type foo 501 | bash: type: foo: not found 502 | ``` 503 | 504 | --- 505 | 506 | ## 𝐑𝐞𝐝𝐢𝐫𝐞𝐜𝐭𝐢𝐨𝐧 507 | 508 | - ` > ` : Redirecting Standard Output 509 | 510 | ``` 511 | ┌──(shreyas㉿kali)-[~/practise/commandline] 512 | └─$ ls -l /usr/bin > ls-output.txt 513 | 514 | ┌──(shreyas㉿kali)-[~/practise/commandline] 515 | └─$ ls -l 516 | total 180 517 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir1 518 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir2 519 | drwxr-xr-x 2 shreyas shreyas 4096 Jan 4 17:21 dir3 520 | -rw-r--r-- 1 shreyas shreyas 171639 Jan 4 18:21 ls-output.txt 521 | 522 | ``` 523 | 524 | --- 525 | 526 | - `command >> file` - append redirected output to a file instead of overwriting the file 527 | 528 | ``` 529 | [me@linuxbox ~]$ ls -l /usr/bin >> ls-output.txt 530 | ``` 531 | 532 | --- 533 | 534 | - `0>` OR `<` : redirecting standard input 535 | - `>` : redirecting standard output 536 | - `2>` : redirecting standard error 537 | 538 | ``` 539 | [me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt 540 | ``` 541 | 542 | --- 543 | 544 | - `ls -l /bin/usr > ls-output.txt 2>&1` OR ` ls -l /bin/usr &> ls-output.txt`: Redirecting Standard Output and Standard Error to One File 545 | - `ls -l /bin/usr 2> /dev/null` : Disposing unwanted output 546 | 547 | --- 548 | 549 | - `command1 | command2` : Pipeline 550 | - `wc` : Print line, Word, and Byte counts 551 | - `grep` : print line matching pattern 552 | - `head -n ls-output.txt` : print initial lines of file 553 | - `tail -n ls-output.txt` : print last lines of files 554 | - `tee` : Read from Stdin and Output to Stdout and Files 555 | - 556 | 557 | ``` 558 | ┌──(shreyas㉿kali)-[~/practise/commandline] 559 | └─$ wc ls-output.txt 560 | 2557 24294 171639 ls-output.txt 561 | 562 | ``` 563 | ``` 564 | [me@linuxbox ~]$ head -n 5 ls-output.txt 565 | total 343496 566 | -rwxr-xr-x 1 root root 31316 2017-12-05 08:58 [ 567 | -rwxr-xr-x 1 root root 8240 2017-12-09 13:39 411toppm 568 | -rwxr-xr-x 1 root root 111276 2017-11-26 14:27 a2p 569 | -rwxr-xr-x 1 root root 25368 2016-10-06 20:16 a52dec 570 | [me@linuxbox ~]$ tail -n 5 ls-output.txt 571 | -rwxr-xr-x 1 root root 5234 2017-06-27 10:56 znew 572 | -rwxr-xr-x 1 root root 691 2015-09-10 04:21 zonetab2pot.py 573 | -rw-r--r-- 1 root root 930 2017-11-01 12:23 zonetab2pot.pyc 574 | -rw-r--r-- 1 root root 930 2017-11-01 12:23 zonetab2pot.pyo 575 | lrwxrwxrwx 1 root root 6 2016-01-31 05:22 zsoelim -> soelim 576 | ``` 577 | 578 | --- 579 | 580 | ## 𝐒𝐞𝐞𝐢𝐧𝐠 𝐭𝐡𝐞 𝐰𝐨𝐫𝐥𝐝 𝐚𝐬 𝐭𝐡𝐞 𝐬𝐡𝐞𝐥𝐥 𝐬𝐞𝐞𝐬 𝐢𝐭 581 | 582 | - `echo` : Display a line of text 583 | - `echo *` : works same as `ls` 584 | - `echo D*` : Display files/directories which starts with D 585 | - `echo *s` : Display files/drectories which ends with s 586 | - `echo [[:upper:]]*` : Display files/directories that starts with uppercase letters 587 | - `echo /usr/*/share` : display all directories between /usr/ & /share 588 | - `echo ~` : tilde expansion 589 | 590 | ``` 591 | ┌──(shreyas㉿kali)-[~] 592 | └─$ echo hello there my name is shreyas 593 | hello there my name is shreyas 594 | 595 | ┌──(shreyas㉿kali)-[~] 596 | └─$ echo * 597 | BugBounty Desktop Documents Downloads Music Pictures practise Public Templates Videos 598 | 599 | ┌──(shreyas㉿kali)-[~] 600 | └─$ echo D* 601 | Desktop Documents Downloads 602 | 603 | ┌──(shreyas㉿kali)-[~] 604 | └─$ echo *s 605 | Documents Downloads Pictures Templates Videos 606 | 607 | ┌──(shreyas㉿kali)-[~] 608 | └─$ echo [[:upper:]]* 609 | BugBounty Desktop Documents Downloads Music Pictures Public Templates Videos 610 | 611 | ┌──(shreyas㉿kali)-[~] 612 | └─$ echo /usr/*/share 613 | /usr/local/share 614 | 615 | ┌──(shreyas㉿kali)-[~] 616 | └─$ echo ~ 617 | /home/shreyas 618 | 619 | 620 | ``` 621 | 622 | - Arithmetic Expansion: 623 | - `$((expression))` 624 | 625 | ``` 626 | ┌──(shreyas㉿kali)-[~] 627 | └─$ echo $((2 + 2)) 628 | 4 629 | 630 | ┌──(shreyas㉿kali)-[~] 631 | └─$ echo $(($((5**2)) * 3)) 632 | 75 633 | 634 | ``` 635 | 636 | Operator | Description 637 | --- | --- 638 | `+` | Addition 639 | `-` | Subtraction 640 | `*` | Multiplication 641 | `/` | Division (but remember, since expansion supports only integer arithmetic, results are integers) 642 | `%` | Modulo, which simply means “remainder” 643 | `**` | Exponentiation 644 | 645 | - Brace Expansion: create multiple text strings from a pattern containing braces 646 | 647 | ``` 648 | ┌──(shreyas㉿kali)-[~] 649 | └─$ echo Front-{A,B,C}-Back 650 | Front-A-Back Front-B-Back Front-C-Back 651 | 652 | ┌──(shreyas㉿kali)-[~] 653 | └─$ echo Number_{1..5} 654 | Number_1 Number_2 Number_3 Number_4 Number_5 655 | 656 | ┌──(shreyas㉿kali)-[~] 657 | └─$ echo {01..15} 658 | 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 659 | 660 | ┌──(shreyas㉿kali)-[~] 661 | └─$ echo a{A{1,2},B{3,4}}b 662 | aA1b aA2b aB3b aB4b 663 | 664 | ``` 665 | 666 | - Parameter expansion: `echo $var` 667 | - Command Substitution 668 | - `echo $(ls)` 669 | - `ls -l $(which cp)` 670 | - `file $(ls -d /usr/bin/* | grep zip)` 671 | 672 | --- 673 | 674 | - Quoting: 675 | - Double Quotes: If we place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are $ (dollar sign), \ (backslash), and ` (backtick). 676 | - Single Quotes: If we need to suppress all expansions, we use single quotes. 677 | - Escaping Characters: 678 | - `\` : is used for escaping 679 | - Backslash Escape Situation: 680 | 681 | Escape Sequence | Meaning 682 | --- | --- 683 | `\a` | Bell (an alert that causes the computer to beep) 684 | `\b` | Backspace 685 | `\n` | Newline; on Unix-like systems, this produces a line feed 686 | `\r` | Carriage return 687 | `\t` | tab 688 | 689 | ``` 690 | ┌──(shreyas㉿kali)-[~] 691 | └─$ sleep 10; echo -e "Time's up\a" 692 | Time's up 693 | 694 | ``` 695 | --- 696 | 697 | ## 𝐀𝐝𝐯𝐚𝐧𝐜𝐞𝐝 𝐊𝐞𝐲𝐛𝐨𝐚𝐫𝐝 𝐓𝐫𝐢𝐜𝐤𝐬 698 | 699 | - `clear` : Clear the terminal screen 700 | - `history` : Display or manipulate the history list 701 | 702 | - Cursor Movement: 703 | 704 | Key | Action 705 | --- | --- 706 | `CTRL-A` | Move the cursor to the beginning of line 707 | `CTRL-E` | Move cursor to the end of the line 708 | `CTRL-F` | Move cursor forward one character; same as the right arrow key 709 | `CTRL-B` | Move cursor backward one character; same as the left arrow key 710 | `ALT-F` | Move cursor one word forward 711 | `ALT-B` | Move cursor backward one word 712 | `CTRL-L` | Clear screen and move the cursor to the top left corner. Same as `clear` command 713 | 714 | --- 715 | - Modifying Text 716 | 717 | 718 | Key | Action 719 | --- | --- 720 | `CTRL-D` | Delete the character at the cursor location 721 | `CTRL-T` | Transpose the character at the cursor location 722 | `ALT-T` | Transpose the word at the cursor location with the one preceding it. 723 | `ALT-L` | Convert the characters from the cursor location to the end of the word to lowercase. 724 | `ALT-U` | Convert the characters from the cursor location to the end of the word to uppercase. 725 | 726 | --- 727 | 728 | - History Expansion 729 | 730 | Sequence | Action 731 | --- | --- 732 | `!!` | Repeat the last command. It is probably easier to press the up arrow and ENTER 733 | `!number` | Repeat history list item `number`. 734 | `!string` | Repeat last history list item starting with `string` 735 | `!?string` | Repeat last history list item containing `string` 736 | 737 | 738 | --- 739 | 740 | ## 𝐏𝐞𝐫𝐦𝐢𝐬𝐬𝐢𝐨𝐧𝐬 741 | 742 | - `id` : Display user identity 743 | - `chmod` : Change a file’s mode 744 | - `umask` : Set the default file permissions 745 | - `su` : Run a shell as another user 746 | - `sudo` : Execute a command as another user 747 | - `chown`: Change a file’s owner 748 | - `chgrp`: Change a file’s group ownership 749 | - `passwd`: Change a user’s password 750 | 751 | - Permission attribute Examples: 752 | 753 | File Attributes | Meaning 754 | --- | --- 755 | `-rwx------` | A regular file that is readable, writable, and executable by the file’s owner. No one else has any access. 756 | `-rw-------` | A regular file that is readable and writable by the file’s owner. No one else has any access. 757 | `-rw-r--r--` | A regular file that is readable and writable by the file’s owner. Members of the file’s owner group may read the file. The file is world-readable. 758 | `-rwxr-xr-x` | A regular file that is readable, writable, and executable by the file’s owner. The file may be read and executed by everybody else. 759 | `-rw-rw----` | A regular file that is readable and writable by the file’s owner and members of the file’s group owner only. 760 | `lrwxrwxrwx` | A symbolic link. All symbolic links have “dummy” permissions. The real permissions are kept with the actual file pointed to by the symbolic link. 761 | `drwxrwx---` | A directory. The owner and the members of the owner group may enter the directory and create, rename, and remove files within the directory. 762 | `drwxr-x---` | A directory. The owner may enter the directory and create, rename, and delete files within the directory. Members of the owner group may enter the directory but cannot create, delete, or rename files. 763 | 764 | --- 765 | 766 | - `chmod` : Change File Mode 767 | - 6(rw-) 768 | - 7(rwx) 769 | - 5(r-x) 770 | - 4(r--) 771 | - 0(---) 772 | 773 | Symbol | Meaning 774 | --- | --- 775 | `u` | Short for "user" but means the file or directory owner. 776 | `g` | Group owner 777 | `o` | Short for "others" but means world 778 | `a` | Short for "all". This is a combination of `u`, `g`, and `o`. 779 | 780 | - If no character is specified, “all” will be assumed. The operation may be a + indicating that a permission is to be added, a - indicating that a permission is to be taken away, or a = indicating that only the specified permissions are to be applied and that all others are to be removed. 781 | 782 | Notation | Meaning 783 | --- | --- 784 | `u+x` | Add execute permission for the owner. 785 | `u-x` | Remove execute permission from the owner. 786 | `+x` | Add execute permission for the owner, group, and world. This is equivalent to a+x. 787 | `o-rw` | Remove the read and write permissions from anyone besides the owner and group owner. 788 | `go=rw` | Set the group owner and anyone besides the owner to have read and write permissions. If either the group owner or the world previously had execute permission, it is removed. 789 | `u+x,go=rx` | Add execute permission for the owner and set the permissions for the group and others to read and execute. Multiple specifications may be separated by commas. 790 | 791 | --- 792 | 793 | ## 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐞𝐬 794 | 795 | - `ps` : Report a snapshot of current processes 796 | - `top` : Display tasks 797 | - `jobs` : List active jobs 798 | - `bg` : Place a job in the background 799 | - `fg` : Place a job in the foreground 800 | - `kill` : Send a signal to a process 801 | - `killall` : Kill process by name 802 | - `shutdown` : Shut down or reboot the system 803 | 804 | 805 | 806 | --- 807 | 808 | ## 𝐍𝐞𝐭𝐰𝐨𝐫𝐤𝐢𝐧𝐠 809 | 810 | - `ping` : Checks if a network is reachable, `ping` command sends a special network packet called an `ICMP ECHO_REQUEST` to a specified host. Most network devices receiving this packet will reply to it, allowing the network connection to be verified. 811 | 812 | ``` 813 | ┌──(shreyas㉿kali)-[~] 814 | └─$ ping youtube.com 815 | PING youtube.com (142.250.204.46) 56(84) bytes of data. 816 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=1 ttl=128 time=149 ms 817 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=2 ttl=128 time=151 ms 818 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=3 ttl=128 time=188 ms 819 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=4 ttl=128 time=140 ms 820 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=5 ttl=128 time=139 ms 821 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=6 ttl=128 time=120 ms 822 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=7 ttl=128 time=131 ms 823 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=8 ttl=128 time=148 ms 824 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=9 ttl=128 time=137 ms 825 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=10 ttl=128 time=132 ms 826 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=11 ttl=128 time=144 ms 827 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=12 ttl=128 time=128 ms 828 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=13 ttl=128 time=128 ms 829 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=14 ttl=128 time=141 ms 830 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=15 ttl=128 time=135 ms 831 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=16 ttl=128 time=130 ms 832 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=17 ttl=128 time=133 ms 833 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=18 ttl=128 time=142 ms 834 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=19 ttl=128 time=134 ms 835 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=20 ttl=128 time=137 ms 836 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=21 ttl=128 time=139 ms 837 | ^C64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=22 ttl=128 time=140 ms 838 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=23 ttl=128 time=121 ms 839 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=24 ttl=128 time=146 ms 840 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=25 ttl=128 time=136 ms 841 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=26 ttl=128 time=165 ms 842 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=27 ttl=128 time=176 ms 843 | 64 bytes from hkg07s38-in-f14.1e100.net (142.250.204.46): icmp_seq=28 ttl=128 time=132 ms 844 | ^C 845 | --- youtube.com ping statistics --- 846 | 28 packets transmitted, 28 received, 0% packet loss, time 27045ms 847 | rtt min/avg/max/mdev = 120.372/140.817/187.758/14.526 ms 848 | 849 | ``` 850 | 851 | --- 852 | 853 | - `traceroute` : lists all the “hops” network traffic takes to get from the local system to a specified host. 854 | 855 | ``` 856 | ┌──(shreyas㉿kali)-[~] 857 | └─$ traceroute google.com 858 | traceroute to google.com (142.250.204.110), 30 hops max, 60 byte packets 859 | 1 192.168.29.2 (192.168.29.2) 0.227 ms 0.099 ms 0.175 ms 860 | 2 * * * 861 | 3 * * * 862 | 4 * * * 863 | 5 * * * 864 | 6 * * * 865 | 7 * * * 866 | 8 * * * 867 | 9 * * * 868 | 10 * * * 869 | 11 * * * 870 | 12 * * * 871 | 13 * * * 872 | 873 | ``` 874 | 875 | --- 876 | 877 | - `ip a` : It replaces the earlier and now deprecated `ifconfig` program. 878 | 879 | ``` 880 | ┌──(shreyas㉿kali)-[~] 881 | └─$ ip a 882 | 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 883 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 884 | inet 127.0.0.1/8 scope host lo 885 | valid_lft forever preferred_lft forever 886 | inet6 ::1/128 scope host 887 | valid_lft forever preferred_lft forever 888 | 2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 889 | link/ether 00:0c:29:c5:88:a0 brd ff:ff:ff:ff:ff:ff 890 | inet 192.168.x.x/24 brd 192.168.x.x scope global dynamic noprefixroute eth0 891 | valid_lft 1630sec preferred_lft 1630sec 892 | inet6 fe80::20c:29ff:x:x/64 scope link noprefixroute 893 | valid_lft forever preferred_lft forever 894 | 895 | ``` 896 | 897 | --- 898 | 899 | - `netstat` : The netstat program is used to examine various network settings and statistics. 900 | - `-r` option will display the kernel’s network routing table 901 | - `ie` : we can examine the network interfaces in our system 902 | 903 | ``` 904 | ┌──(shreyas㉿kali)-[~] 905 | └─$ netstat -ie 906 | Kernel Interface table 907 | eth0: flags=4163 mtu 1500 908 | inet 192.168.x.x netmask 255.255.255.0 broadcast 192.168.29.255 909 | inet6 fe80::20c:29ff:x:x prefixlen 64 scopeid 0x20 910 | ether 00:0c:29:c5:88:a0 txqueuelen 1000 (Ethernet) 911 | RX packets 102 bytes 11285 (11.0 KiB) 912 | RX errors 0 dropped 0 overruns 0 frame 0 913 | TX packets 207 bytes 17053 (16.6 KiB) 914 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 915 | 916 | lo: flags=73 mtu 65536 917 | inet 127.0.0.1 netmask 255.0.0.0 918 | inet6 ::1 prefixlen 128 scopeid 0x10 919 | loop txqueuelen 1000 (Local Loopback) 920 | RX packets 8 bytes 400 (400.0 B) 921 | RX errors 0 dropped 0 overruns 0 frame 0 922 | TX packets 8 bytes 400 (400.0 B) 923 | TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 924 | 925 | 926 | ┌──(shreyas㉿kali)-[~] 927 | └─$ netstat -r 928 | Kernel IP routing table 929 | Destination Gateway Genmask Flags MSS Window irtt Iface 930 | default 192.168.29.2 0.0.0.0 UG 0 0 0 eth0 931 | 192.168.29.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 932 | 933 | 934 | ``` 935 | 936 | --- 937 | 938 | Transporting Files over a Network 939 | 940 | - `ftp` : `ftp` is used to communicate with FTP servers, machines that contain files that can be uploaded and downloaded over a network. `FTP` (in its original form) is not secure because it sends account names and passwords in cleartext. 941 | 942 | ``` 943 | [me@linuxbox ~]$ ftp fileserver 944 | Connected to fileserver.localdomain. 945 | 220 (vsFTPd 2.0.1) 946 | Name (fileserver:me): anonymous 947 | 331 Please specify the password. 948 | Password: 949 | 230 Login successful. 950 | Remote system type is UNIX. 951 | Using binary mode to transfer files. 952 | ftp> cd pub/cd_images/ubuntu-18.04 953 | 250 Directory successfully changed. 954 | ftp> ls 955 | 200 PORT command successful. Consider using PASV. 956 | 150 Here comes the directory listing. 957 | -rw-rw-r-- 1 500 500 733079552 Apr 25 03:53 ubuntu-18.04-desktop-amd64.iso 958 | 226 Directory send OK. 959 | ftp> lcd Desktop 960 | Local directory now /home/me/Desktop 961 | ftp> get ubuntu-18.04-desktop-amd64.iso 962 | local: ubuntu-18.04-desktop-amd64.iso remote: ubuntu-18.04-desktop-amd64.iso 963 | 200 PORT command successful. Consider using PASV. 964 | 150 Opening BINARY mode data connection for ubuntu-18.04-desktop-amd64.iso (733079552 bytes). 965 | 226 File send OK. 966 | 733079552 bytes received in 68.56 secs (10441.5 kB/s) 967 | ftp> bye 968 | ``` 969 | 970 | Command | Meaning 971 | --- | --- 972 | `ftp fileserver` | Invoke the `ftp` program and have it connect the FTP server `fileserver` 973 | `anonymous` | Login name. After the login prompt, a password prompt will appear. Some servers will accept a blank password; others will require a password in the form of an email address. In that case, try something like user@example. 974 | `cd` | change directory 975 | `ls` | list directory 976 | `lcd Desktop` | Change the directory on the local system to ~/Desktop. In the example, the ftp program was invoked when the working directory was ~. This command changes the working directory to ~/Desktop. 977 | `get` | transfer file from remote server to local system 978 | `bye` | Log off the remote server and end the ftp program session. The commands quit and exit may also be used. 979 | 980 | - `lftp` is a Better ftp 981 | 982 | --- 983 | 984 | - `wget` : It is useful for downloading content from both web and FTP sites. Single files, multiple files, and even entire sites can be downloaded. 985 | 986 | ``` 987 | [me@linuxbox ~]$ wget http://linuxcommand.org/index.php 988 | --11:02:51-- http://linuxcommand.org/index.php 989 | => `index.php' 990 | Resolving linuxcommand.org... 66.35.250.210 991 | Connecting to linuxcommand.org|66.35.250.210|:80... connected. 992 | HTTP request sent, awaiting response... 200 OK 993 | Length: unspecified [text/html] 994 | 995 | [ <=> ] 3,120 --.--K/s 996 | 997 | 11:02:51 (161.75 MB/s) - `index.php' saved [3120] 998 | ``` 999 | 1000 | --- 1001 | 1002 | - `ssh` : SSH solves the two basic problems of secure communication with a remote host. 1003 | - It authenticates that the remote host is who it says it is (thus preventing so-called man-in-the-middle attacks). 1004 | - It encrypts all of the communications between the local and remote hosts. 1005 | - `ssh remote-sys` : To connect to a remote host named remote-sys 1006 | - `ssh username@remote-sys` : login with specific username 1007 | - `ssh remote-sys `: to execute just a single command 1008 | 1009 | 1010 | 1011 | ``` 1012 | [me@linuxbox ~]$ ssh remote-sys 1013 | The authenticity of host 'remote-sys (192.168.1.4)' can't be established. 1014 | RSA key fingerprint is 41:ed:7a:df:23:19:bf:3c:a5:17:bc:61:b3:7f:d9:bb. 1015 | Are you sure you want to continue connecting (yes/no)? 1016 | ``` 1017 | 1018 | --- 1019 | 1020 | - `scp` - (secure copy). copy files from local host to remote host 1021 | 1022 | ``` 1023 | [me@linuxbox ~]$ scp remote-sys:document.txt . 1024 | me@remote-sys's password: 1025 | document.txt 100% 5581 5.5KB/s 00:00 1026 | [me@linuxbox ~]$ 1027 | ``` 1028 | 1029 | - `sftp` : SSH file-copying program 1030 | 1031 | ``` 1032 | [me@linuxbox ~]$ sftp remote-sys 1033 | Connecting to remote-sys... 1034 | me@remote-sys's password: 1035 | sftp> ls 1036 | ubuntu-8.04-desktop-i386.iso 1037 | sftp> lcd Desktop 1038 | sftp> get ubuntu-8.04-desktop-i386.iso 1039 | Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04-desktop-i386.iso 1040 | /home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB 7.4MB/s 01:35 1041 | sftp> bye 1042 | ``` 1043 | 1044 | --- 1045 | 1046 | 1047 | ## 𝐒𝐞𝐚𝐫𝐜𝐡𝐢𝐧𝐠 𝐟𝐨𝐫 𝐟𝐢𝐥𝐞𝐬 1048 | 1049 | - `locate` : Find files by name 1050 | - `find` : Search for files in a directory hierarchy 1051 | - `xargs ` : Build and execute command lines from standard input 1052 | - `touch` : Change file times 1053 | - `stat`: Display file or file system status 1054 | 1055 | --- 1056 | 1057 | - `find` : find files the hard way 1058 | - `find ~` : to produce a listing of our home directory 1059 | - `find ~ | wc -l` : to count the number of files. 1060 | - `find ~ -type d | wc -l` : `-type d` limit the search to directories 1061 | - `find ~ -type f | wc -l` : `-type f` limit the search to regular files 1062 | - `find ~ -type f -name "*.JPG" -size +1M | wc -l`: all the regular files that match the wildcard pattern *.JPG and are larger than one megabyte 1063 | 1064 | File type | Description 1065 | --- | --- 1066 | `b` | Block special device file 1067 | `c` | Character special device file 1068 | `d` | Directory 1069 | `f` | Regular file 1070 | `l` | Symbolic link 1071 | 1072 | 1073 | - find size units 1074 | 1075 | Character | Unit 1076 | --- | --- 1077 | `b` | 512-byte blocks. This is default if no unit is specified. 1078 | `c` | Bytes 1079 | `w` | 2-byte words 1080 | `k` | Kilobytes (units of 1,024 bytes) 1081 | `M` | Megabytes (units of 1,048,576 bytes) 1082 | `c` | Gigabytes (units of 1,073,741,824 bytes) 1083 | 1084 | - More about `find` options: [Find cheatsheet](https://github.com/shreyaschavhan/linux-commands-cheatsheet/blob/main/find-cheatsheet.md) 1085 | 1086 | --- 1087 | 1088 | - `xargs` - It accepts input from standard input and converts it into an argument list for a specified command 1089 | 1090 | ``` 1091 | find ~ -type f -name 'foo*' -print | xargs ls -l 1092 | -rwxr-xr-x 1 me me 224 2007-10-29 18:44 /home/me/bin/foo 1093 | -rw-r--r-- 1 me me 0 2016-09-19 12:53 /home/me/foo.txt 1094 | ``` 1095 | 1096 | --- 1097 | 1098 | Remaining: 1099 | - archiving and backup 1100 | - regular expressions 1101 | - text processing 1102 | - compiling programs 1103 | 1104 | 1105 | -------------------------------------------------------------------------------- /nmap-cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## 𝐧𝐦𝐚𝐩 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭: 2 | 3 | - Basic scans: 4 | > - `nmap ` - Scan Single IPs 5 | > - `nmap ` - Scan Specific IPs 6 | > - `nmap 192.168.1.1-254` - Scan a Range 7 | > - `nmap scanme.domain.name` - Scan a domain 8 | > - `nmap 192.168.1.0/24` - Scan using CIDR notation 9 | > - `nmap -iL targets.txt` - Scan targets from a file 10 | > - `nmap -iR 100` - Scan 100 random hosts 11 | > - `nmap --exclude 192.168.1.1` - Excude listed host 12 | 13 | --- 14 | - Scans: 15 | > - `nmap -sP 10.7.1.0/24` : ping multiple ips at once 16 | > - `nmap -p - `nmap -sT ` : TCP (full open) scan - using full 3 way handshake 18 | > - `nmap -sS -p ` - Stealthy scan (don't let TCP 3 way handshake complete to avoid getting caught. 19 | > - `nmap -O ` : OS Detection 20 | > - `nmap -A `: OS Detection + Version Detection + Script Scanning + traceroute 21 | > - `nmap -sV ` : Service version detection 22 | > - `nmap -D `: Add Decoy 23 | > - `nmap --script ssl-enum-ciphers -p ` : Check SSL 24 | 25 | 26 | Foot notes: 27 | 1. https://www.youtube.com/watch?v=4t4kBkMsDbQ 28 | 29 | --- 30 | 31 | ## Updates: 32 | 33 | - By [Marv](https://www.reddit.com/user/MrK_GER/) 34 | - Suggestion: [here](https://www.reddit.com/r/oscp/comments/xwgmal/comment/irb9jnz/?utm_source=share&utm_medium=web2x&context=3) 35 | ``` 36 | nmap -sV -Sc -oA nmap/ 37 | ``` 38 | ``` 39 | -sV ==> Version detection 40 | -sC ==> Run default scripts 41 | -oA ==> Save the output in all formats 42 | ``` 43 | -------------------------------------------------------------------------------- /ssh-cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## 𝐒𝐒𝐇 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭: 2 | 3 | > - Install ssh : `sudo apt-get install ssh` 4 | > - Enable and start ssh: `sudo systemctl enable ssh` & `sudo ssh start` 5 | > - Connect to a host: `ssh @` 6 | > - Connect to a host with non-default port: `ssh @ -p ` 7 | > - Connect to a host using private key: `ssh -i @` 8 | 9 | 10 | -------------------------------------------------------------------------------- /vim-cheatsheet.md: -------------------------------------------------------------------------------- 1 | ## 𝐕𝐢𝐦 (𝐕𝐢 𝐈𝐦𝐩𝐫𝐨𝐯𝐞𝐝) 𝐂𝐡𝐞𝐚𝐭𝐬𝐡𝐞𝐞𝐭 2 | 3 | - Why to learn Vi? 4 | - Vi is almost always available. Absolute necessary and good to know for pentesting. 5 | - Vi is lightweight and fast. 6 | 7 | - `vi` : Starting Vi 8 | 9 | ``` 10 | ~ 11 | ~ 12 | ~ VIM - Vi Improved 13 | ~ 14 | ~ version 8.0.707 15 | ~ by Bram Moolenaar et al. 16 | ~ Vim is open source and freely distributable 17 | ~ 18 | ~ Sponsor Vim development! 19 | ~ type :help sponsor for information 20 | ~ 21 | ~ type :q to exit 22 | ~ type :help or for on-line help 23 | ~ type :help version8 for version info 24 | ~ 25 | ~ Running in Vi compatible mode 26 | ~ type :set nocp for Vim defaults 27 | ~ type :help cp-default for info on this 28 | ~ 29 | ~ 30 | ``` 31 | 32 | - `:q` : Exiting Vi 33 | - `:q!` : force exiting Vi 34 | - `vim foo.txt` : creating new file and editing using Vi 35 | - `press i` : to enter editing mode 36 | - `press ESC`: to exit insert mode 37 | - `:w` : to save work 38 | 39 | - Moving Cursor Around: 40 | 41 | Key | Moves the cursor 42 | --- | --- 43 | `l` or `right arrow` | Right one character 44 | `h` or `left arrow` | Left one character 45 | `j` or `down arrow` | Down one line. 46 | `k` or `up arrow` | Up one line 47 | `0 (zero)` | To the beginning of the current line. 48 | `^` | To the first non-whitespace character on the current line 49 | `$` | To the end of the current line 50 | `w` | To the beginning of the next word or punctuation character. 51 | `W` | To the beginning of the next word, ignoring punctuation characters 52 | `b` | To the beginning of the previous word or punctuation character. 53 | `B` | To the beginning of the previous word, ignoring punctuation characters. 54 | `CTRL-F or Page Down` | Down one page 55 | `CTRL-B or PAGE UP` | Up one page 56 | `numberG` | To line number. For example, 1G moves to the first line of the file 57 | `G` | To the last line of the file. 58 | 59 | 60 | - `u` : undo the last change that you made. 61 | - `a` : append text at the end of the line. 62 | - `o` : Insert line below the current line. 63 | - `O` : Insert line above the current line. 64 | - `x` : will delete a character at the cursor location. 65 | 66 | Command | Deletes 67 | --- | --- 68 | `x` | The current character 69 | `3x` | The current character and the next two characters 70 | `dd` | The current line 71 | `5dd` | The current line and the next four lines 72 | `dW` | From the current cursor position to the beginning of the next word 73 | `d$` | From the current cursor location to the end of the current line 74 | `d0` | From the current cursor location to the beginning of the line 75 | `d^` | From the current cursor location to the first non-whitespace character in the line. 76 | `dG` | From the current line to the end of the file 77 | `d20G` | From the current line to the twentieth line of the file 78 | 79 | - `y`: is used to yank (copy) text 80 | - `d`: cut the text 81 | - `p`: paste the contents 82 | 83 | Command | Copies 84 | ---|--- 85 | `yy` | The current line 86 | `5yy` | The current line and the next four lines 87 | `yW` | From the current cursor position to the beginning of the next word 88 | `y$` | From the current cursor location to the end of the current line 89 | `y0` | From the current cursor location to the beginning of the line 90 | `y^` | From the current cursor location to the first non-whitespace character in the line 91 | `yG` | From the current line to the end of the file 92 | `y20G` | From the current line to the twentieth line of the file. 93 | 94 | - `J (capital j)`: to join lines 95 | - `f`: search within a line 96 | - `/Line`: search within a file 97 | - `:%s/Line/line/g`: global search and replace 98 | - 99 | 100 | --------------------------------------------------------------------------------