Sep
8th

Text-processing utilities in Linux

Text processing is different than word processing. In word processing, text is edited and manipulated in a “What-You-See-Is-What-You-Get” (WYSIWYG) environment. This enables you to produce printed copies of the text, complete with features such as graphics and tables.

Linux stores files in plain-text format. This allows you to use different processing, or filtering, utilities on the text. These utilities let you format, analyze, and manipulate text in many different ways. For example, you can format pages and paragraphs, check spelling, add page numbers and headers, and count the lines, words, and characters that a file contains.

Text-processing utilities

text processing utilities
text processing utilities

The general command syntax used for text-processing commands is

command [option ] filename(s)

Reading files
To work with files, you need to know what information they contain. One way of doing this is to use the cat command to display the contents of a file on your terminal screen. This command provides a number of options.

Options for the cat command

text-processing utilities

Viewer commands
A quicker way of viewing the contents of a file is by using viewer commands, which display the information at the start or end of a file. Examples of viewer commands include head and tail.

By default, the head command displays the first 10 lines of a file, and the tail command displays the last 10 lines of a file. Additional options can be used with these commands to view more specific areas of a file. For example, you can use the -n option with the commands to specify the number of lines they must display.

Pager commands
If a particular file is longer than one screen, it may scroll past too quickly for you to read it. You can scroll through documents at your own pace by using pager commands, which display documents one screen at a time. Examples of pager commands include less and more.

The more command is the original pager command and derives from the Berkeley version of UNIX. It enables you to move through a document in a forward direction only.

The less command was developed to replace the more command and provides a wider range of options for viewing files.

Pager command options

pager command option

Jul
30th

Understanding disk quotas in Linux

After talk about special character on linux command last week, now let understand on disk quota here. In Linux, a system of disk quotas enables the system administrator to restrict disk usage by individuals and groups.

linux

Quotas can specify

  • the maximum amount of total disk space allotted to a user or group
  • The maximum number of files a user or group can create

You assign quotas by partition, so an individual or group who creates files on two partitions may have a different quota for each partition, or a quota for only one of the two partitions.

User and group quotas
User quotas and group quotas are independent of each other – so the value of the group quota is not the sum of the values of the users’ quotas in a group. When a user attempts to create a file, Linux first checks if there is a group quota for the user’s group. If a group quota for the group to which the user belongs has already been filled, the user can’t create the file, regardless of the status of the user’s quota. To create the file, the user must change groups. Every file that an individual user creates counts towards the quota of the user’s group. If the user isn’t part of a quota-restricted group, or if group quotas aren’t switched on for a partition, the user can create files on the partition as long as the user’s quota isn’t filled. (more…)

Jul
16th

Special characters on the Linux command line

Specially defined characters are essential for many of the Linux shell’s powerful features, such as filename completion and command substitution. The shell interprets these characters in a different way from other, regular characters on the command line. However, if you want to disable these characters, you can use a process called quoting.

Filename completion characters

Filename completion characters are metacharacters that enable you to abbreviate filenames or directory names. This saves time and lets you process files selectively, even if you don’t know their full names or locations.

Commonly used filename completion characters are included in the table below.

Filename completion characters
special characters on linux command line

The * character (asterisk) is the most frequently used file completion character. You can use the string b*, for example, to match all the filenames beginning with the letter “b”. You can also use multiple asterisks to define a file. For example, *xx*.gif retrieves any filename that contains “xx” anywhere in its name and that has the .gif extension. (more…)

Jul
9th

Why use the Linux shell?

Most PC users communicate with the operating system on their machines using a graphical user interface (GUI), such as those used in Microsoft Windows 2000 or Mac OS 9. Linux has its own GUIs, most notably GNU Network Object Model Environment (GNOME) and the K Desktop Environment (KDE). GUIs provide buttons, menus, icons, and all the other point-and-click features that have simplified modern computing so greatly. However, it is a mistake to assume that GUIs are always the best way to communicate with an operating system. Although GUIs certainly provide simplicity, they tend to obscure some of a computer’s capabilities from the user. This is where a shell comes in.

linux shell

Advantages of using a shell

Greater control
A shell is a program that acts as an interface between the user and the operating system, just as a GUI does. However, a shell works without graphics – when you use one, you issue instructions to the operating system by typing in commands. In fact, the shell is often referred to as a command interpreter.

This may seem like a return to basic computing, but a command-line interface lets you exercise a degree of control over the operating system that would otherwise be lacking. There are a number of reasons for this: (more…)

Jul
2nd

Mounting Linux file systems

After talking on the Linux File Types in the previous entries, is time to learn the basic on mounting linux file systems. For the data contained on hard disks, disk partitions, network drives, and removable media to be accessed under Linux, it is necessary to attach – or mount – the devices containing the data to the Linux directory structure. The reason for this is that Linux treats every device or partition as a separate and independent file system. It also views all data as though it were in a subdirectory of the root (/) directory, regardless of the kind of device on which it is stored – even when it is kept on a separate computer.

disk drive

It is an important part of the role of the Linux system administrator to ensure that file systems are mounted correctly, whether at boot time or manually, to ensure that all required data is available at the expected locations.

Advantages of mounting Linux file systems and devices

Devices are mounted at predetermined directories below the root file system. These are usually, although not always, special directories created for the purpose. The file systems that belong under the /var, /home, and /usr directories, for example, are kept on separate partitions or devices from the root file system. Network machines are frequently configured so that the /home data for all machines is actually stored on a single Network File System (NFS) server, which is then mounted under the /home directory on each individual machine. This enables users to access their own home directories in the usual locations, regardless of which computers they are actually logged on at. (more…)