shell.cheat 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. % Shell Usage
  2. # Re-call last input with sudo
  3. sudo !!
  4. # Help
  5. help cd / help dir (...)
  6. # Finding Help
  7. apropos directory / apropos search (...)
  8. # Define custom startup screen
  9. sudo nano /etc/motd
  10. # Run a script as background process
  11. <process> &
  12. #List all running processes
  13. ps -A
  14. # Kill a running process
  15. killall <Process-name>
  16. % Shell System
  17. # Get the current path
  18. pwd
  19. # Get the current hostname
  20. hostname
  21. # Get the current users
  22. users
  23. # Show calendar
  24. cal
  25. # Show today's date
  26. date
  27. # Exit terminal
  28. exit
  29. % Shell Permissions
  30. # Use -R option to change permissions recursively.
  31. ps -ef | grep apache | grep -v grep
  32. # Change group
  33. chgrp <group-name-from> <group-name-to>
  34. % Shell Directories
  35. # List directory contents
  36. ls
  37. # List all directory contents
  38. ll
  39. # List all directory contents sorted by time edited
  40. ls -alt
  41. # List directory (wildcard matching)
  42. ls *.<txt>
  43. # List all files of type
  44. find . -name '*.<txt>' -print
  45. # Go back to previous directory
  46. cd -
  47. # Make (empty) directory
  48. mkdir <dirname>
  49. # Remove (empty) directory
  50. rmdir <dirname>
  51. # Remove directory with all contents without prompt
  52. rm -rf <dirname>
  53. # Remove directory contents and keep directory
  54. rm -rf *
  55. # Change directory
  56. cd <dirname>
  57. % shell Symlinks
  58. # Create symlink
  59. ln -s <source-dirname> <destination-dirname>
  60. # Update symlink
  61. ln -sfn <source-dirname> <destination-dirname>
  62. # Remove symlink
  63. unlink <sample-dirname>
  64. % Shell Files
  65. # Make (empty) file
  66. touch <filename-txt>
  67. # Duplicate file
  68. cp <filename> <file-copyname>
  69. # Copy/Page folder with content
  70. cp -a <old-folder>/ <new-folder>
  71. # Move/Rename file
  72. mv <current-filename-path> <new-filename-path>
  73. # Move/Rename file and prompt before overwriting an existing file
  74. mv -i <current-filename> <new-filename>
  75. # Remove file
  76. rm <filename-txt>
  77. # Write to file (will overwrite existing content)
  78. cat > <filename-txt>
  79. # Search for a filename-(not content!) in the current directory
  80. find <filename-txt>
  81. # Search for a string inside all files in the current directory and subdrectories
  82. grep -r <string> *
  83. # Search and replace within file
  84. sed -i s/<original-text>/<new-text>/g <filename-txt>
  85. # MD5 hash for files
  86. md5 <filename-txt>
  87. # MD5 hash for folders
  88. tar c <folder> | md5sum
  89. # Encrypt file
  90. openssl enc -aes-256-cbc -e -in <sample-filename-txt> -out <sample-encrypted-txt>
  91. # Decrypt file
  92. openssl enc -aes-256-cbc -d -in <sample-encrypted> -out <sample-filename>
  93. % Shell Server
  94. # Access via ssh
  95. ssh <username_remote>
  96. # Copy file from server to local
  97. scp <username_remote>:<file-to-send-path> <path-to-recieve>
  98. # Copy file from local to server
  99. scp <file-to-send> <username_remote>:<where-to-put>
  100. # Escape files with spaces in name like this
  101. <path-to-file>\\\ <name-png>
  102. $ username_remote: cat ~/.ssh/config | grep -i "host "|sed 's/^[ \t]*//g' | awk '{print $2}'
  103. % Shell System
  104. # Show disc space
  105. df -h
  106. # Show disc space (inodes)
  107. df -i
  108. # Show disc space for current directory
  109. du -hs
  110. # Current processes (also CPS usage)
  111. top or htop
  112. # Show running php processes
  113. ps aux | grep php
  114. # Monitor error log (stream as file grows)
  115. tail error.log -f -n 0
  116. % Shell Apps
  117. # Start appliction
  118. xdg-open <programme>
  119. # Open finder with current folder
  120. open .
  121. % Shell Variables
  122. # Register variable
  123. export <TESTING>=<Variable-text>
  124. # Echo variable
  125. echo $<Variable>
  126. # Unset variable
  127. unset <Variable>
  128. % Shell Output & Redirects
  129. # Write to file
  130. echo <Hello> > <hello-txt>
  131. # Append content from a file to another file
  132. cat <file1-txt> >> <file2-txt>
  133. # Add the amount of lines, words, and characters to <file2-txt>
  134. cat <file1-txt> | <word-count> | cat > <file2-txt>
  135. # Sort the content of a file (like cat)
  136. sort <hello-txt>
  137. # Save to sorted content to a new file
  138. cat <file1-txt> | sort > <sorted-file1-txt>
  139. # Sort and remove duplicates and save to a new file
  140. sort <file1-txt> | uniq > <uniq-file1-txt>