Linux Server Administration: The Skills That Actually Make You Dangerous in Production
Most people learning DevOps start with Kubernetes...
For further actions, you may consider blocking this person and/or reporting abuse
This command:
means “find
.logfiles under/var/wwwthat were last modified more than 30 days ago.”Breakdown:
find— Linux command for searching files/directories./var/www— starting directory.findsearches it recursively, including subdirectories.-name "*.log"— only match filenames ending in.log.*means any sequence of characters.*.logbeforefindsees it.-mtime +30— match files whose modification time is more than 30 days ago.Example
Suppose
/var/wwwcontains:The command would output:
Important
-mtimedetail-mtimemeasures age in 24-hour periods, with rounding down. So-mtime +30is slightly stricter than simply saying “older than 30 calendar days”; in practice, it selects files whose rounded-down age is greater than 30 days.If you're using this to delete old logs, don't immediately add
-delete—it's safer to inspect the results first.If you're asking whether this is valid for every 5 minutes:
Yes. It means:
*/5— every 5 minutes (0, 5, 10, 15, ... 55)*— every hour*— every day of the month*— every month*— every day of the weekSo it runs at 12:00, 12:05, 12:10, 12:15, ...
*/5vs0:05In a cron expression, you don't write
0:05. The*/5goes in the minute field.means every 5 minutes.
If you meant incron specifically, that's different from cron:
incronis event-driven (e.g., “when this file changes”), so it doesn't use*/5to schedule periodic execution.For exactly 00:05 (5 minutes past midnight):
```cron id="r8x2kp"
5 0 * * *
So:
*/5 * * * *5 0 * * *0 5 * * *In cron,
/means “step” or “every N units.”So:
means “every 5.”
For the minute field:
means:
Think of it like this
*= all values/5= take every 5th value*/5= every 5Examples:
The
/is called the step value operator in cron.If you mean every 2 hours and 13 minutes (every 133 minutes), standard cron can't express that reliably with a simple
*/...expression, because cron fields reset at the hour boundary.If you mean at minute 13 of every 2nd hour, use:
That runs at:
So:
13= minute 13*/2= every 2 hours* * *= every day/month/day-of-weekIf you literally mean every 2 hours 13 minutes, tell me the starting time (e.g.
00:00), because that needs a different approach.To run once every day at 2:13 AM:
```cron id="z7p3kx"
13 2 * * *
If you mean run on the 15th of every month, but only if the 15th is a Saturday:
```cron id="k4m8tz"
0 0 15 * 6
Here
6means Saturday indate +%u.If you mean run on the 15th day of every month, at a specific time:
At midnight on the 15th
At 2:13 AM on the 15th
The fields are:
So
15in the third field means the 15th of every month.To run once a year on December 15th at midnight:
```cron id="v4x8nm"
0 0 15 12 *
This:
is shell redirection. It sends both normal output and errors into
/var/log/backup.log.1.
>> /var/log/backup.log>>means append output to the file.Example:
If
backup.shprints:those lines are added to the end of
backup.log.>= overwrite the file>>= append to the file2.
2>&1Linux programs have standard streams:
2>&1means:So:
means:
In a cron job
You might see:
This means:
Run the backup every day at 2:00 AM, append normal output and errors to
/var/log/backup.log.These are all
systemctlcommands for managing the Nginx service, but each does something different.systemctl start nginxsystemctl stop nginxsystemctl restart nginxsystemctl reload nginxsystemctl status nginxsystemctl enable nginx1.
startStarts Nginx immediately.
If Nginx is already running, there's generally nothing useful to do.
Important:
startdoes not automatically make Nginx start after reboot.2.
stopStops Nginx immediately.
Your website will become unavailable while Nginx is stopped.
3.
restartEssentially:
Useful when you want to completely restart Nginx.
For example, after making certain changes where a full restart is required.
4.
reloadTells Nginx to re-read its configuration without doing a full stop/start.
This is commonly preferred after changing Nginx configuration:
reloadis usually less disruptive because existing connections can continue while Nginx applies the new configuration.5.
statusShows information such as:
It can also show recent service log messages.
This doesn't start, stop, or modify Nginx.
6.
enableThis means:
It does not necessarily start Nginx right now.
If you want both:
This means:
Easy way to remember
And one very common combination for Nginx configuration changes is:
First test the configuration; only reload if the test succeeds.
This command is commonly used to find which directories are taking the most disk space:
Let's break it down:
1.
du -sh /*du= disk usage-s→ show only a summary for each item-h→ human-readable sizes (K,M,G, etc.)/*→ every file/directory directly under/Example output:
2.
|The pipe sends the output of the command on the left to the command on the right.
3.
sort -rhSorts the results by size.
-r→ reverse order, largest first-h→ understand human-readable sizes like45G,500M,2KWithout
-r, the smallest would come first.4.
| head -20headshows the first lines.means:
Since
sort -rhputs the largest first, you get the 20 largest items.Overall meaning
means:
For example:
This is a useful command when you get an alert like:
and want to quickly find where the space is being used.
Sure.
sedis a stream editor, commonly used to find and replace text.The basic command:
means:
Break it down
The important part is:
Think of it as:
Example 1: Simple replacement
File:
Run:
Result:
Example 2: Replace a word
Before:
Command:
After:
Example 3: Change a port
Before:
Command:
After:
Example 4: Change a configuration value
Before:
Command:
After:
Example 5: Replace only the first occurrence
Suppose:
Using:
Result:
Without
g,sedreplaces only the first match on each line.With
g:Result:
So:
Example 6: Replace only on a specific line
File:
Change only line 2:
Result:
The
2means:Example 7: Replace on a range of lines
Means:
Example 8: Delete lines
sedisn't only for replacement.Delete line 3:
Delete blank lines:
Here:
^= beginning of line$= end of line^$= empty lined= deleteExample 9: Comment out a line
Before:
Command:
After:
^PermitRootLoginmeans:Example 10: Replace an entire line
Suppose:
You want:
You can use:
Here:
So it replaces the entire matching line.
Very important:
-iCompare:
This prints the modified content, but doesn't change
file.txt.Whereas:
actually modifies
file.txt.For safety, you can create a backup:
Now you have:
This is particularly useful when modifying things like Nginx, SSH, or application configuration files.
Cheat sheet
The key thing to remember is:
s/what/with-what/g= substitutewhatwithwith-what, globally on each line.This command:
means:
Break it down
Suppose
file.txtcontains:Run:
Result:
Notice:
oldreplaced withnewCompare
→ Replace throughout the entire file.
→ Replace only on line 2.
→ Replace only on lines 2, 3, and 4.
A useful pattern to remember:
So
2,4is the range, ands/old/new/gis the operation performed on that range.If you want to replace
oldwithnewonly on line 1 and line 5, you can use:Easier to understand
The
;separates twosedcommands.For example:
After:
you get:
Another way
You can use a pattern to select specific lines:
For just two specific lines, this is the clearest approach.
022inumaskmeans remove these permissions from the default permissions.Think of it as:
Why files become
644New files start with a maximum base permission of:
Apply
umask 022:So:
rw-r--r--Why directories become
755Directories start with:
Apply
022:So:
rwxr-xr-xWhat does each digit mean?
Permission values:
So
umask 022essentially means:That's why
022is a very common default on Linux servers.