Advertisement
dexthor

bash

May 18th, 2021 (edited)
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.73 KB | None | 0 0
  1. COMMANDS
  2. ========
  3. clear >>> clear_terminal
  4. history >>> history of commands used
  5. pwd >>> print_working_directory
  6. ls >>> list
  7. cd >>> change_directory (cd - or cd [/abs.path] - to go upwards; cd [/rel.path] - to go downwards)
  8. cd / >>> root directory
  9. cd ~ >>> home directory
  10. cd - >>> one step up
  11. mkdir >>> make_directory (mkdir [dir_name(s)])
  12. rmdir >>> remove_directory(ies) (empty ones only)
  13. cp >>> copy_paste (cd [source_files destination])
  14. rm >>> remove_file (rm [file_name(s)])
  15. mv >>> move_file(s)_or_directory(ies) (mv [path(s)/name] [optional: path(s)/new_name] destination)
  16. find >>> search for files by name, by type, last time it was accessed, last time it was modified (find [location] -name ['filename'])
  17. id >>> identificates uid (user id), gid (group id) and groups user belongs to
  18. groups >>> list groups user belongs to
  19. chmod >>> change_mod (chmod u/g/o+/-/=r/w/x file(s)) >>> sets user/group/other permissions to read/write/execute files
  20. stat >>> file_status
  21. chown >>> change_owner (chown [new_owner][:new_group] file...)
  22. !! >>> run last command (e.g. sudo !!)
  23. type >>> gets the command type (usually used with -t flag)
  24. alias >>> e.g. alias d=date >>> 'date' command is now accessed with 'd'
  25. unalias >>> e.g. unalias d >>>. 'date' command is no longer accessed with 'd'
  26. compgen >>> completion_generation (completes commands with Tab)
  27. man >>> manual >>> explains command (e.g. man pwd)
  28. whatis >>> short definition of a command (e.g. whatis pwd)
  29. help >>> explains builtins (e.g. help pwd)
  30. less >>> terminal pager which inspects contents of text files (e.g. 'less <file_name>...')
  31. wc (e.g. 'wc file_name') >>> word_count >>> (x y z) >>> x=lines count, y=words count, z=bytes count;
  32.    wc -m >>> characters count
  33.    wc -l >>> lines count
  34. head >>> reads first 10 rows of a file (e.g. head file_name); '-n K' >>> read first K lines; '-n -K' >>> read all but last K lines
  35. tail >>> reads last 10 rows of a file (e.g. tail file_name); '-n K' >>> read last K lines; '-n +2' >>> read all but first line
  36. column >>> show results in two side-by-side columns, instead of a one long list (e.g. column file_name);
  37.   column -s"<delimiter>" -t  file_name >>> prettyprint small tables (larger tables with 'less')
  38. shuf >>> shuffle (e.g. shuf [-n K] file_name) >>> extract random lines from a file
  39. file >>> determines the type of a file (e.g. file file_name); 'file *' >>> displays types of all files inside a folder
  40. cat >>> concatenates the contents of the arguments/files (in order) and displays them (e.g. 'cat <arg1> <arg2>');
  41.         displays the contents of a file (although it is a 'cat abuse', it is common practice as well)
  42. tac >>> same as cat but reverses the order of the lines (while keeping the order of the files)
  43. sort >>> sorts lines of text file(s) lexicographically (e.g. sort [-g]|[-r]|[-u]... <file_name>...);
  44.          sorts by columns (e.g. sort -t',' -k3,3gr file_name); without '-g' - lexicographically, with '-g' - numerically
  45. cut >>> cuts certaing columns from table (e.g. cut -d"," -f2,5 example_data.csv);
  46.         -d >>> delimiter; -f >>> fields/columns (could be a range as well> -f1-3)
  47. grep >>> global_regular_expression_print
  48. echo/printf >>> same as print (e.g. echo 'say something')
  49. > --- redirection operator >>> input > redirection > output (e.g. echo 'text' >'new_file_name' >>> creates new file with that text)
  50.   --- can be used with cat grep sort less help ...(e.g. cat 'file_name_1' 'file_name_2' >'new_file_name_3')
  51.   --- >empty_file
  52.   --- >/dev/null (moving something to null device)
  53. >> --- redirection operator with appending functionality
  54.    --- echo -n '' >>empty_file
  55. touch >>> changes time stamp and can create more than one empty files (e.g. touch <file_name_1> <file_name_2>
  56. | >>> pipe >>> connects the output of the first command into the input of the second command (e.g. <command_1> | <command_2>)
  57.  
  58.  
  59. OPTIONS/FLAGS
  60. =============
  61. / >>> root directory
  62. -p >>> appends slash (/) at the end of a folder
  63. -A >>> all >>> displays all the files and folders (incl. hidden, starting with .)
  64. -a >>> all >>> displays all the files and folders (incl. .(current) and ..(parent) directories)
  65. -l >>> long >>> displays metadata of the files (eg. ls -l)
  66. -h >>> human_readable
  67. -i >>> interactive_mode >>> raises command confirmation
  68. -R >>> recursive >>> used with cp to copy directory; used with rm to remove directory
  69. --help >>> explains files (e.g. 'pwd --mv')
  70.  
  71.  
  72. WILDCARDS
  73. =========
  74. * >>> matches any character, any number of times, except leading dots (.)
  75. ? >>> matches any character exactly one time
  76. [] >>> matches any characters inside (only once)
  77. ! >>> matches everyhing but whatever character follows it
  78. character class and bracket expressions:
  79.  https://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement