Advertisement
yordan_filipov

Linux_commands

Feb 17th, 2023
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. whoami --> current user
  2. man whoami --> manual about certain command
  3. clear --> clear the screen (Ctrl+L)
  4. pwd --> current dir
  5. ls --> lists the files and folder in current dir
  6. ls /folder_path --> lists the files and folder in certain folder
  7. ls -l --> permisions, date and etc..
  8. ls -a --> including dot (hidden) files
  9. ls -al --> combine options
  10. cd --> change dir
  11. cd .. --> previous dir
  12. cd /../../ --> 2 previous dirs
  13. cd ~ --> home dir
  14. mkdir folder_name folder_name2 --> makes directories
  15. mkdir -p fl1/fl2/fl3 --> creates folder1 and inside folder 1 creates folder 2 and so on..
  16. touch file1.txt some_image.png --> creates file/s
  17. touch app.{js,html,css} --> creates app.js, app.html, app.css empty files
  18. touch {1..3}.txt --> creates 1.txt, 2.txt, 3.txt empty files
  19. rm -rv file1.txt some_file.jpg --> remove files and prints the deleted ones (-v verbose)
  20. mv pear.txt renamed_pear.txt --> rename a file
  21. mv some_folder/ SOME_folder --> rename a folder
  22. mv pear.txt some_img.png Some_Folder/ --> moves the files in certain folder
  23. cp file1.txt file2.txt --> makes a copy of file1
  24. cp -rv folder1/ another_folder --> folder copying
  25. head -7 file1.txt --> shows the first 7 lines of the file
  26. tail -7 file1.txt --> shows the last 7 lines of the file
  27. date > file1.txt --> replace the content of file1.txt with current date (instead of date it could be any command)
  28. ls -l >> file1.txt --> appends the list of current files and dirs in file1.txt
  29. cat file1.txt file2.txt --> prints the content of a files
  30. cat f1.txt f2.txt > new_file.txt --> concatenates 2 files into another new file
  31. cat -n f1.txt --> prints the file with a number on every row
  32. less f1.txt --> enters in a reading mode in a file (after that '/ someword' search for a word in the file)
  33. echo "some text" > file1.txt --> creates a file with some text
  34. echo *.??? --> prints every file name, that ends with a dot, and after the dot there are 3 chars
  35. echo app.{js,txt,html} --> app.js app.txt app.html
  36. wc file1.txt --> word count - prints rows/words/characters
  37. ls -l | wc > file1.txt --> Piping - combines commands
  38. sort file1.txt --> prints an alphabetically sorting of a file
  39. uniq file1.txt --> removes adjacent duplicates
  40. cmd | cmd | cmd .. --> pipe takes the output from one command and pass it as input to another (works from left to right)
  41. diff -u file1 file2 --> shows the difference between files (github style)
  42. find . -name '*a*' --> find everything with an 'a' in the name (files, dirs)
  43. grep green file1.txt --> highlights the matches of the word 'green' in file1
  44. du -h --> lists size of dirs
  45. history --> lists the history of the written commands
  46. history | grep 'some_word' --> searching for a certain word in the written commands
  47. ps --> current processes
  48. kill -9 PID --> force end a process (PID can be shown when type 'ps a')
  49. killall -9 node --> kills every process with a name 'node'
  50. some_command & --> runs a process in the background
  51. jobs --> shows the background processes
  52. gzip -k filename --> keeps the original file and a new compressed one
  53. gunzip filename --> extracts a compressed file
  54. tar -cf archive.tar file1.txt file2.txt --> adds two files into archive
  55. nano filename --> opens and edit a file (text editor)
  56. alias custom_command='ls -l' --> makes a custom command (shortcut) works only in the current terminal session
  57. cat file1.txt | xargs rm --> xargs pass the elaments of file1 in a list for 'rm' which removes them
  58. ln original_file copy_file --> creates a hard link (copy_file) which referes to the original one (both are pointing to the same file in memory)
  59. ln -s original_file copy_file --> something like a shortcut (if original is deleted, copy_file points to nothing)
  60. su another_username --> switch user
  61. sudo --> 'superuser do' gives admin privileges
  62. passwd --> change password
  63.  
  64.  
  65. Permissions of the file attributes:
  66. 1st char --> type:
  67. - --> file
  68. d --> directory
  69. l --> symlink (shortcut)
  70.  
  71. 2nd, 3rd and 4th chars (permissions of the owner):
  72. r --> read
  73. w --> write
  74. x --> execute
  75. if it's '-' instead of 'r', it means the user cannot read the file and etc.
  76.  
  77. 5th, 6th and 7th chars (permissions for the group owner and the members of the group):
  78. same possible group rwx
  79. 8th, 9th and 10th chars (permissions for everyone else):
  80. same possible group rwx
  81.  
  82. chmod mode file --> change permissions
  83. chmod a-rw file1.txt --> '-' removes 'r' read and 'w' write permisions for 'a' everyone
  84. chmod a=r file1.txt --> '=' leaves 'a' everyone only with 'r' permissions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement