Linux (Ubuntu) Commands

Important Commands to remember when working with  Linux like Operating System.

  1. Entire System Settings are made of txt files
  2. cat command shows information of the file and many more (Reseach about CAT command)
  3. cat >> fileName => will put whatever output into a fileName, not exist it creates it as well.
  4. cat > fileName => will put input/content in a file and erase existing content.
  5. cat >> fileName => appends content to the file.
  6. Control D => Tells cat command that you are done typing or done with cat command and it will go ahead and save the file.
  7. cat file1 file2 file3 => will stick file1 file2 and file3 together for easy readability
  8. more fileName => will allow you to read content from the file
  9. less fileName => will allow you to read less content from the file
  10. q => when using more or less command, q indicates that you want to quit reading or displaying content.

  11. When you work on one path and then decide to navigate to another directory. While on another directory you choose to go back to a previous directory type:
    - cd - => will take you to a previous directory
    - cd .. => will take you to one directory level
    - cd ~ => will take you to the home directory
    - cd / => will take you to root directory

    Users Command
  12. users => will show users who are logged in the System
  13. id => will show information about the account you are currently logged in
  14. [NB] What makes Linux secure is that every file is owned by someone
  15. If you installed htop, by typing htop will show users who are currently logged in the processes running on the system.

    Permission in Ubuntu
  16. User Group Everyone
    rwx   rwx       rwx  = read write execute
    421   421      421  = calculate numbers from a different group and determine the permission level
    7          7          7    = means everyone from Users, Group and Everyone can read, write and execute a file.
    (4+2 = 6) from User-Section then from Group-Section add (2 + 1 = 3) which is 621 means Users can read and write, Groups can write and execute a file and Everyone not belonging to any group can only execute.
  17. chmod -x fileName => makes file executable. If a file has an "x" then it is executable.

    Kill Processes
  18. watch free -h  => runs command every few seconds and shows you memory used.
  19. killall firefox => kills firefox process
  20. Control L => clears the console
  21. Control-Shift + or - => increases or decreases text size in terminal

    Running Files
  22. .fileName.extension => will execute or run the file considering you have made it into an executable. Note: Ubuntu does not care about file extension it will even execute a file without an extension, it will compile it with GCCC or any other programming language. If your file as an extension remembers to install that Programming language beforehand.

    System Information Commands
  23. df => display information about the used disk space
  24. du => display used disk space of a directory
  25. free => display free memory
  26. top => display top running processes
  27. uname -a => prints system information includes the Kanel and processes.
  28. lsb_releas -a => prints version of Linux and release date
  29. ip addr => prints information about the network interface.

    Compress a Folder to a Different Directory
  30. tar -zcvf ChooseNameOfArchive.tar.gz directory-nameYouWantToArchive
    - If you have a directory named "directory-nameYouWantToArchive" in the current directory and you want to save it as "ChooseNameOfArchive.tar.gz" you would run the following command tar -zcvf ChooseNameOfArchive.tar.gz directory-nameYouWantToArchive
  31. Move a folder to a directory:
    - cp -r /var/www/somefolder/. /var/www . (This command will traverse all files and subfolders in the same folder and copy them to www folder)
  32. Delete a folder (Warning: When you delete there is no getting the folder back) sudo rm -r /NameOfTheFolder 
    - You have to be in the same directory where the folder is located just to be safe.

    Adding a New User
  33. adduser userName password newUser => will create a new user called userName and assign password of new user

  34. man "command" => will display help info about "command"
  35. man intro => very useful to display an introduction to the man command
  36. info info => more detailed information than that of "man": displays information about infor pages.
  37. whatis -r

    Developing Notes:
  38. When working in Linux Barebone Server and would like to save some time, watch out for these:
    - If you want to back up the folder, you would save time by just copying the folder and renaming it to backUp instead of downloading the whole folder.
    Check if PHP is running
    - /etc/init.d/php7.2-fpm status

  39. Link Here
  40. Another good resource