Saturday, March 1

Mount

mount command examples

To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01

# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2

CAT

cat command examples

You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.
$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf
    1	/var/log/btmp {
    2	    missingok
    3	    monthly
    4	    create 0660 root utmp
    5	    rotate 1
    6	}

Service

service command examples

Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.
Check the status of a service:
# service ssh status
Check the status of all the services.
service --status-all
Restart a service.
# service ssh restart

DF

df command examples

Displays the file system disk space usage. By default df -k displays output in bytes.
$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             29530400   3233104  24797232  12% /
/dev/sda2            120367992  50171596  64082060  44% /home
df -h displays output in human readable form. i.e size will be displayed in GB’s.
ramesh@ramesh-laptop:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G  3.1G   24G  12% /
/dev/sda2             115G   48G   62G  44% /home
Use -T option to display what type of file system.
ramesh@ramesh-laptop:~$ df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext4    29530400   3233120  24797216  12% /
/dev/sda2     ext4   120367992  50171596  64082060  44% /home

Free

free command examples

This command is used to display the free, used, swap memory available in the system.
Typical free command output. The output is displayed in bytes.
$ free
             total       used       free     shared    buffers     cached
Mem:       3566408    1580220    1986188          0     203988     902960
-/+ buffers/cache:     473272    3093136
Swap:      4000176          0    4000176
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.
$ free -g
             total       used       free     shared    buffers     cached
Mem:             3          1          1          0          0          0
-/+ buffers/cache:          0          2
Swap:            3          0          3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
ramesh@ramesh-laptop:~$ free -t
             total       used       free     shared    buffers     cached
Mem:       3566408    1592148    1974260          0     204260     912556
-/+ buffers/cache:     475332    3091076
Swap:      4000176          0    4000176
Total:     7566584    1592148    5974436

Crontab

crontab -a filenameInstall filename as your crontab file. On many systems, this command is executed simply as crontab filename (i.e., without the -a  option).
crontab -eEdit your crontab file, or create one if it doesn't already exist.
crontab -lDisplay your crontab file.
crontab -rRemove your crontab file.
crontab -vDisplay the last time you edited your crontab file. (This option is available on only a few systems.)
crontab -u userUsed in conjunction with other options, this option allows you to modify or view the crontab file of user. When available, only administrators can use this option.
FieldValueDescription
minute0-59The exact minute that the command sequence executes
hour0-23The hour of the day that the command sequence executes
day1-31The day of the month that the command sequence executes
month1-12The month of the year that the command sequence executes
weekday0-6The day of the week that the command sequence executes (Sunday = 0, Monday = 1, Tuesday = 2, and so forth)
commandSpecialThe complete sequence of commands to execute. The command string must conform to Bourne shell syntax. Commands, executables (such as scripts), or combinations are acceptable.
# Example 1:  0,30 8-17 * * 1-5 cmd
Show/Hide Answer (+/-)
Run cmd on the half-hour from 8:00 AM to 5:30 PM, Monday thru Friday
# Example 2:  0 12 1,15 * 5 cmd
Show/Hide Answer (+/-)
Run cmd at noon each Friday AND the first and fifteenth of every month
# Example 3:  17 3 * * 1 cmd
Show/Hide Answer (+/-)
Run cmd at 3:17 AM Monday (a backup program perhaps)
# Example 4:
# This command sends a "popup" message to the user's screen,
# at 3:00 PM Fridays, if they are logged in:
0 15 * * 5 echo "Time for staff meeting" | write $LOGNAME >/dev/null 2">"&1

# Example 5:
# This command sends a multi-line "popup" message to the user's screen,
# at 3:00 PM Fridays, if they are logged in:
0 15 * * 5 write $LOGNAME '>'/dev/null 2'>'&1 %Time for the%staff meeting.

shutdown

shutdown command examples

Shutdown the system and turn the power off immediately.
# shutdown -h now
Shutdown the system after 10 minutes.
# shutdown -h +10
Reboot the system using shutdown command.
# shutdown -r now
Force the filesystem check during reboot.
# shutdown -Fr now