Linux (Ubuntu) Commands that will increase your productivity as a System Administrator
Important Commands to remember when working with Linux like Operating System.
- Entire System Settings are made of txt files
- cat command shows information of the file and many more (Reseach about CAT command)
- cat >> fileName => will put whatever output into a fileName, not exist it creates it as well.
- cat > fileName => will put input/content in a file and erase existing content.
- cat >> fileName => appends content to the file.
- Control D => Tells cat command that you are done typing or done with cat command and it will go ahead and save the file.
- cat file1 file2 file3 => will stick file1 file2 and file3 together for easy readability
- more fileName => will allow you to read content from the file
- less fileName => will allow you to read less content from the file
- q => when using more or less command, q indicates that you want to quit reading or displaying content.
- 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 => will show users who are logged in the System
- id => will show information about the account you are currently logged in
- [NB] What makes Linux secure is that every file is owned by someone
- If you installed htop, by typing htop will show users who are currently logged in the processes running on the system.
Permission in Ubuntu
- 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.
- chmod -x fileName => makes file executable. If a file has an "x" then it is executable.
- watch free -h => runs command every few seconds and shows you memory used.
- killall firefox => kills firefox process
- Control L => clears the console
- Control-Shift + or - => increases or decreases text size in terminal
- .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
- df => display information about the used disk space
- du => display used disk space of a directory
- free => display free memory
- top => display top running processes
- uname -a => prints system information includes the Kanel and processes.
- lsb_releas -a => prints version of Linux and release date
- ip addr => prints information about the network interface.
Compress a Folder to a Different Directory
- 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
- 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)
- 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
- adduser userName password newUser => will create a new user called userName and assign password of new user
- man "command" => will display help info about "command"
- man intro => very useful to display an introduction to the man command
- info info => more detailed information than that of "man": displays information about infor pages.
- whatis -r
- 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
- 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
- To remove the scheduled task run
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.
- Link Here
- Another good resource
Was this page helpful?