Thursday, August 10, 2017

Tips & Tricks

1.Split the files
The following is an example of how to use the split command on a 600MB image.iso file:
# split -b 200m image.iso

It will generate three files, namely xaa,xab and xac of 200MB each. Afterwards you can use the cat command to combine the three to get back the original file, as follows
# cat xa* > newimage.iso

2. Prevent users from changing their passwords
You should have the root previliages to change this permission. Once you change this one users will not be able to change their passwords.
# chmod 511 /usr/bin/passwd

3. Crontab Example
first asterisk to enter the day of week 0-6, where 0 is Sunday. You can enter the month(1-12)in place of the second asterisk. Replace the third asterisk with the day of month (1-31). The fourth one is for the hour(0-23),while the fifth one is to enter the minutes(0-59).

For example, if you need to run a script daily at 5:30pm, then the entry will as shown below:
30 17 * * * sh /home/myuser/ >/dev/null 2>&1

If the last part “>/dev/null 2>&1” is omitted, then by default, cron will send an e-mail to the user account after executing the cronjob.

4. How to use the swap as a file?
To make a swap file of 1GB, multiply 1024MB and 1024 to get a block size. Now at a shell prompt as the root user, type the following command with the count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
Now set up the swap file:
mkswap /swapfile

Enable the swap file after create it by using the following command:
swapon /swapfile

Add the following entry in the /etc/fstab file to make the system activate this file as swap while booting the system:
/swapfile swap swap defaults 0 0