Thursday 30 April 2020

Exam 101: Control mounting and unmounting of filesystems

LPI Study Material, LPI Guides, LPI Learning, LPI Certification, LPI Exam Prep


Linux filesystems


The Linux filesystem is one big tree rooted at /, and yet we have filesystems on different devices and partitions. How do we resolve this apparent incongruity? The root (/) filesystem is mounted as part of the initialization process. Each of the other filesystems that you create is not usable by your Linux system until it is mounted at a mount point.

Prerequisites


To get the most from the post in this series, you should have a basic knowledge of Linux and a working Linux system on which you can practice the commands covered in this post. Unless otherwise noted, the examples in this post use CentOS 6, with a 2.6.32-504 kernel. Your results on other systems may differ. Sometimes different versions of a program will format output differently, so your results may not always look exactly like the listings and figures shown here.

Mounting filesystems


In the current set of mounted filesystems, a mount point is simply a directory where the filesystem on a device is grafted into the tree. Mounting is the process of making the filesystem on the device accessible. For example, you might mount filesystems on hard drive partitions as /boot, /tmp, or /home, and you might mount the filesystem on a floppy drive as /mnt/floppy and the filesystem on a CD-ROM as /media/cdrom1. As you can see, mount points may be in the root directory, or in a subdirectory farther down the tree.

Besides filesystems on partitions, floppy disks, and CDs, there are other types of filesystems. The tmpfs filesystem is a virtual memory filesystem. You can also mount filesystems from one system on another system using a networked filesystem such as NFS or AFS. You can even create a file in an existing filesystem and format that as a, possibly different, kind of filesystem and mount that too. This is often done with images of optical media, where you perhaps download an ISO CD or DVD image, then mount that file rather than burning it to real media. Swap space in a file rather than a dedicated swap partition is another example.

While the mount process actually mounts the filesystem on some device (or other resource), it is common to simply say that you “mount the device,” which is understood to mean “mount the filesystem on the device.”

Mounting and unmounting filesystems usually requires root authority. If you are logged in as an ordinary user, you will either use su - to switch to root or sudo. In our examples, when the command prompt ends with #, as in the listing below, you will need root authority.

The basic form of the mount command takes two parameters: the device (or other resource) containing the filesystem to be mounted, and the mount point. We’ll mount our small FAT32 partition /dev/sda3 at the mount point /dos. The mount point must exist before you mount anything over it. If it does not, you will get an error and need to create the mount point or use a different mount point. We illustrate these aspects of basic mounting in Listing 2.

Listing 2. Mount error

[root@attic4‑cent ~]#mount /dev/sda3 /dos
mount: mount point /dos does not exist
[root@attic4‑cent ~]#mkdir /dos
[root@attic4‑cent ~]#mount /dev/sda3 /dos

When you mount a filesystem over an existing directory, the files on the filesystem you are mounting become the files and subdirectories of the mount point. If the mount point directory already contained files or subdirectories, they are not lost, but are no longer visible until the mounted filesystem is unmounted, at which point they become visible again. It is a good idea to avoid this problem by using only empty directories as mount points.

After mounting a filesystem, any files or directories created or copied to the mount point or any directory below it will be created on the mounted filesystem. So a file such as /dos/sampdir/file.txt will be created on the FAT32 filesystem that we mounted at /dos in our example.

Usually, the mount command will automatically detect the type of filesystem being mounted. Occasionally you may need to specify the filesystem type explicitly using the -t option as shown in Listing 3.

Listing 3. Mounting with explicit filesystem type

[root@attic4‑cent ~]#mount ‑t vfat /dev/sda3 /dos

To see what filesystems are mounted, use the mount command with no parameters. Listing 4 shows our example system. Note that you do not need root authority to simply list mounted filesystems.

Listing 4. Displaying mounted filesystems

[ian@attic4‑cent ~]$ mount
/dev/sda11 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /grubfile type ext3 (rw)
/dev/sdb2 on /home/ian/data type ext4 (rw)
/dev/sdb3 on /home/ian/research type ext3 (rw)
/dev/sdc1 on /home/ian/pictures type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sda3 on /dos type vfat (ro)
/dev/sr0 on /media/KNOPPIX type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=1000,
gid=1000,iocharset=utf8,mode=0400,dmode=0500)

You can also view similar information by displaying /proc/mounts or /etc/mtab, both of which contain information about mounted filesystems.

Mount options


The mount command has several options that override the default behavior. For example, you can mount a filesystem read-only by specifying -o ro. If the filesystem is already mounted, add remount as shown in Listing 5.

Listing 5. Remounting read-only

[root@attic4‑cent ~]#mount ‑o remount,ro /dos

Notes:

◉ Use commas to separate multiple options, such as remount and ro.

◉ When remounting an already mounted filesystem, it suffices to specify either the mount point or the device name. It is not necessary to specify both.

◉ You cannot mount a read-only filesystem as read-write. Media that cannot be modified, such as CD-ROM discs, will automatically be mounted read-only.

◉ To remount a writable device read-write, specify -o remount,rw-oremount,rw

Remount commands will not complete successfully if any process has open files or directories in the filesystem you are remounting.

Labels, UUIDs, and links


In UNIX and early Linux systems, the /dev directory usually contained entries for all the devices that might ever be attached to a system. Any device that was used was always located in the same place in the /dev tree, so using names such as /dev/sda6 was natural. With the advent of hot-plugging of devices such as USB or Firewire (IEEE 1394) attached devices, a given device might appear in one USB port today, and that same device might be plugged into a different USB port tomorrow. In this environment, you might want to always mount your USB stick at /media/myusbstick, regardless of which USB port you plug it in to. If the filesystem on the partition supports either, you can use these with the mount command too. Use the blkid command to find out the UUID and label (if present) associated with a device.

Listing 6 shows how to use blkid to find the label and UUID for our root partition and then how to create two additional mount points and mount the root partition at these two additional points. This example is for illustration. You would not normally do this in a production environment.

Listing 6. Mount using labels or UUIDs

[root@attic4‑cent ~]#blkid /dev/sda11
/dev/sda11: UUID="2f60a3b4‑ef6c‑4d4c‑9ef4‑50d7f75124a2" TYPE="ext3" LABEL="CentOS 6"
[root@attic4‑cent ~]#mkdir /mnt/sda11label
[root@attic4‑cent ~]#mkdir /mnt/sda11uuid
[root@attic4‑cent ~]#mount LABEL="CentOS 6" /mnt/sda11label
[root@attic4‑cent ~]#mount UUID="2f60a3b4‑ef6c‑4d4c‑9ef4‑50d7f75124a2" /mnt/sda11uuid

With the advent of udev, you will find additional symbolic links in the /dev directory for devices such as hard drives. Listing 7 shows the links to /dev/sda6 on my CentOS 6 system.

Listing 7. Symbolic links to /dev/sda6

[root@attic4‑cent ~]#find /dev ‑lname "*sda11"/dev/root
/dev/disk/by‑label/CentOS\x206
/dev/disk/by‑uuid/2f60a3b4‑ef6c‑4d4c‑9ef4‑50d7f75124a2
/dev/disk/by‑id/wwn‑0x50014ee056628af6‑part11
/dev/disk/by‑id/scsi‑SATA_WDC_WD6401AALS‑_WD‑WMASY6347052‑part11
/dev/disk/by‑id/ata‑WDC_WD6401AALS‑00L3B2_WD‑WMASY6347052‑part11
/dev/disk/by‑path/pci‑0000:00:11.0‑scsi‑0:0:0:0‑part11
/dev/block/8:11
/dev/.udev/watch/113
/dev/.udev/links/disk\x2fby‑label\x2fCentOS\x5cx206/b8:11
/dev/.udev/links/root/b8:11
/dev/.udev/links/disk\x2fby‑id\x2fwwn‑0x50014ee056628af6‑part11/b8:11
/dev/.udev/links/disk\x2fby‑uuid\x2f2f60a3b4‑ef6c‑4d4c‑9ef4‑50d7f75124a2/b8:11
/dev/.udev/links/disk\x2fby‑path\x2fpci‑0000:00:11.0‑scsi‑0:0:0:0‑part11/b8:11
/dev/.udev/links/disk\x2fby‑id\x2fscsi‑SATA_WDC_WD6401AALS‑_WD‑WMASY6347052‑part11/b8:11
/dev/.udev/links/disk\x2fby‑id\x2fata‑WDC_WD6401AALS‑00L3B2_WD‑WMASY6347052‑part11/b8:11

You can also use a symbolic link as another way of specifying the device name when mounting a device.

Boot time and fstab


In the post for topic 102, “Learn Linux, 101: Boot managers,” you learned how to use the root= parameter in both GRUB and LILO to tell the boot loader what filesystem should be mounted as root. For GRUB2, this is the set rootsetroot statement. Once the root filesystem is mounted, the initialization process runs mount with the -a option to automatically mount a set of filesystems. The set is specified in the file /etc/fstab.

Listing 8 shows /etc/fstab for a sample CentOS 6 system. In this example, most hard drive partitions are identified by UUID. I have added examples of how to mount /dev/sda3 at /dos as we did earlier, and also how to use a label to mount a labeled partition at /mnt/fedora22.

Listing 8. Example CentOS 6 fstab

[root@attic4‑cent ~]#cat /etc/fstab

#
#/etc/fstab
#Created by anaconda on Wed Jul  8 09:34:46 2015
#
#Accessible filesystems, by reference, are maintained under '/dev/disk'
#See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=2f60a3b4‑ef6c‑4d4c‑9ef4‑50d7f75124a2 /                   ext3    defaults        1 1
UUID=3c3de27e‑779a‑44d5‑ad7a‑61c5fd03d9e7 /grubfile           ext3    defaults        1 2
UUID=158d605e‑2591‑4749‑bf59‑5e92e1b1c01d swap                swap    defaults        0 0
tmpfs                                     /dev/shm            tmpfs   defaults        0 0
devpts                                    /dev/pts            devpts  gid=5,mode=620  0 0
sysfs                                     /sys                sysfs   defaults        0 0
proc                                      /proc               proc    defaults        0 0
UUID=4c962b67‑c646‑467f‑96fb‑cbbd6de40140 /home/ian/data      ext4    defaults        1 2
UUID=0998d33c‑3398‑463d‑b0e3‑7c13ca0c675f /home/ian/research  ext3    defaults        1 2
UUID=e3be4658‑b79b‑470d‑82fe‑bb434bcdcc2f /home/ian/pictures  ext4    defaults        1 2
LABEL="FEDORA22"                          /mnt/fedora22       ext4    defaults        1 2
/dev/sda3                                 /dos                vfat    defaults        0 0

Lines starting with a # character are comments. Remaining lines contain six fields. Because the fields are positional, they must all be specified.

file system
This may be a device name such as /dev/sda1, or a label (LABEL=) or UUID (UUID=). For the root filesystem of our CentOS 6 example, it could be /dev/sda11, LABEL=”CentOS 6″, or UUID=2f60a3b4-ef6c-4d4c-9ef4-50d7f75124a2. Using a label or UUID makes your system more robust when devices are added or removed.

mount point
This is the mount point we discussed in Mounting filesystems above. For swap space, this should be the value ‘none’ or ‘swap’. On older systems you will usually find the value ‘none’.

type
Specifies the type of filesystem. CD/DVD drives will often support either ISO9660 or UDF filesystems, so you may specify multiple possibilities in a comma-separated list if you specify such a drive in /etc/fstab. If you want mount to automatically determine the type, specify auto. For example, you might see lines like the following on some older systems for a CD or DVD and a floppy disk.
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0

option
◉ Specifies the mount options. Specify defaults if you want default mount options. Some options you will want to know about are:

◉ rw and ro specify whether the filesystem should be mounted read-write or read-only.

◉ noauto specifies that this filesystem should not be automatically mounted at boot time or whenever mount -a is issued. In our example, this is done for the removable drives.

◉ user specifies that a non-root user is permitted to mount and unmount the filesystem. This is especially useful for removable media. In older systems, this option is specified in /etc/fstab rather than on the mount command. With newer systems, it may be specified in udev rules that are located in rules files within /lib/udev/rules.d or /etc/udev/rules.d. The options for the DVD drive on my CentOS 6 system come from udev rules, and that is why there is no entry in /etc/fstab for an optical drive.

◉ exec and noexec specify whether or not to allow execution of files from the mounted filesystem. User-mounted filesystems default to noexec unless exec is specified afteruser.

◉ noatime will disable recording of access times. Not using access times may improve performance.

dump
Specifies whether the dump command should consider this ext2 or ext3 filesystem for backups. A value of 0 tells dump to ignore this filesystem.

pass
Non-zero values of pass specify the order of checking filesystems at boot time, as discussed in our post “Learn Linux, 101: Maintain the integrity of filesystems.”

When you mount a filesystems that is listed in /etc/fstab, you can give either the device name or the mount point when mounting the filesystem. You do not need to give both.

On some systems, for example SUSE 11.2, you may find that the fstab generated at install time uses symbolic links to the device. So, you may see /dev/disk/by-id/ata-WDC_WD1001FALS-00J7B1_WD-WMATV3772868-part6, rather than /dev/sda6 for the file system value. Refer back to Listing 7 for additional possibilities

Consult the man pages for fstab, mount, and udev for additional information, including options not covered here.

Unmounting filesystems


All mounted filesystems are usually unmounted automatically by the system when it is rebooted or shut down. When a filesystem is unmounted, any cached filesystem data in memory is flushed to the device.

You may also unmount filesystems manually. Indeed, you should do this when removing writable media such as diskettes or USB drives or memory keys.

Use the unmount command to unmount the filesystem, specifying either the device name or mount point as an argument. This listing shows how to unmount /dos, then remount it and unmount again using the device name.

Listing 10. Unmounting filesystems

[root@attic4‑cent ~]#umount /dos
[root@attic4‑cent ~]#mount /dev/sda3 /dos
[root@attic4‑cent ~]#umount /dev/sda3

After a filesystem is unmounted, any files in the directory used for the mount point are visible again.

If you attempt to unmount a filesystem while a process has open files on that filesystem, you will see an error message. Before unmounting a filesystem, you should check that there are no processes running that have open files on the filesystem. Use the lsof or fusercommand to determine what files are open or what process has open files. You may need the -w option on lsof to avoid warning messages related to the Gnome Virtual File system (gvfs). Check the man pages to learn about additional mount options and lsof. If you are checking a whole device, you can specify the device name or the mount point. You may also check whether an individual file is in use or not.

To illustrate these commands, I created a copy of /etc/fstab on /dos and a small script to read lines from stdin and print them to stdout with a 10 second pause between each line. Listing 11 shows the error message from umount when files are in use and the use of lsof and fuser to check for open files on /dos, or the underlying device /dev/sda9.

Listing 11. Checking for open files

[root@attic4‑cent ~]#umount /dos
umount: /dos: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@attic4‑cent ~]#lsof ‑w /dos
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
slowread. 28960  ian    0r   REG    8,3     1207    2 /dos/fstab
sleep     28972  ian    0r   REG    8,3     1207    2 /dos/fstab
[root@attic4‑cent ~]#lsof ‑w /dev/sda3
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
slowread. 28960  ian    0r   REG    8,3     1207    2 /dos/fstab
sleep     28978  ian    0r   REG    8,3     1207    2 /dos/fstab
[root@attic4‑cent ~]#lsof ‑w /dos/fstab
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
slowread. 28960  ian    0r   REG    8,3     1207    2 /dos/fstab
sleep     28989  ian    0r   REG    8,3     1207    2 /dos/fstab
[root@attic4‑cent ~]#fuser ‑m /dos
/dos:                28960 29001
[root@attic4‑cent ~]#fuser ‑m /dev/sda3
/dev/sda3:           28960 29001

At this point you can either wait until the filesystem is no longer busy, or you can do a lazy unmount, by specifying the -l option. A lazy unmount detaches the filesystem from the filesystem tree immediately, and cleans the references to the filesystem when it is no longer busy.

Removable filesystems


We mentioned some issues with removable devices such as USB or Firewire (IEEE 1394) attached devices. It is inconvenient to switch to root access every time you need to mount or unmount such a device. The same goes for CD, DVD, and floppy drives, where you need to unmount the device to change media. In the discussion of fstab above, we mentioned the user option, which allows ordinary users to mount and unmount devices.

Note that the filesystem types for the optical drive are specified as udf,iso9660, while the filesystem type for the floppy is specified as auto. For the optical drive, the mount process will check first for a udf filesystem (common on DVD) and then for an iso9660 filesystem (common on CD). For the floppy drive, the mount process will probe for a filesystem type. You can create or edit /etc/filesystems to change the order in which the filesystems will be probed.

Note: You should always unmount removable drives or media before disconnecting the drive or attempting to remove the media. Failure to do so may result in loss of data that has not yet been written to the device.

If you run a graphical desktop such as Nautilus, you will usually find options that allow removable devices and media to be automatically mounted. For example, if I insert a Knoppix DVD into the DVD drive of my system, I might see a mount entry such as shown in Listing 12. The presence of ‘uid=1000’ shows that the user with id 1000 can unmount this disc. The id command shows the uid for user ian is 1000, so ian can unmount this disc.

Listing 12. Desktop mounting of DVD

[ian@attic4‑cent ~]$ mount | grep sr0
/dev/sr0 on /media/KNOPPIX type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=1000,
gid=1000,iocharset=utf8,mode=0400,dmode=0500)
[ian@attic4‑cent ~]$ id ian
uid=1000(ian) gid=1000(ian) groups=1000(ian)

You may also use the eject command to eject removable media when the drive supports the operation as most CD and DVD drives do. If you have not unmounted the device first, then eject will both unmount and eject the disc.

Swap space


You may have noticed in the discussion of fstab above that swap space does not have a mount point. The boot process usually enables swap space defined in /etc/fstab unless the noauto option is specified. To manually control swap space on a running system — for example, if you added a new swap partition—use the swapon and swapoff commands. See the man pages for details.

You can view the currently enabled swap devices with cat /proc/swaps or with swapon -sswapon-s as shown in Listing 13.

Listing 13. Displaying swap space

[ian@attic4‑cent ~]$ swapon ‑s
Filename  Type  Size  Used  Priority
/dev/sda2                               partition  10241432  8 ‑1
[ian@attic4‑cent ~]$ cat /proc/swaps
Filename  Type  Size  Used  Priority
/dev/sda2  partition  10241432  8  ‑1

This completes your introduction to device mounting and unmounting on Linux.

Tuesday 28 April 2020

wc command in Linux with examples - 2020

wc stands for word count. As the name implies, it is mainly used for counting purpose.

WC Command, Linux Tutorial and Material, Linux Guides, LPI Tutorial and Material

◉ It is used to find out number of lines, word count, byte and characters count in the files specified in the file arguments.

◉ By default it displays four-columnar output.

◉ First column shows number of lines present in a file specified, second column shows number of words present in the file, third column shows number of characters present in file and fourth column itself is the file name which are given as argument.

Syntax:


wc [OPTION]... [FILE]...

Let us consider two files having name state.txt and capital.txt containing 5 names of the Indian states and capitals respectively.

$ cat state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh

$ cat capital.txt
Hyderabad
Itanagar
Dispur
Patna
Raipur

Passing only one file name in the argument.

$ wc state.txt
 5  7 63 state.txt
       OR
$ wc capital.txt
 5  5 45 capital.txt

Passing more than one file name in the argument.

$ wc state.txt capital.txt
  5   7  63 state.txt
  5   5  45 capital.txt
 10  12 108 total

Note : When more than file name is specified in argument then command will display four-columnar output for all individual files plus one extra row displaying total number of lines, words and characters of all the files specified in argument, followed by keyword total.

Options:


1. -l: This option prints the number of lines present in a file. With this option wc command displays two-columnar output, 1st column shows number of lines present in a file and 2nd itself represent the file name.

With one file name
$ wc -l state.txt
5 state.txt

With more than one file name
$ wc -l state.txt capital.txt
  5 state.txt
  5 capital.txt
 10 total

2. -w: This option prints the number of words present in a file. With this option wc command displays two-columnar output, 1st column shows number of words present in a file and 2nd is the file name.

With one file name
$ wc -w state.txt
7 state.txt

With more than one file name
$ wc -w state.txt capital.txt
  7 state.txt
  5 capital.txt
 12 total

3. -c: This option displays count of bytes present in a file. With this option it display two-columnar output, 1st column shows number of bytes present in a file and 2nd is the file name.

With one file name
$ wc -c state.txt
63 state.txt

With more than one file name
$ wc -c state.txt capital.txt
 63 state.txt
 45 capital.txt
108 total

4. -m: Using -m option ‘wc’ command displays count of characters from a file.

With one file name
$ wc -m state.txt
63 state.txt

With more than one file name
$ wc -m state.txt capital.txt
 63 state.txt
 45 capital.txt
108 total

5. -L: The ‘wc’ command allow an argument -L, it can be used to print out the length of longest (number of characters) line in a file. So, we have the longest character line Arunachal Pradesh in a file state.txt and Hyderabad in the file capital.txt. But with this option if more than one file name is specified then the last row i.e. the extra row, doesn’t display total but it display the maximum of all values displaying in the first column of individual files.

Note: A character is the smallest unit of information that includes space, tab and newline.

With one file name
$ wc -L state.txt
17 state.txt

With more than one file name
$ wc -L state.txt capital.txt
 17 state.txt
 10 capital.txt
 17 total

6. –version: This option is used to display the version of wc which is currently running on your system.

$ wc --version
wc (GNU coreutils) 8.26
Packaged by Cygwin (8.26-1)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Applications of wc Command


1. To count all files and folders present in directory: As we all know ls command in unix is used to display all the files and folders present in the directory, when it is piped with wc command with -l option it display count of all files and folders present in current directory.

$ ls gfg
a.txt
b.txt 
c.txt 
d.txt 
e.txt 
geeksforgeeks 
India

$ ls gfg | wc -l
7

2. Display number of word count only of a file: We all know that this can be done with wc command having -w option, wc -w file_name, but this command shows two-columnar output one is count of words and other is file name.

$ wc -w  state.txt
7 state.txt

So to display 1st column only, pipe(|) output of wc -w command to cut command with -c option. Or use input redirection(<).

$ wc -w  state.txt | cut -c1
7
      OR
$ wc -w < state.txt
7

Sunday 26 April 2020

‘dd’ command in Linux - 2020

dd is a command-line utility for Unix and Unix-like operating systems whose primary purpose is to convert and copy files.

◈ On Unix, device drivers for hardware (such as hard disk drives) and special device files (such as /dev/zero and /dev/random) appear in the file system just like normal files.

DD Command, Linux Tutorial and Materials, Linux Certification, LPI Study Materials

◈ dd can also read and/or write from/to these files, provided that function is implemented in their respective drivers

◈ As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data.

◈ The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.

Usage: The command line syntax of dd differs from many other Unix programs, in that it uses the syntax option=value for its command line options, rather than the more-standard -option value or –option=value formats. By default, dd reads from stdin and writes to stdout, but these can be changed by using the if (input file) and of (output file) options.

Some practical examples on dd command :


1. To backup the entire harddisk : To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command as shown. In this dd command example, the UNIX device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.

# dd if = /dev/sda of = /dev/sdb

◈ “if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.

◈ If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.

◈ Input file and output file should be mentioned very carefully. Just in case, you mention source device in the target and vice versa, you might loss all your data.

◈ To copy, hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.

# dd if = /dev/sda of = /dev/sdb conv=noerror, sync

2. To backup a Partition : You can use the device name of a partition in the input file, and in the output either you can specify your target path or image file as shown in the dd command.

# dd if=/dev/hda1 of=~/partition.img

3. To create an image of a Hard Disk : Instead of taking a backup of the hard disk, you can create an image file of the hard disk and save it in other storage devices. There are many advantages of backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe.It creates the image of a harddisk /dev/hda.

# dd if = /dev/hda of = ~/hdadisk.img

4. To restore using the Hard Disk Image : To restore a hard disk with the image file of an another hard disk, the following dd command can be used

# dd if = hdadisk.img of = /dev/hdb

The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.

5. To create CDROM Backup : dd command allows you to create an iso file from a source file. So we can insert the CD and enter dd command to create an iso file of a CD content.

# dd if = /dev/cdrom of = tgsservice.iso bs = 2048

dd command reads one block of input and process it and writes it into an output file. You can specify the block size for input and output file. In the above dd command example, the parameter “bs” specifies the block size for the both the input and output file. So dd uses 2048bytes as a block size in the above command.

Saturday 25 April 2020

Why Linux is Better?

LPI Study Material, LPI Certifications, LPI Tutorial and Material, LPI Exam Prep, LPI Study Material

Look around and you will see Linux everywhere, yes it is right! Linux is present in Android phones. Android uses the Linux kernel under the hood. As Linux is an open-source operating system, Google’s Android developers generally modify the Linux kernel to satisfy their requirements. Linux offers the Android developers a pre-built already maintained operating system kernel to commence with, so no need to start afresh. This is the way many different devices are built. For example, the PlayStation 4 uses the open-source FreeBSD kernel, while the Xbox One uses the Windows NT kernel found in modern versions of Windows.

If you are an Android user you can see Linux kernel version running on your device under About phone or About tablet in Android’s Settings. You will be surprised to know that entire clan of supercomputers run on Linux kernel, the reason being Linux is free and easily customizable. After all, not just applications, such as word processors and web browsers, can be discarded but also users can choose core components, such as which system displays graphics, and other user-interface components. Below are some reasons that describe why Linux is better:

1. The main highlighting feature of Linux is that it is open-source software. The code used to create Linux is free and accessible to society to view, edit, and for users with the relevant skills to contribute to.

2. One of the most stimulating things about using Linux is that there is no forced reboots or no contentious update nags. And the fact that most of the software installed updates right alongside the system. If an application is being used, Linux simply postpones them until the software is shut down. Once the system restarts, the new version is loaded. No nags, no interruptions, no stepping through multiple dialogue windows. It’s pretty much an invisible process to the user.

3. An even elevated level of security on Linux machines is implemented by IPtables. This is a firewall that allows you to create a further secured environment for the execution of any command or access the network.

4. Linux is available in distributions such as Linux Mint, Debian, Ubuntu, Gentoo, Kali, and many others. Various email clients, the environment, console and system packages also make the system extremely fragmented.

5. Linux is completely free and with the long-term support (LTS) so no need for activation key, unlike Windows-which will also display a pop-up on every screen prompting to ‘Activate Now’, ruining all your screenshots at once.

6. In Linux, you get superUser access and privileges (for real), as Linux OS will not take any step without the consent of the superuser. So while installing updates in Windows, you have to reboot while in Linux you have to be root.

7. While Linux installation, you don’t need to install drivers for Wi-Fi, Bluetooth, mouse, touchpad etc. explicitly as they can be installed during installation with little patience. While windows will tell (not ask) you to update for the first time to install updated drivers and by chance, if you happen to update on mobile data then all the data for the day goes poof!!! So if you want to use your internet to its full capacity, then switch to Linux.

8. Windows is known for its good looking GUI, but there are some things which cannot be done using a couple of mouse clicks so you need a Command Line Interface which is the Linux terminal.

9. Linux distributions are architectured in such a way that they can work smoothly, without any glitch, even in a system with 2 GB RAM. So, Linux is stable with fewer specifications.

10. Linux community is loyal to all the Linux users so it would give Long Term Support, unlike the Windows community which recently stopped giving support for Windows 7 users so for any bugs or data breach in Windows 7, you cannot contact Windows help centres.

11. A Linux distribution is fully customizable right from the start screen (Plymouth) to the Desktop environment, from icons to mouse pointers, you have full access to your OS. The best part, Make up your own Linux using a Linux kernel and make it public.

12. Currently, there are 500+ distributions of Linux available on the digital web, so it’s difficult to tell which one is the best. The clear answer is based on the requirement:

◉ For general-purpose, use Linux based on Debian and red hat

◉ For programming purpose, use Linux based on Arch

◉ For hackers, there is Kali Linux, cyborg, parrot

13. Ever heard of anti-virus for Linux? Because they don’t exist as Linux malware are not over the internet like Windows malware is so feel free to download anything. Also due to the security features of Linux, it is less vulnerable.

Thursday 23 April 2020

Unix/Linux ‘alias’ command examples

Linux Study Materials, Linux Certification, Linux Guides, Linux Exam Prep

Unix and Linux aliases are a really nice way of customizing the command line to work the way you want it to work. With alias commands, you’re essentially doing a little programming, and creating new Unix and Linux commands custom-tailored to the way you work. You can create aliases to use instead of existing commands, and you can also create aliases as Linux command pipelines.

I’m not going to describe my Linux aliases too much, but mostly just put them out here so you can see how they work. One thing I should note is that this syntax assumes you’re using the Bash or Korn shells. The syntax is a little different with other shells, like csh, but I don’t remember the syntax differences, so I’m just going with the Bash alias syntax.

Sample Linux aliases


Here’s a list of sample aliases I currently use (or have used in the past):

alias cd..="cd .."
alias cd...="cd ../.."
alias cd...="cd ../.."
alias gi="grep -i"
alias l="ls -al"
alias lm="ls -al | more"
alias lf="ls -FG"
alias h=history
alias hm="history | more"

# places
alias bin="cd /Users/al/tomcat/bin"
alias html="cd /home/apache/html"

# file finding
alias ff="find . -type f -name "

# "que pasa" (an old friend said this a lot)
alias qp="ps auxwww | more"

# ssh: i modified this one for public consumption
alias fb="ssh al@foo.bar.com"

# for dos users
alias dir="ls -al"
alias md=mkdir
alias ren=mv
alias type=cat
alias search=grep

Hopefully most of those aliases are very straightforward. Note that any time you have spaces in your commands (to the right of the equal sign) you'll need to put quotes around your commands.

Using Linux aliases


Once you've configured your aliases you can use them just like a normal Linux command, like this:

cd...

The system responds by replacing your alias with the actual command(s) the alias represents:

cd ../..

The weirdest alias I've shown may be ff, which I use like this:

ff some_file

which expands to this:

find . -type f -name some_file

Tuesday 21 April 2020

An `egrep` example with multiple regular expressions

Linux Tutorial and Material, Linux Guides, Linux Certifications, Linux egrep, LPI Exam Prep

Summary: How to use the Linux egrep command with multiple regular expressions (regex patterns).

As a quick note here today, I just used the Linux egrep command to perform a case-insensitive search on multiple regular expressions (regex patterns). Really, what I did was a little more complicated:

locate -i calendar | grep Users | egrep -vi 'twiki|gif|shtml|drupal-7|java|PNG'

As you can see from that command, I did this:

◉ Used to locate command with the case-insensitive option to find all files with the string "calendar" in them.

◉ Used the grep command so the output would only display files and directories with the string "Users" in them.

◉ Used the egrep command with multiple regex patterns to reduce the output much more. I used the -v argument to perform the "opposite" meaning of a normal egrep command, so strings with these patterns were not shown; and also used the -i argument to perform a case insensitive egrep search here.

While my original locate -i calendar command shows nearly 3,000 files, the locate command combined with grep and egrep in this manner shows only 15 files.

An easier egrep command


Before I go away, here's an easier egrep command to look at:

egrep 'apple|banana|orange' *

That egrep command searches for those three strings (regular expressions, really) in all files in the current directory. This next command does the same thing, but in a case-insensitive manner:

egrep -i 'apple|banana|orange' *

Sunday 19 April 2020

Linux pipe command examples (command mashups)

One of my favorite things about Unix, Linux, and Mac OS X systems is that you can create your own commands by merging other commands. There isn't any formal name for these command combinations, other than to say that you're "piping" commands together, so I recently started referring to these as "command mashups".

Linux Pipe Command, Linux Tutorials and Materials, LPI Study Materials

Here's a simple pipeline command I use all the time, creating a long list of files and piping the output into the Linux more command:

ls -al | more

Here's a pipeline command mashup I use to get a list of all sub-directories in the current directory:

ls -al | grep '^d'

That pipe command works because the grep command only shows the file records that begin with the letter d.

Here's how I list all the processes running on a Unix system that include the string "fred":

ps auxwww | grep fred | more

That helps me find processes that might be owned by a user named "fred".

Read More: LPI Linux Essentials

Here's an example of how I list all the files in my Apache log directory for the month of August in the current year:

ls -al | grep Aug | grep -v '200[456]' | more

I use that grep command to filter out files from the years 2004, 2005, and 2006, as all the log files for several years are currently in one directory.

This ps and wc command pipeline gives you an idea of how many processes are currently running on your system:

ps aux | wc -l

The number returned is actually high by one because the first line of output from the ps command is a header, and not a process.

This command that combines locate and grep helps me find Java files on my computer:

locate "*.java" | grep java

Of course there are many more mashups you can create, just about as many as your imagination allows. I just wanted to show these examples so you'd see how they work.

The basic concept is that you run one command, and then pipe the output from that command into another, and then another, etc. This is formally referred to as piping the "standard output" ("standard out", "STDOUT") from one command to the "standard input" ("standard in", "STDIN") of another command.

Saturday 18 April 2020

Sysvale and LPI: Strategic planning in times of COVID-19

COVID-19, LPI Study Materials, LPI Tutorial and Material, LPI Certification, LPI Prep

When 2019 was just about to end, I got a message from Eugênio Marques, CEO of Sysvale Softgroup, a healthtech that has been collaborating with the Linux Professional Institute (LPI) since its foundation a little more than five years ago. Eugênio asked me to recommend someone who could host their strategic planning sessions and he also invited me to participate in these sessions as they wanted to formalize their Hiring Partner and devise specific actions in this regard.

It's worth noticing even before LPI had the Hiring Partner Program, Sysvale did create their own “Sysvale Certificada” program, promoting certifications among its collaborators and also opening it to the surrounding community, partnering with two major universities in the region, FACAPE and UNIVASF. The company is also well known for its award winning Free Technology Residence program, inspired by the health related residences where soon to be graduating students have the opportunity to learn by doing -- and being paid for this -- for a period varying from six to eighteen months before they are really ready to face the ICT market. Pretty much all of these students end up being hired by Sysvale or creating their own companies.

With the energetic help of Maria Gabriela Gomes Ferreira, the majority of Sysvale Team and myself, representing LPI, we started the strategic planning sessions on January, 6th, 2020. The sessions ended with a public presentation at the event “Sysvale Convida II”, on January 10th, where I talked about ICT careers (There are no quick tricks in the Magic World of ICT was the name of my talk) and Gabriela talked about her ten years journey helping companies to better prepare for their future.

By the end of February, 2020, the planning sessions continued on, now with Luiza Janeri, Agile Coach and OKR Specialist. Again, Luiza provided a talk to the extended community on how to use OKR (Objective and Key Results) metrics to better your personal life.

Then came the Coronavirus …

Being an Agile development company, Sysvale soon launched a solution to help all cities in Brazil to map the status of COVID-19 reach. The Northeastern based health tech assemble a team of developers, administrators, health professionals and public administrators from within and outside of the company to create a tool to provide clear information on the outbreak to the general public and, at the same time, gather individual, voluntary information about their health conditions, allowing health related public servers to take direct action in a very early stage.

COVID-19, LPI Study Materials, LPI Tutorial and Material, LPI Certification, LPI Prep
"The lack of information to the regular citizen is one of the greatest problems we are facing this moment and this is exactly where we have targeted our solution.", says Eugenio Marques, Sysvale's CEO. The solution, LigaSaudável, is totally based on Open Source Software and it is free for every citizen to use. Although it is targeted to Brazilian people and the reality Brazil is facing right now, the solution can readily be used by any Portuguese speaking region and can be easily ported to other languages.

Among several actions planned for 2020 are two open LPI certification events to be produced in partnership with the local academia, a “MeetUp” style, free Linux Essentials Training and the polishing of Sysvale’s DevOps Hello World workshop.

By better preparing its own team and also the surrounding community by using LPI’s certifications, Sysvale will place its feet on the international market in 2020, first within Portuguese speaking areas of the world such as Portugal, Mozambique, East Timor, Macao, Angola and Goa.

Source: lpi.org

Thursday 16 April 2020

Linux Professional Institute DevOps Tools Engineer

DevOps Tools Engineer, LPI Study Materials, LPI Cert Exam, LPI Certifications

Businesses across the globe are increasingly implementing DevOps practices to optimize daily systems administration and software development tasks. As a result, businesses across industries are hiring IT professionals that can effectively apply DevOps to reduce delivery time and improve quality in the development of new software products.

To meet this growing need for qualified professionals, LPI developed the Linux Professional Institute DevOps Tools Engineer certification which verifies the skills needed to use the tools that enhance collaboration in workflows throughout system administration and software development.

In developing the Linux Professional Institute DevOps Tools Engineer certification, LPI reviewed the DevOps tools landscape and defined a set of essential skills when applying DevOps. As such, the certification exam focuses on the practical skills required to work successfully in a DevOps environment – focusing on the skills needed to use the most prominent DevOps tools. The result is a certification that covers the intersection between development and operations, making it relevant for all IT professionals working in the field of DevOps.

DevOps Tools Engineer, LPI Study Materials, LPI Cert Exam, LPI Certifications
Current Version: 1.0 (Exam code 701-100)

Objectives: 701-100

Prerequisites: There are no prerequisites for this certification.

Requirements: Pass the Linux Professional Institute DevOps Tools Engineer exam. The 90-minute exam consists of 60 multiple choice and fill-in-the-blank questions.

Validity Period: 5 years

Cost: Click here for exam pricing in your country.

Languages: English, Japanese

To receive the Linux Professional Institute DevOps Tools Engineer Certification the candidate must:

◉ Have a working knowledge of DevOps-related domains such as Software Engineering and Architecture, Container and Machine Deployment, Configuration Management and Monitoring.

◉ Have proficiency in prominent free and open source utilities such as Docker, Vagrant, Ansible, Puppet, Git, and Jenkins.

Also Read: LPI Certifications

Tuesday 14 April 2020

Best Linux Certifications: RHCE, LPI, CompTIA, Linux Foundation, Oracle - 2020

Linux certifications are highly recommended by many companies as Linux gaining recognition by global platforms these days. These certification programs are gaining popularity among data administrators, system admins, DevOps engineers. It helps IT, professionals, to get knowledge and recognition.

Why Linux Certification?


◈ Most of the hiring manager are looking to recruit Linux professionals.

◈ The emergence of open cloud platforms is creating increasing demand for Linux professionals who have the right expertise

◈ Linux-certified professionals always be a better position in the job market

◈ Employers are looking for more Linux talent.

◈ Better salary increments for Linux certified professionals

Which Linux certification to choose?


There are multiple well-elaborated Linux certification courses available to those professionals who want to recognize and work as a Linux certificate get professional.

Some of the best certification course are given in this article are:

◈ Red Hat Linux SuSE Linux

◈ Linux Professional Institute (LPIC)

◈ CompTIA

◈ Linux Foundation

◈ Oracle

RHCE- Red Hat Certified Engineer


RHCE, LPI, CompTIA, Linux Foundation, Oracle, LPI Study Materials, LPI Tutorials and Materials, LPI Guides

Red Hat Enterprise Linux (RHEL) is a Linux distribution system which is developed by Red Hat. This certification program is targeted toward the commercial market.

Red Hat System Administration certification Study Material are designed for IT professionals who don't have previous Linux system administration experience.

Certification Name Red Hat Certified System Administrator (RHCSA)
Red Hat Certified Architect (RHCA)
Red Hat Certified Engineer (RHCE) 
Prerequisites & Required Courses  Basic technical user skills with handling computer applications and knowledge of some operating systems are expected. 
Exam Duration  5 hours. 
Career Path 
  • Linux system administrators
  • DevOps engineers
  • Cloud administrators 
Cost Per Exam  $400 each ($2,000 total RHCA exam costs) 

Oracle Linux Certification

RHCE, LPI, CompTIA, Linux Foundation, Oracle, LPI Study Materials, LPI Tutorials and Materials, LPI Guides

The Oracle Linux 6 Certified Implementation Specialist Certification course available for those who design, configure and implement Linux 6 solutions.

However, any applicant can complete this certification. It is mostly achieved by Oracle partner implementation professional who has hands-on experience in Linux and previous experience of implementing Linux 6.

Certification Name Oracle Linux 5 and 6 System Administration 
Prerequiesties & Requires Courses  No prerequisites 
Number of Questions  80
Duration  150 minutes 
Format  Multiple questions 
Passing Score   61%
Career Path   Oracle Linux System Administrator 
Cost per Exam   ₹10,475.00 
Validity  5 years 
Recommended Practice 1Z0-100: Oracle Linux 5 and 6 System Administration

LPI Certification Programs


RHCE, LPI, CompTIA, Linux Foundation, Oracle, LPI Study Materials, LPI Tutorials and Materials, LPI Guides

Linux Professional Institute (LPI) found in October 1999. After ten years later and after Linus Torvalds began his pioneering efforts on the Linux kernel. It helps software professionals to enhance their Linux knowledge.

Certification Name LPIC-1: Linux Administrator
LPIC-2: Linux Engineer
LPIC-3: Linux Enterprise Professional
Prerequiesties & Requires Courses 
  • LPIC-1: Fundamental Linux knowledge is required
  • LPIC-2: Candidate must have an active LPIC-1 certification
  • LPIC-3: Active LPIC-2 certification plus completion is one of the 300 series specialty exams
Format Online
Languages English, German, Japanese, Portuguese, Chinese
Passing Criteria Passing exams 101 and 102
Career Path Linux Certified Professional
Cost Per Exam $200
Validity  5 years 
All Practice Exam LPI Certification

CompTIA


RHCE, LPI, CompTIA, Linux Foundation, Oracle, LPI Study Materials, LPI Tutorials and Materials, LPI Guides

CompTIA Linux+ is a Linux certification course that tests the important usage and managerial activities which are common to all Linux distributors.

To get Linux+ certification, you have to clear these two online tests, which are CompTIA Linux Certification LX0-103 and LX0-104. The course content is very similar to the LPIC-1.

Certification Name
CompTIA Linux
Number of Exams
Two exams: LX0-103 and LX0-104
Prerequisites & Required Courses
(LX0-103) - None required
(LX0-104)- Recommended: CompTIA A+ CompTIA Network+ and 1 year of Linux administration experience
Format
Online
Number of Questions
60
Type of Questions
Multiple Choice
Duration
90 minutes
Languages
English, German, Portuguese, Spanish
Passing Criteria
500 (on a scale of 200 to 800)
Career Path 
Network Field Technician
  • Network Support Specialist
  • Network Administrator
  • Network Analyst
  • Technical Support
Cost Per Exam 
LX0-103 -$438 total ($219 per exam)
Validity 
3 Years
Practice Exam

Linux Foundation



The Linux Foundation Certified System Administrator (LFCS) certification. This certification is best suited for those candidates who want to become Linux system admin pursue their career as a Linux administrator.

The exam has a practical course design which allows a candidate to simulate on-the-job tasks and scenarios faced by a professional system administrator. Obtaining this Linux certification course helps them to check their skills.

Certification Name
Linux Foundation Certified System Administrator
Prerequisites & Required Courses
No prerequisites
Duration
2 hours
Exam Format
Online
Languages
English, Spanish, Portuguese, Japanese and German
Passing Score
  • LFCS Exam, a score of 66% or above needed
  • LFCE Exam, a score of 57% or above needed
Career Path
Linux Foundation Certified Engineer
Cost per Exam
$300
Validity
3 Years

Gcux: Giac Certified Unix Security Administrator


The main motive of attaining this certification program is to train professionals for installing, configuring, and monitoring Unix and Linux operating systems. You can get exam dumps online to practice.

Certification Name
GIAC Certification
Prerequisites & Required Courses
None required
Duration
2 hours
Number of Questions
75
Exam Format
Online
Passing Score
68%
Career Path
Not found
Cost Per Exam
$1,899
Validity
Not found

Advantages of Linux Certifications


Here is a prime pros/benefits of using Linux Certification
  • Joining Linux Certification program allows you to access to the official training material that helps you to prepare for the exam.
  • Offers you a chance to work on real-time projects and demonstrate learning hands-on.
  • Helps you to gain concise knowledge of concepts and its applications.
  • Support and guidance from industry experts and certified trainers all over the world
  • Hands-on Practice and lab sessions which help you clear your concepts in the area of application.

Saturday 11 April 2020

fmt command in Linux with examples

fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time consuming when it comes to large text files, this is where fmt comes to rescue.

fmt Command, Linux Tutorial and Material, Linux Learning, Linux Certification, LPI Prep

fmt re formats each paragraph in the file specified, writing to standard output. Here’s the syntax of fmt command:

// syntax of fmt command
$fmt [-WIDTH] [OPTION]... [FILE]...

where, the -WIDTH is an abbreviated firm of –width=DIGITS and OPTION refers to the options compatible with the fmt command and FILE refers to the file name.

If no FILE is specified, or if FILE is a dash(“-“), fmt reads from the standard input.

Using fmt command


fmt by default with no option used format all the words present in the given file in a single line.

$ cat kt.txt
hello
everyone.
Have
a
nice
day.

/* fmt by default puts all words
   in a single line and prints on
   stdout. */
$fmt kt.txt
hello everyone. Have a nice day.

To save or write the formatted output you can use fmt as :

/* Here the formatted output gets
   written in dv.txt */
$fmt kt.txt > dv.txt


Options for fmt command


-w, – -width=WIDTH option : By default, the maximum width is 75 that fmt command produces in output but with the help of -w option it can be changed, it just requires a numerical value for the width you want to specify.

$cat kt.txt
hello everyone. Have a nice day.

/* the width gets reduced to 10
   with -e option */
$fmt -w 10 kt.txt
hello ever
yone. Have
a nice day.

-t, – -tagged-paragraph option : There can be a need for highlighting the very first line in a text file which can be done by making the indentation of first line different from the other lines which can be done with -t command.

$cat kt.txt
hello everyone. Have a nice
and prosperous day.

/*-t makes the indentation
   of first line different
   from others */
$fmt -t kt.txt
hello everyone. Have a nice
   and prosperous day.

-s option : This option split long lines, but don’t refill them.

$cat kt.txt
Love is patient, love is kind. It does not envy,
it does not boast, it is not proud. It is not rude,
it is not self-seeking, it is not easily angered,
it keeps no record of wrongs. Love does not delight
in evil but rejoices with the truth. It always protects,
always trusts, always hopes, always perseveres.
Love never fails.

/* long lines get splited with -s option */
$fmt -s kt.txt
Love is patient, love is kind.
It does not envy, it does not boast, it is not proud.
It is not rude, it is not self-seeking,
it is not easily angered, it keeps no record of wrongs.
Love does not delight in evil but rejoices with the truth.
It always protects, always trusts, always hopes, always perseveres.
Love never fails.

-u, – -uniform-spacing option : This option uses one space between words and two spaces after sentences for formatting.

$cat kt.txt
Love   is   patient,   love is   kind.
    It does   not envy, it   does not boast,
 it is not   proud.

/* Spaces are uniformed with -u option */
$fmt -u kt.txt
Love is patient, love is kind.  It does not envy,
it does not boast, it is not proud.

-c, – -crown-margin option : This option preserves the indentation of the first two lines.
-p, – -prefix=STRING option : This option takes a STRING as an argument and reformat only lines beginning with STRING, reattaching the prefix to reformatted lines.
-g, – -goal=WIDTH option : This option refers to the goal width i.e default of 93% of width.
 – -help option : This display a help message and exit.
 – -version option : This display version information and exit.

Application of fmt command:

fmt lets you format the large text files easily with the options like -u which can be very difficult task if done manually.
fmt also lets you change the default width with the help of -w option.
◈ It is a good way to save time when it comes to format the files.

Thursday 9 April 2020

How to Work Remotely and Securely with FOSS Tools

With the advent of global problems such as Coronavirus (COVID-19) and the need for social distancing to help mitigate the spread of such diseases, many organizations are looking to remote solutions.

LPI Study Materials, LPI Tutorial and Materials, LPI Learning, LPI Exam Prep, LPI Prep

A well-designed disaster recovery plan would already have policies in place for employees to work remotely in times of a crisis. Nonetheless, many companies are finding that they do not have such policies in place. There are likely a variety of reasons as to why an organization would not have a solution ready for employees to work remotely whether they be financial, political, or a lack of understanding of the technologies that are available.

Although office politics do not lend themselves well to easy "one size fits all" solutions, we can address the financial aspect as well as the technologies that are both feasible and accessible. We will take a look at some various solutions that are open source as well as some proprietary applications that are multi-platform to help you stay connected with your coworkers.

Remote Communications


The highest priority for any remote employee is the ability to communicate with their coworkers. Of course, we have had email for decades and practically every email platform supports the ability to send and receive messages from a plethora of desktop and mobile applications, regardless of the operating system or client used thanks to predefined standards such as SMTP, POP, and IMAP (and their secure alternatives).

Nowadays, many organizations are jumping on the Slack bandwagon. Slack is a great tool and very easy to work with, but there are some caveats to its usage. First off, the Slack infrastructure is entirely owned and operated by the company behind the software itself. This means that your organization does not have control over retention or backups of your messages without further costs. There is also an extra cost to the usage of Slack depending on how many messages or the size of the messages that your account consumes.  Neither does your business have control over the security of these messages.

A great alternative to Slack is Mattermost.  Mattermost possesses nearly all of the features that you would find in Slack, as well as the ability to run the client application on any mobile device and it offers a multi-platform desktop application. The extra upside to Mattermost is that it is open source software, and you can host it on your own servers or within Docker containers.  Your organization has complete control over all message retention, backups, security updates and policy controls. For the security-minded company, Mattermost is an excellent choice over Slack.

Zoom is another very popular multi-platform communications application that many organizations depend on for their meetings held via teleconferencing.  As of late there have been some security issues related to how Zoom can leak personal information. There are easy fixes to these as the articles point out, but would it not be better to use an open source application that gives greater preference to security?

This is where promising projects such as Jitsi could be used.  Jitsi is fully open source software, utilizes WebRTC (an internet standard) and end-to-end encryption for all of its calls.  There is no need to register an account with a hosting company, as the server software is available for an organization to install and run on its own.  A caveat to Jitsi is that at this time there are no mobile applications.  Yet given the open source nature of the code and an increase in adoption of Jitsi, such a hurdle could be easily overcome.

Remote Collaboration


The above software packages are a given for remote collaboration, but we now turn our focus to document, calendar and contact sharing.

Many organizations may have access to G Suite and its associated web-based applications.  However, these are hosted and controlled by Google and the business offerings are not free.  Pricing for this platform varies depending on how many users in the organization are going to use the applications and which advanced features a business would need.  As with most software solutions, there is a FOSS alternative.

The flagship platform for such tasks is none other than Nextcloud.  Nextcloud is an extremely versatile, highly scalable and fully open source solution for cloud-based office services.  Nextcloud has recently taken their excellent software to a new level with their Hub offering which allows groups to collaborate together on documents, conduct secure video teleconferencing via its Talk plugin, as well as self-managed groupware capabilities for email, contacts and calendaring.  Much of the functionality that can be found within Google’s G Suite can be duplicated within Nextcloud with its plethora of plugins.  The best part is, your organization controls the data instead of a third party.

The GNOME desktop environment also offers built-in functionality (via Settings>Online Accounts) to connect to multiple Nextcloud instances.  This way you can seamlessly synchronize your calendar, contacts, files and more on your Linux system.  If you do not use the GNOME desktop there are also Nextcloud clients available within distribution package repositories, as well as a flatpak package or a snapcraft package depending on your choice of installation method.

Remote Connectivity


One final topic that we should look at is the ability to connect from your home office back to your business office’s network.  The primary method with which this is done is through a VPN (virtual private network) connection.  VPN solutions are typically maintained by a business’ information technology department and access to a VPN would have to be granted by the IT department. 

Nonetheless NetworkManager, the default networking utility installed on most Linux distributions, has the ability to connect to numerous types of VPN systems.  There is support for OpenVPN, Cisco’s AnyConnect by way of the OpenConnect plugin as well as the vpnc plugin.

If you do not have a VPN solution for your business, there are open source solutions available through projects such as OPNsense and pfSense.  Both of these projects offer full-featured firewall solutions as well as VPN capabilities.  These platforms are built on FreeBSD and offer solid performance and security.  They can both be easily installed on commodity hardware with at least two network interfaces, bringing commercial-grade firewall solutions to your organization.  Should you need extended features and more scalability, these two projects also offer paid enterprise services to implement such functionality.

Once you have connected to your office’s network, you can use applications such as Remmina to connect to Windows, macOS, or Linux workstations and servers.  Remmina makes it easy to organize saved connections should you need to connect to multiple systems.  It can also handle SSH connections for Linux server administrators, making it easy to categorize a number of connection types based on a server's usage (such as production, testing, QA, etc.).

Summing Up


With many stay-at-home orders being issued by various government entities, many people are finding that they still need to find efficient, secure and cost-effective methods for continuing their work.  The FOSS community has been developing remote solutions for a variety of use-cases for years.  Now, more than ever, the efforts of these developers can be appreciated by those who have never had the need to leave their offices before.

Source: lpi.org

Tuesday 7 April 2020

Unix / Linux - File Management

We will discuss in detail about file management in Unix. All data in Unix is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the filesystem.

Linux Tutorial and Material, Linux Learning, Linux Cert Exam, LPI Prep

When you work with Unix, one way or another, you spend most of your time working with files. This post will help you understand how to create and remove files, copy and rename them, create links to them, etc.

In Unix, there are three basic types of files −

◉ Ordinary Files − An ordinary file is a file on the system that contains data, text, or program instructions. In this post, you look at working with ordinary files.

◉ Directories − Directories store both special and ordinary files. For users familiar with Windows or Mac OS, Unix directories are equivalent to folders.

◉ Special Files − Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts and enable you to access a single file using different names.

Listing Files


To list the files and directories stored in the current directory, use the following command −

$ls

Here is the sample output of the above command −

$ls

bin        hosts  lib     res.03
ch07       hw1    pub     test_results
ch07.bak   hw2    res.01  users
docs       hw3    res.02  work

The command ls supports the -l option which would help you to get more information about the listed files −

$ls -l
total 1962188

drwxrwxr-x  2 amrood amrood      4096 Dec 25 09:59 uml
-rw-rw-r--  1 amrood amrood      5341 Dec 25 08:38 uml.jpg
drwxr-xr-x  2 amrood amrood      4096 Feb 15  2006 univ
drwxr-xr-x  2 root   root        4096 Dec  9  2007 urlspedia
-rw-r--r--  1 root   root      276480 Dec  9  2007 urlspedia.tar
drwxr-xr-x  8 root   root        4096 Nov 25  2007 usr
drwxr-xr-x  2    200    300      4096 Nov 25  2007 webthumb-1.01
-rwxr-xr-x  1 root   root        3192 Nov 25  2007 webthumb.php
-rw-rw-r--  1 amrood amrood     20480 Nov 25  2007 webthumb.tar
-rw-rw-r--  1 amrood amrood      5654 Aug  9  2007 yourfile.mid
-rw-rw-r--  1 amrood amrood    166255 Aug  9  2007 yourfile.swf
drwxr-xr-x 11 amrood amrood      4096 May 29  2007 zlib-1.2.3
$

Linux Tutorial and Material, Linux Learning, Linux Cert Exam, LPI Prep
Here is the information about all the listed columns −

◉ First Column − Represents the file type and the permission given on the file. Below is the description of all type of files.

◉ Second Column − Represents the number of memory blocks taken by the file or directory.

◉ Third Column − Represents the owner of the file. This is the Unix user who created this file.

◉ Fourth Column − Represents the group of the owner. Every Unix user will have an associated group.

◉ Fifth Column − Represents the file size in bytes.

◉ Sixth Column − Represents the date and the time when this file was created or modified for the last time.

◉ Seventh Column − Represents the file or the directory name.

In the ls -l listing example, every file line begins with a d, -, or l. These characters indicate the type of the file that's listed.

Sr.No. Prefix & Description
1 -
Regular file, such as an ASCII text file, binary executable, or hard link.
b
Block special file. Block input/output device file such as a physical hard drive.
c
Character special file. Raw input/output device file such as a physical hard drive.
d
Directory file that contains a listing of other files and directories. 
l
Symbolic link file. Links on any regular file.
p
Named pipe. A mechanism for interprocess communications.
s
Socket used for interprocess communication. 

Metacharacters


Metacharacters have a special meaning in Unix. For example, * and ? are metacharacters. We use * to match 0 or more characters, a question mark (?) matches with a single character.

For Example −

$ls ch*.doc

Displays all the files, the names of which start with ch and end with .doc −

ch01-1.doc   ch010.doc  ch02.doc    ch03-2.doc 
ch04-1.doc   ch040.doc  ch05.doc    ch06-2.doc
ch01-2.doc ch02-1.doc c

Here, * works as meta character which matches with any character. If you want to display all the files ending with just .doc, then you can use the following command −

$ls *.doc

Hidden Files


An invisible file is one, the first character of which is the dot or the period character (.). Unix programs (including the shell) use most of these files to store configuration information.

Some common examples of the hidden files include the files −

◉ .profile − The Bourne shell ( sh) initialization script

◉ .kshrc − The Korn shell ( ksh) initialization script

◉ .cshrc − The C shell ( csh) initialization script

◉ .rhosts − The remote shell configuration file

To list the invisible files, specify the -a option to ls −

$ ls -a

.         .profile       docs     lib     test_results
..        .rhosts        hosts    pub     users
.emacs    bin            hw1      res.01  work
.exrc     ch07           hw2      res.02
.kshrc    ch07.bak       hw3      res.03
$

◉ Single dot (.) − This represents the current directory.

◉ Double dot (..) − This represents the parent directory.

Creating Files


You can use the vi editor to create ordinary files on any Unix system. You simply need to give the following command −

$ vi filename

The above command will open a file with the given filename. Now, press the key i to come into the edit mode. Once you are in the edit mode, you can start writing your content in the file as in the following program −

This is unix file....I created it for the first time.....
I'm going to save this content in this file.

Once you are done with the program, follow these steps −

◉ Press the key esc to come out of the edit mode.

◉ Press two keys Shift + ZZ together to come out of the file completely.

You will now have a file created with filename in the current directory.

$ vi filename
$

Editing Files


You can edit an existing file using the vi editor. We will discuss in short how to open an existing file −

$ vi filename

Once the file is opened, you can come in the edit mode by pressing the key i and then you can proceed by editing the file. If you want to move here and there inside a file, then first you need to come out of the edit mode by pressing the key Esc. After this, you can use the following keys to move inside a file −

◉ l key to move to the right side.

◉ h key to move to the left side.

◉ k key to move upside in the file.

◉ j key to move downside in the file.

So using the above keys, you can position your cursor wherever you want to edit. Once you are positioned, then you can use the i key to come in the edit mode. Once you are done with the editing in your file, press Esc and finally two keys Shift + ZZ together to come out of the file completely.

Display Content of a File


You can use the cat command to see the content of a file. Following is a simple example to see the content of the above created file −

$ cat filename
This is unix file....I created it for the first time.....
I'm going to save this content in this file.
$

You can display the line numbers by using the -b option along with the cat command as follows −

$ cat -b filename
1   This is unix file....I created it for the first time.....
2   I'm going to save this content in this file.
$

Counting Words in a File


You can use the wc command to get a count of the total number of lines, words, and characters contained in a file. Following is a simple example to see the information about the file created above −

$ wc filename
2  19 103 filename
$

Here is the detail of all the four columns −

◉ First Column − Represents the total number of lines in the file.

◉ Second Column − Represents the total number of words in the file.

◉ Third Column − Represents the total number of bytes in the file. This is the actual size of the file.

◉ Fourth Column − Represents the file name.

You can give multiple files and get information about those files at a time. Following is simple syntax −

$ wc filename1 filename2 filename3

Copying Files


To make a copy of a file use the cp command. The basic syntax of the command is −

$ cp source_file destination_file

Following is the example to create a copy of the existing file filename.

$ cp filename copyfile
$

You will now find one more file copyfile in your current directory. This file will exactly be the same as the original file filename.

Renaming Files


To change the name of a file, use the mv command. Following is the basic syntax −

$ mv old_file new_file

The following program will rename the existing file filename to newfile.

$ mv filename newfile
$

The mv command will move the existing file completely into the new file. In this case, you will find only newfile in your current directory.

Deleting Files


To delete an existing file, use the rm command. Following is the basic syntax −

$ rm filename

Caution − A file may contain useful information. It is always recommended to be careful while using this Delete command. It is better to use the -i option along with rm command.

Following is the example which shows how to completely remove the existing file filename.

$ rm filename
$

You can remove multiple files at a time with the command given below −

$ rm filename1 filename2 filename3
$

Standard Unix Streams


Under normal circumstances, every Unix program has three streams (files) opened for it when it starts up −

◉ stdin − This is referred to as the standard input and the associated file descriptor is 0. This is also represented as STDIN. The Unix program will read the default input from STDIN.

◉ stdout − This is referred to as the standard output and the associated file descriptor is 1. This is also represented as STDOUT. The Unix program will write the default output at STDOUT

◉ stderr − This is referred to as the standard error and the associated file descriptor is 2. This is also represented as STDERR. The Unix program will write all the error messages at STDERR.