CRON Cheatsheet

I’m tired of always looking up CRON scheduling, so here it is including some examples.

CRON Scheduling table:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6)
# │ │ │ │ │                                      
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command to execute

Note that the day of week (0-6) typically starts with Sunday as the first index (0), so Monday = 1, Tuesday = 2 and so on. On some systems you might be able to also use 7 as Sunday.

CRON Examples:

Note that all the cron jobs output are redirected to /tmp/log.txt. If omitted, the default is to send an email to the sysadmin email address (if configured).

Run Python script every night at 02 am

* 02 * * * python /path/to/ >> /tmp/log.txt 2>&1

Run PHP script once every two hours

0 */2 * * * php /path/to/script.php >> /tmp/log.txt 2>&1

Run shell script every 10 minutes

*/10 * * * * /path/to/ >> /tmp/log.txt 2>&1

Workaround for running a script every 15 seconds

* * * * * /path/to/ >> /tmp/log.txt 2>&1

* * * * * sleep 15; /path/to/ >> /tmp/log.txt 2>&1

* * * * * sleep 30; /path/to/ >> /tmp/log.txt 2>&1

* * * * * sleep 45; /path/to/ >> /tmp/log.txt 2>&1

Run a script every weekday at midnight

0 0 * * 1-5 /path/to/ >> /tmp/log.txt 2>&1

Run script every Monday in June, July and August at 0530

30 05 * 6-8 1 /path/to/ >> /tmp/log.txt 2>&1

Related post:

Linux Cheatsheet

Powershell Snippets

List local user accounts

Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'"

List local user accounts and parse array

$local_users = Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | findstr "Caption";
for ($i = 0; $i -lt $local_users.Count; $i++) {
    Write-Host $local_users[$i].split("\\")[1];

List all installed Windows updates

Get-Hotfix-computername <hostname>Select HotfixID, InstalledOn |Sort-Object InstalledOn
Output will look something like:

tail equivalent in Powershell

Get-Content filename.txt -Tail 30

List all AD groups for user

Save the following code to a script called getgroups.ps1:

(New-Object System.DirectoryServices.DirectorySearcher(

Run the script from powershell and enter username as parameter, like this:

.\getgroups.ps1 johndoe

Linux Cheatsheet


ip addr show        => Display network interfaces and IP address
ip address add dev eth0 => Set IP address to
ethtool eth0 => Show ethernet status eth0
mii-tool eth0 => Show ethernet status for eth0
whois <domain> => Lookup whois info for domain
dig <domain> => Lookup DNS info for domain
host <domain> => Lookup DNS address for domain
wget fileurl => Download fileurl
netstat -tupl => List all active listening ports


dmesg               => List detected hardware and boot messages
cat /proc/cpuinfo => Get CPU info
cat /proc/meminfo => Get memory info
lshw => Display hardware configuration
lsblk => Display block device info
free -h => Display available memory in human readable format
lspci -tv => Display PCI devices
lsusb -tv => Display USB devices
dmidecode => Display hardware info from BIOS
hdparm -tT /dev/sda => Read speed test on disk "sda"
powertop => Battery life info
iotop => Disk IO info
smartctl => Disk status
tlp-stat => Power status and battery info

Print lines of code (amount) for all .php files in current directory

find . -name '*.php' | xargs wc -l

Log something to /var/log/syslog

logger <message>

Show all group memberships for current user


Get username for Apache service

ps aux | grep apache

(Relatively) secure permissions on public html folder for Apache/nginx

The goal is to set root as file owner and add the www-data as group (www-data is the group of the user running apache/nginx). Then, for every user which requires write-permission, simply add them to the www-data group.

sudo chown root:www-data /path/to/htdocs/* -R 
sudo chmod 775 /path/to/htdocs/* -R
chmod 775 gives everyone R/W/X except public because they shouldn’t have write permissions

Change www-data with whatever group belonging to the user account which is running apache/nginx.

Count files in directory

ls -lah | wc -l

Create an alias for bash commands and/or custom functions

First you need to open your bash profile config file. If preferred, you can use nano and open it with: nano ~/.bashrc

Example: Add a shorthand command for ls and tail with some extra parameters:

alias l="ls -lahS"
alias t='tail -n 200 $1'

As you can see, the tail command also reads file argument given to the command.

Example: Add a custom function for searching for a string in all files in current directory:

grepfor() {
grep -rnw './' -e "$1"

When done, reload your config file by running:
. ~/.bashrc

Search for string in files

grep -rnw '/path/to/dir/' -e 'stringpattern'

List only files with size above 100 MB

find . -type f -size +100M -exec ls -lh {} \;

This command scans the current dir for files above 100 MB and then executes the ls -lh command for those files. You could also say -size -10M to do the same for files below 10 MB in size.

Clean/format USB drives

sudo fdisk -l
sudo mkdosfs /dev/xxx # (i.e sdb1)
sudo mkdir /media/usb
sudo mount /dev/xxx /media/usb

See uptime and average load


Change timezone

sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Europe/Oslo /etc/localtime

Replace Europe/Oslo with your preferred timezone

Remove password for local user (make it passwordless)

sudo passwd --delete username

See current users logged on server

users (usernames only)


who(includes extra information like logon time and IP address etc)

Show IP addresses for all local network cards (including local loopback)

ifconfig | grep inet | cut -d: -f2 | cut -d" " -f1


ifconfig | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'

If you wish to see the IP address for a specific NIC (network interface card), simply append the name after ifconfig, like ifconfig eth0 | ...

Map network share

$ sudo mkdir /mnt/ShareName
$ sudo mount -t cifs -o username=domain\username,password=pw //server/share /mnt/ShareName

List automated ssh attacks to your server from syslog:

$ sudo cat /var/log/* | grep BREAK-IN

This post will be continually updated with useful commands and other notes for Linux environments

Related posts:

MS Cheatsheet

Show WiFi password in terminal for saved networks

netsh wlan show profile <SSID> key=clear | find "Key Content"

You can type

netsh wlan show profile

to list all wireless networks you’ve saved earlier.

List TCP/IP interfaces on remote computer

netsh -r "hostname" interface ipv4 show interfaces

Get Windows OEM license key

wmic path SoftwareLicensingService get OA3xOriginalProductKey

List environment variables


Filter output

set prog

Install .NET Framework 3.5 on Windows 10

Online version:
DISM.EXE /Online /Add-Capability /CapabilityName:NetFx3~~~~

Offline version (requires .cab installer for the .NET framework):
DISM.EXE /Online /Add-Package /PackagePath:C:\Temp\

Kill a non responding task from command prompt

taskkill /F /IM taskname.exe

/F = Force kill (ignores any prompts etc)

/IM = Image Name (name of process)

Generate WLAN report (run as admin)

netsh wlan show wlanreport

» See an example report here

List all server shares on local domain network

net view /all /

Message (aka net send)

msg /server:hostname username


msg /server:pc01 johndoe

List all local MAC addresses

getmac /v

Map network share

net use x: \\server\share /user:domain\username password

Remote sysinfo

msinfo32 /computer hostname

See uptime (and more)

net stats srv

if not available, use

net stats workstation

Show Domain Controllers in domain

nltest /

Set Environment variable on remote computer

setx /s hostname /u domain\user /p pw variable value


setx /s PC1234 /u itdb\kek /p 123456 JAVA_HOME "C:\Program Files\Java\jre1.8.0_73"

See Windows license expiration information

slmgr /xpr

Alternatively run slmgr /dli for detailed information about your Windows license

For remote computers: slmgr hostname username password /dli

Useful Windows utilities which you can start from the RUN prompt

  • lusrmgr.msc (Local Users Management)
  • sysdm.cpl (System Properties)
  • appwiz.cpl (Programs & Features)
  • eventvwr (Event Viewer)
  • compmgmt.msc (Computer Management)
  • printmanagement.msc (Print Management)
  • devmgmt.msc (Device Management)
  • services.msc (Services)
  • taskschd.msc (Task Scheduler)

This post will be continually updated with useful tips for remote troubleshooting and various tools for Microsoft environments

Related posts:

CRON Cheatsheet

Powershell Snippets

Linux Cheatsheet