Kuk Linux 2023

Kuk Linux 2023

Kuk Linux 2023

Q6(a) :- Write the commands of vi-editor for deleting character and word, copy single lines and three lines, paste, cursor navigation and save.

The vi Editor:

The vi editor is a powerful and widely-used text editor available on most Unix-like operating systems, including Linux. It is a modal editor, meaning it operates in different modes, each designed for specific types of tasks such as text entry, command execution, and text manipulation. The vi editor is known for its efficiency and is often preferred by experienced programmers and system administrators.

History

  • Origins: The vi editor was originally created by Bill Joy in 1976 for the Unix operating system. It was derived from an earlier editor called ed and its visual mode extension ex.
  • Vim: An enhanced version of vi called Vim (Vi IMproved) was released by Bram Moolenaar in 1991. Vim includes many additional features such as syntax highlighting, extensive plugin support, and better configuration options, while maintaining compatibility with vi.
Below are some essential commands for various operations in vi.

Deleting Characters and Words

  • Delete a single character:
    • x: Deletes the character under the cursor.
  • Delete a single word:
    • dw: Deletes from the cursor position to the end of the word.

Copying Lines

  • Copy a single line:
    • yy or Y: Yanks (copies) the current line.
  • Copy three lines:
    • 3yy: Yanks (copies) three lines starting from the current line.

Pasting

  • Paste the copied text:
    • p: Pastes the copied text after the cursor position.
    • P: Pastes the copied text before the cursor position.

Cursor Navigation

  • Move left:
    • h: Moves the cursor one character to the left.
  • Move right:
    • l: Moves the cursor one character to the right.
  • Move up:
    • k: Moves the cursor one line up.
  • Move down:
    • j: Moves the cursor one line down.
  • Move to the beginning of the line:
    • 0: Moves the cursor to the beginning of the current line.
  • Move to the end of the line:
    • $: Moves the cursor to the end of the current line.
  • Move to the beginning of the file:
    • gg: Moves the cursor to the beginning of the file.
  • Move to the end of the file:
    • G: Moves the cursor to the end of the file.
  • Move to a specific line number:
    • :n: Moves the cursor to line number n.

Saving

  • Save the file:
    • :w: Writes (saves) the file.
  • Save and exit:
    • :wq or ZZ: Writes (saves) the file and exits vi.
  • Exit without saving:
    • :q!: Exits vi without saving changes.

Q6(b) :- Create makefile to execute and delete atleast two .c files.

du and df Commands in Linux

The du (disk usage) and df (disk free) commands are used to display disk usage statistics in Unix-like operating systems. Here’s a detailed explanation of each command, their formats, and usage with examples.

du Command

The du command summarizes disk usage of each file and directory recursively. It provides an estimate of the file space usage.
  • Provides detailed information on disk space used by files and directories.
  • Can display results in a summarized or detailed format.
  • Allows control over depth of directory traversal.
 
Basic Format

du [options] [file|directory]

Common Options and Their Uses

  1. -h: Human-readable format (e.g., 1K, 234M, 2G)

du -h /path/to/directory
  • This command displays the disk usage of the specified directory in a human-readable format.

  • 2. -s: Summarize, display only the total for each argument

du -s /path/to/directory
  • This command provides a summary of the total disk usage of the specified directory.

  • 3. -a: Display disk usage for all files, not just directories

du -a /path/to/directory

  • This command displays the disk usage for all files and directories recursively.

  • 4. --max-depth=N: Limit the output to directories up to a specified depth

du –mx-depth=1 /path/to/directory

This command displays the disk usage of the directory and its immediate subdirectories.

Examples

  1. Display Disk Usage in Human-Readable Format:

du -h /home/user

  • This command displays the disk usage of the /home/user directory in a human-readable format.

  • 2. Summarize Disk Usage:

du -sh /var/log
This command provides a summarized view of the total disk usage of the /var/log directory.

df Command

The df command displays the amount of disk space available on the file system containing each file name argument.
  • Offers a quick overview of disk space availability on file systems.
  • Can display file system types and inode information.
  • Allows filtering by file system type.

Basic Format
df [options] [file]

Common Options and Their Uses

  1. -h: Human-readable format (e.g., 1K, 234M, 2G)

df -h
  • This command displays the disk space usage in a human-readable format for all mounted file systems.

  • 2. -T: Print file system type

df -T
  • This command displays the disk space usage along with the file system type.

  • 3. -i: Inodes information

df -i
  • This command shows the number of inodes used and available on each file system.

  • 4. -t: Limit listing to file systems of a specified type

df -t ext4

This command displays the disk space usage for file systems of type ext4 only.

Examples

Display Disk Space Along with File System Type:

df -Th

This command displays the disk space usage along with the file system type in a human-readable format.

Scroll to Top