├── cheat_sheet.org.sh └── to_do.txt /cheat_sheet.org.sh: -------------------------------------------------------------------------------- 1 | # cheat_sheet.org 2 | # (C) William Hackmore, 2010 3 | # The contents of this file are released under the GNU General Public License. Feel free to reuse the contents of this work, as long as the resultant works give proper attribution and are made publicly available under the GNU General Public License. 4 | # Last updated 8/14/2012 5 | # Best viewed in emacs org-mode. 6 | 7 | * Command Reference: 8 | ** Basics: 9 | *** Getting help: 10 | 11 | # View the manual for target command 12 | man [command] 13 | 14 | # Get help with a target command (probably the same as above, but not always): 15 | [command] -h 16 | 17 | # In case you forget the name of a command, print possible commands relating to [guess]: 18 | apropos [guess] 19 | 20 | # View index of help pages: 21 | info 22 | 23 | *** Command Line Utilities: 24 | **** Basic File and Directory Operations: 25 | # Print current working directory: 26 | pwd 27 | 28 | # Show files in current directory: 29 | ls 30 | 31 | # Show maximum information about all files, including hidden: 32 | ls -a 33 | 34 | # Recurse into subdirectories and list those as well: 35 | ls -r 36 | 37 | # Move/rename a file or directory (be careful that you don't move the source over a destination with the same name): 38 | mv [source] [destination] 39 | 40 | # Delete target forever (be very careful), use -r recursive flag for directories: 41 | rm [target] 42 | 43 | # Copy file or directory: 44 | cp [source] [destination] 45 | 46 | # Mount filesytem: 47 | mount /dev/[device name] /media/[device name] 48 | 49 | # Unmount: 50 | umount /media/[device name] 51 | 52 | # Forensically clone filesystems and do other low-level operations on files. Very dangerous: 53 | dd 54 | 55 | # Work with filesystems and partitions. (Easier, still quite dangerous): 56 | fdisk 57 | 58 | **** System Administration: 59 | 60 | # Execute command as an administrator (dangerous, but necessary for system administration tasks): 61 | sudo [command] 62 | 63 | # Become system administrator: 64 | sudo -s 65 | 66 | # Quit system administration: 67 | exit 68 | 69 | # Check distro repositories for software updates: 70 | sudo apt-get update 71 | 72 | # Download and install updates (update first): 73 | sudo apt-get upgrade 74 | 75 | # Search for package in the repositories: 76 | apt-cache search [keyword] 77 | 78 | # Get more detail on one specific package: 79 | apt-cache show [package name] 80 | 81 | # Download and install a package: 82 | sudo apt-get install [package name] 83 | 84 | # View the output of a command in a more convenient format: 85 | [command] | less 86 | 87 | **** Working With Files: 88 | 89 | # Print a file in terminal: 90 | cat [file] 91 | 92 | # Find files matching [filename]: 93 | locate [filename] 94 | 95 | # Search through [filename] for matches to [phrase]: 96 | grep [phrase] [filename] 97 | 98 | # Search through output of a command for [phrase]: 99 | [command] | grep [phrase] 100 | 101 | **** Working With Processes: 102 | 103 | # List all running processes: 104 | ps -e 105 | 106 | # Standard system monitor showing a more extensive view of all processes and system resources: 107 | top 108 | 109 | # Like top, but with a better, cleaner interface: 110 | htop 111 | 112 | # Stop a process from using all system resources and lagging computer: 113 | nice [process name] 114 | 115 | # Kill misbehaving process (use sparingly, last resort, try 'nice' command first): 116 | pkill [process name] 117 | 118 | **** Compression and Encryption: 119 | 120 | # Make a simple compressed backup of a file or directory: 121 | tar -cvzf [backup output.tgz] [target file or directory] 122 | 123 | # Open a compressed .tgz or .tar.gz file: 124 | tar -xvf [target.tgz] 125 | 126 | # Encrypt a file: 127 | gpg -o [outputfilename.gpg] -c [target file] 128 | 129 | # Decrypt a file: 130 | gpg -o [outputfilename] -d [target.gpg] 131 | 132 | # Zip and encrypt a directory simultaneously: 133 | gpg-zip -o encrypted-filename.tgz.gpg -c -s file-to-be-encrypted 134 | 135 | *** The Bash shell: 136 | **** File Name expansions: 137 | # Current user's home directory: 138 | ~/ 139 | 140 | # Current directory: 141 | ./ 142 | 143 | # Parent directory: 144 | ../ 145 | 146 | # Or even (Two parent directories down): 147 | ../../ 148 | 149 | # All files in target directory. (Be very careful.): 150 | /* 151 | 152 | **** Output Redirects: 153 | 154 | # Redirect output of one command into the input of another with a pipe: 155 | [command 1] | [command 2] 156 | 157 | # Or even: 158 | 159 | [command 1] | [command 2] | [command 3] 160 | 161 | # Redirect output to a file: 162 | [command] > file 163 | 164 | # Or: 165 | 166 | [file] > [file] 167 | 168 | # Or even, to redirect in a different direction: 169 | [file] < [file] 170 | 171 | # Append output rather than writing over the target file: 172 | 173 | [file/command] >> [file] 174 | 175 | # Works like |, but it writes output to both target and terminal: 176 | tee [target] 177 | 178 | **** Controlling Execution: 179 | # Wait until [command 1] is finished to execute [command 2] 180 | [command 1] ; [command 2] 181 | 182 | # Or even: 183 | [command 1] ; [command 2] ; [command 3] 184 | 185 | **** Wildcards: 186 | # Zero or more characters: 187 | * 188 | 189 | # Matches "phrase" and any number of trailing characters: 190 | phrase* 191 | 192 | # Matches any incidences of "phrase" with any trailing or leading chars: 193 | *phrase* 194 | 195 | # Matches any one char: 196 | ? 197 | 198 | # Matches any of the characters listed inside brackets: 199 | [chars] 200 | 201 | # Matches a range of chars between a-z: 202 | [a-z] 203 | 204 | ** Advanced: 205 | *** Command Line Utilities, Continued: 206 | **** Networking: 207 | 208 | # Configure network interfaces: 209 | ifconfig 210 | 211 | # Configure wireless network interfaces: 212 | iwconfig 213 | 214 | # Connect to a remote server. 215 | ssh [username]@[ipaddress] 216 | 217 | # Forward x from target to current machine (Get a remote desktop. Very obscure and very useful): 218 | ssh -x [username]@[ipaddress] 219 | 220 | # Copy files over the network from one machine to another: 221 | scp [source filename]:[username]@[ipaddress] [target filename]:[target username]@[target ipaddress] 222 | 223 | # Copy only changes between files or directories (super efficient way to sync directories, works either locally or with remote servers using username@ipaddress:optionalport, just like ssh): 224 | rsync [source] [target] 225 | 226 | # Check to see if target is online and responding 227 | ping [ip address] 228 | 229 | # View network route to target: 230 | traceroute6 [ip address] 231 | 232 | # Network Monitor 233 | netstat 234 | 235 | # Manage standard linux firewall (advanced users only) 236 | iptables 237 | 238 | # Scan this machine to check for open ports: 239 | nmap 127.0.0.1 240 | 241 | ***** netcat: 242 | 243 | # Listen for input from network on [recieving port], dump it to a file (possibly insecure): 244 | netcat -l [recieving port] > file_copied 245 | 246 | # Pipe the output of a command to a target ip and port over the network: 247 | [command] | netcat -w [number of seconds before timeout] [target ip] [target port] 248 | 249 | # Use tar to compress and output a file as a stream, pipe it to a target ip and port over the network: 250 | sudo tar -czf - [filename] | netcat -w [number of seconds before timeout] [target ip] [target port] 251 | 252 | **** Users and Groups: 253 | # Change owner of a file or directory: 254 | chown 255 | 256 | # Change privileges over file or directory: 257 | chmod 258 | 259 | # Create a new user: 260 | adduser 261 | 262 | # Change user privileges (be very careful with this one): 263 | usermod 264 | 265 | # Delete user" 266 | deluser 267 | 268 | # Print groups: 269 | groups 270 | 271 | # Create a new group: 272 | groupadd 273 | 274 | # Change group privileges: 275 | groupmod 276 | 277 | # Delete group: 278 | delgroup 279 | 280 | # Temporarily become a different user: 281 | su [username] 282 | 283 | 284 | # Print usernames of logged in users: 285 | users 286 | 287 | # Write one line to another user from your terminal: 288 | talk 289 | 290 | # Interactive talk program to talk to other users from terminal: 291 | ytalk 292 | 293 | **** Working With Files, Continued: 294 | # View what processes are using what files: 295 | lsof 296 | 297 | # View the differences between two files: 298 | diff [file 1] [file 2] 299 | 300 | # Output the top -n lines of [file]: 301 | head -n [number of lines] [file] 302 | 303 | # Like head, but it outputs the last -n lines: 304 | tail 305 | 306 | # Checksum a file: 307 | md5sum [file] 308 | 309 | # Checksum every file in a directory: 310 | md5deep [directory] 311 | 312 | # Checksum a file (safer algorithm with no hash collisions): 313 | sha1sum 314 | 315 | # Same operation as md5deep, but using sha1: 316 | sha1deep 317 | 318 | # Call [command] every -n seconds, and display output: 319 | watch -n [number of seconds] [command] 320 | 321 | # Execute [command], print how long it took: 322 | time [command] 323 | 324 | # View files in home from largest to smallest: 325 | du -a ~/ | sort -n -r | less 326 | 327 | # remove spaces from filenames in current directory 328 | rename -n 's/[\s]/''/g' * 329 | 330 | # change capitals to lowercase in filenames in current directory 331 | rename 'y/A-Z/a-z/' * 332 | 333 | ***** Environment and Hardware: 334 | # Print full date and time: 335 | date 336 | 337 | # Print the hostname of this machine: 338 | echo $HOSTNAME 339 | 340 | # Print information about current linux distro: 341 | lsb_release -a 342 | 343 | # Print linux kernel version: 344 | uname -a 345 | 346 | # Print information about kernel modules: 347 | lsmod 348 | 349 | # Configure kernel modules (never do this): 350 | modprobe 351 | 352 | # View Installed packages: 353 | dpkg --get-selections 354 | 355 | # Print environment variables: 356 | printenv 357 | 358 | # List hardware connected via PCI ports: 359 | lspci 360 | 361 | # List hardware connected via USB ports: 362 | lsusb 363 | 364 | # Print hardware info stored in BIOS: 365 | sudo dmidecode 366 | 367 | # Dump captured data off of wireless card: 368 | dumpcap 369 | 370 | # Dump info about keyboard drivers: 371 | dumpkeys 372 | 373 | ***** System Administration (Continued): 374 | 375 | # Add a Personal Package Archive from Ubuntu Launchpad: 376 | 377 | add-apt-repository 378 | 379 | # Install a .deb file from command line: 380 | sudo dpkg -i package.deb 381 | **** Python: 382 | 383 | # update pip (Python package manager): 384 | pip install -U pip 385 | 386 | # search pip repos 387 | pip 388 | 389 | # create a virtual python environment 390 | virtualenv [dirname] --no-site-packages 391 | 392 | # connect to a virtual python environment 393 | source [dirname]/bin/activate 394 | 395 | # disconnect from a python environment: 396 | deactivate 397 | 398 | # install package into virtual python environment from outsie: 399 | pip install [packagename]==[version_number] -E [dirname] 400 | 401 | # export python virtual environment into a shareable format: 402 | pip freeze -E [dirname] > requirements.txt 403 | 404 | # import python virtual environment from a requirements.txt file: 405 | pip install -E [dirname] -r requirements.txt 406 | 407 | **** git (all commands must be performed in the same directory as .git folder): 408 | 409 | # Start a new git project: 410 | git init 411 | 412 | # Clone a git (target can be specified either locally or remotely, via any number of protocols): 413 | git clone [target] 414 | 415 | # Commit changes to a git: 416 | git commit -m "[message]" 417 | 418 | # Get info on current repository: 419 | git status 420 | 421 | # Show change log for current repository: 422 | git log 423 | 424 | # Update git directory from another repository: 425 | git pull [target] 426 | 427 | # Push branch to other repository: 428 | git push [target] 429 | 430 | # Create a new branch: 431 | git branch [branchname] 432 | 433 | # Switch to target branch: 434 | git checkout [branchname] 435 | 436 | # Delete a branch: 437 | git branch -d [branchname] 438 | 439 | # Merge two branches: 440 | git merge [branchname] [branchname] 441 | 442 | *** Virtualization: 443 | 444 | #clone a virtual machine (this works, it's been tested): 445 | vboxmanage clonehd [virtual machine name].vdi --format VDI ~/[target virtual machine name].vdi 446 | 447 | #mount a shared virtual folder: 448 | #you need to make sure you have the right kernel modules. You can do this with modprobe, but this package works instead in a ubuntu-specific way. 449 | 450 | sudo apt-get install virtualbox-ose-guest-utils 451 | 452 | sudo mount -t vboxsf [name of Shared folder specified in Virtualbox] [path of mountpoint] 453 | 454 | *** mysql: 455 | 456 | # Get help: 457 | help 458 | 459 | # Show databases: 460 | show databases; 461 | 462 | # Choose a database to use: 463 | use [database name here]; 464 | 465 | # Show database schema: 466 | show tables; 467 | 468 | # Delete database: 469 | DROP DATABASE [databasename]; 470 | 471 | # New database: 472 | CREATE DATABASE [databasename]; 473 | 474 | # Create a new user: 475 | CREATE USER [username@localhost] IDENTIFIED BY '[password]' ; 476 | 477 | # Show users: 478 | select * from mysql.user; 479 | 480 | # Delete a user: 481 | delete from mysql.user WHERE User='[user_name]'; 482 | 483 | # Give user access to all tables (make them root). the "%" means that they can sign in remotely, from any machine, not just localhost.: 484 | grant all privileges on *.* to someusr@"%" identified by '[password]'; 485 | 486 | # give certain privileges to a user on a certain database: 487 | grant select,insert,update,delete,create,drop on [somedb].* to [someusr]@["%"] identified by '[password]'; 488 | 489 | # Tell mysql to use new user priv policies: 490 | flush privileges; 491 | 492 | # change user password: 493 | use mysql; 494 | 495 | update user set password='[password]'('[newpassword]') where User='[user_name]' ; 496 | 497 | # mysql command line args: 498 | 499 | # export text file with commands to rebuild all mysql tables: 500 | 501 | mysqldump [databasename] > [dumpfilename.txt] 502 | 503 | # restore from a dump: 504 | 505 | mysql -u [username] -p < [dumpfilename.txt] 506 | 507 | # dump entire database: 508 | 509 | mysqldump -u [username] -p --opt [databasename] > [dumpfile.sql] 510 | 511 | # restore from entire database dump: 512 | 513 | mysql -u [username] -p --database=[databasename] < [dumpfile.sql] 514 | -------------------------------------------------------------------------------- /to_do.txt: -------------------------------------------------------------------------------- 1 | Still need to cover the following topics: 2 | 3 | .bashrc 4 | /etc/apt/sources.list 5 | /etc/fstab 6 | init scripts 7 | cron 8 | anacron 9 | more detail about filesystems 10 | /etc 11 | daemons 12 | wget 13 | curl 14 | --------------------------------------------------------------------------------