Category Archives: 11. Linux Study


1. What is crontab?
Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. File location varies by operating systems, See Crontab file location at the end of this document.

2.What is a cron job or cron schedule?
Cron job or cron schedule is a specific set of execution instructions specifing day, time and command to execute. crontab can have multiple execution statments.

3. Crontab Restrictions
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.

4. Crontab Commands
export EDITOR=vi ;to specify a editor to open crontab file.

crontab -e Edit crontab file, or create one if it doesn’t already exist.
crontab -l crontab list of cronjobs , display crontab file contents.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)

5. Crontab file
Crontab syntax :
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

How to execute python script on schedule?

Linux Basic Qs

1. How can you see which kernel version a system is currently running?
A: uname

arobel@:~$ uname
arobel@:~$ uname -v
#184-Ubuntu SMP Wed Oct 18 11:55:51 UTC 2017
arobel@:~$ uname -r

cat /proc/version
Linux version 2.6.32-696.23.1.el6.x86_64 ( (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Mar 13 22:44:18 UTC 2018

2. How to check the IP address configured on the system?
A: ifconfig / ip addr show / ip addr show eth0

3. How do you check for free disk space?
A: df -ah (diskfree // all file system / human readable)

4. How do you manage services on a system?
A: service status/restart/start – service udev status
systemctl status

5. How would you check the size of a directory’s contents on disk?
A: du -sh (Disk used)

6. How would you check for open ports on a Linux machine?
A: netstat (big output) / netstat -tulpn (Tcp/upd/listening/port)

Note: use sudo id need more information

7. How do you check cpu usage for a process?
A: ps aux | grep / top(updated every 2sec ) decending order. / htop

8. Dealing with mounts?
A: ls /mnt
mount /dev/sda2 /mnt
mount (to verify)

less /etc/fstap (Disk partition / UUID/ Swap partition.

9. How do you look up something you don’t know?
A: man To check options of the command.

10. What do you do when can’t find an answer in man page?

Init, Upstart, Systemd

Quik Notes:
dd if=/dev/zero of=/dev/sda
dd -> writes stuffs (like, bit for bit, cylinder for cylinder, etc)

dd if=/dev/zero
write using input file /dev/zero (all zeros)

output and overwrite /dev/sda (first ATA/SCSI/SATA/SAS drive on system (meaning, your hard drvie).
so, the command wiped out everything on your hard drive.

How to set a static IP Address from CLI

Assuming you want to make the following changes to the network device eth0

Change the IP to the static value
Set the Subnet Mask to
Set the Default Gateway for the device to be
you can perform these changes using the following two commands

#sudo ifconfig eth0 netmask;
#sudo route add default gw eth0;

Linux Basic Commands

Linux Commands
Command Description
cat [filename] Display file’s contents to the standard output device
(usually your monitor).
cd /directorypath Change to directory.
chmod [options] mode filename Change a file’s permissions.
chown [options] filename Change who owns a file.
clear Clear a command line screen/window for a fresh start.
cp [options] source destination Copy files and directories.
date [options] Display or set the system date and time.
df [options] Display used and available disk space.
du [options] Show how much space each file takes up.
file [options] filename Determine what type of data is within a file.
find [pathname] [expression] Search for files matching a provided pattern.
grep [options] pattern [filesname] Search files or output for a particular pattern.
kill [options] pid Stop a process. If the process refuses to stop, use kill -9 pid.
less [options] [filename] View the contents of a file one page at a time.
ln [options] source [destination] Create a shortcut.
locate filename Search a copy of your filesystem for the specified
lpr [options] Send a print job.
ls [options] List directory contents.
man [command] Display the help information for the specified command.
mkdir [options] directory Create a new directory.
mv [options] source destination Rename or move file(s) or directories.
passwd [name [password]] Change the password or allow (for the system administrator) to
change any password.
ps [options] Display a snapshot of the currently running processes.
pwd Display the pathname for the current directory.
rm [options] directory Remove (delete) file(s) and/or directories.
rmdir [options] directory Delete empty directories.
ssh [options] user@machine Remotely log in to another Linux machine, over the network.
Leave an ssh session by typing exit.
su [options] [user [arguments]] Switch to another user account.
tail [options] [filename] Display the last n lines of a file (the default is
tar [options] filename Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).
top Displays the resources being used on your system. Press q to
touch filename Create an empty file with the specified name.
who [options] Display who is logged on.

NTP Server

NTP on Ubuntu

-sudo apt-get install ntp ntpdate

#Edit VIM
-sudo vim /etc/ntp.conf
Need to the add FF

# Note that “restrict” applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
-server iburst
-fudge stratum 1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict mask notrust
-restrict mask nomodify notrust

:x! -to save

#Restart services
-sudo /etc/init.d/ntp restart

-ntpq -p

Connect router / Switch
Conf t
ntp server x.x.x.x