WC
WC
WC
•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.
Total no. of lines in both files
• -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.
• -m: Using -m option ‘wc’ command displays count of
characters from a file.
•
head command
• The head command, as the name implies, print the top N number of
data of the given input. By default, it prints the first 10 lines of the
specified files. If more than one file name is provided then data from
each file is preceded by its file name.
Printing first 5 lines
• -v: By using this option, data from the specified file is always
preceded by its file name.
Tail command
• tail -n 3 state.txt
• or
• tail -3 state.txt
• tail +n file_name, data will start printing from line number ‘n’ till the
end of the file specified.
Links
• In UNIX, links are general pointers that point to files and directories.
The primary difference between these links is that a hard link directly
references the file. In contrast, a soft link is a name-based reference to
a file. However, a Hard link links files and directories inside the same
file system, whereas a Soft link may traverse file system boundaries.
• A Hard Link is a copy of the original file that serves as a pointer to the
same file, allowing it to be accessed even if the original file is deleted
or relocated. Unlike soft links, modifications to hard-linked files affect
other files, and the hard link remains active even if the source file is
deleted from the system.
• On UNIX-based systems, a hard link is just another name for a file
that already exists. It's typically found in file systems that allow
various hard links to the same file. Hard links have the same Inode
value, unlike soft links, but they point to the file location rather than
the directory.
Soft link
• A soft link is a short pointer file that links a filename to a pathname.
It's nothing more than a shortcut to the original file, much like the
Windows OS's shortcut option. The soft link serves as a pointer to
another file without the file's actual contents. It allows the users to
delete or the soft links without affecting the original file's contents.
• You may also use soft links to link files across the file system.
Generally, the soft link is an alias for the original file or directory. It
helps to redirect to the specified file and directory when accessed via
the pathname indicated in the soft link's subject.
1.A soft link is a specific pointer that connects the system files. It's extremely similar to
the shortcut feature that is available in Microsoft's Windows operating systems. In
contrast, a hard link differs from a soft link. It acts as a pointer to the original file,
implying that it is an exact mirror duplicate of the original file. It is just another name
for a file that already exists.
2.A hard link is an additional name for the original file that references to the target file
through inode. On the other hand, Soft link is different from the original file and is an
alternative for it, but it does not use inode.
3.A hard link remains valid even if the target file is deleted. On the other hand, a soft link
becomes invalid when the originating file is deleted.
4.In some circumstances, the performance of a hard link outperforms a soft link.
5.The "ln" command is used to make a hard link in Linux. On the other hand, the
command for a soft link is "ln -s".
1.Hard links are faster than soft links. On the other hand, soft links are
slower than hard links.
2.Hard links cannot be established outside the file system. On the other
hand, Soft links can be established across the file system.
3.A hard link may only link to a file, not a directory. On the other hand,
soft links may link both to a file or a directory.
• Hard links. You can think of a hard link as an additional name for an
existing file. Hard links are linking two or more file names with the same
inode . You can only create hard links for directories and files located on the
same filesystem or partition. One file can have one or more hard links.
• Soft links. A symbolic link, also referred to as a soft link, is a type of file that
acts as a reference to another file or directory in the file system. It is
comparable to a shortcut in the Windows operating system, as it allows you
to access a file or directory from a different location without creating a copy
of it. Symbolic links are useful for organizing files, as well as for making it
easier to access frequently used files or directories. Unlike a hard link, a
symbolic link can point to a file or directory on a different partition or
filesystem.
• ln is a command-line utility for creating links between files. By
default, the ln command creates hard links. To create a symbolic link,
use the -s (--symbolic) option.