Linux Ubuntu Commands that will increase your productivity as a System Administrator

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
  38. ls FolderName/ #will show files inside that folder
  39. cat Foldername/FileName #will show you the content of the file (readonly) in that folder

    Developing Notes:
  40. 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

    Cron Jobs
    - minute(m) hour(h),DayOfMonth(DoM),Month(mon),DayOfWeek(DoW) or use (*) for (any)
    - Crontab file on Linux ubuntu is located in /var/spool/cron/crontabs
    Mistakes to avoid when scheduling CronJobs in Linux: If you want a job to run a task on the 1st and 15th of every month make sure you specify (0 0 1,15 *) 0 means that the job will run only once, if you leave a * in there, the job will run every minute on 1st and 15th of every month. If you want to schedule a task to run after days, months or yearly, make sure that the beginning * (stars) are set to 0 or else the job will run every minute when that schedule comes.

    - Crontab uses military time, remember when scheduling a task.

    - Schedule Intervals: to run a job every 10 minutes, (*/10 * * * *) this means that the job will run every 10 minutes every day.
    - If you want to schedule a job to run every 30minutes Monday-Friday 9 am to 5 pm then the job will be:
       */30 9-17 (Military time) * * 1-5

    - If you want to edit a Crontab for another user
       crontab -u UserName -e
    - To view crontab created by your userName
       crontab -l 
    - To remove the scheduled task run
      crontab -r

    Good Practices about writing CronJobs
    - Make sure you include comments talking about what the job does
    - Make sure that the crontab file you edit using crontab -e has an empty newline at the end. If the crontab file does not contain an empty newline at the end, the job will not run.
    - If you want to call another Shell Script from a Shell Script executed using a Cron Job, in the first script you should specify where the second script is located using a full path, otherwise, the second script won't be executed.

  41. Link Here
  42. Another good resource 


Cathy said:

Thank you

Posted On: November 25, 2019 12:39:39 PM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy