Unix/Linux Commands and Vi Editor Guide
Unix/Linux Commands and Vi Editor Guide
In vi Command Mode, keyboard shortcuts facilitate navigation without modifying text. Examples include 'K' to move up a line, 'J' to move down, 'H' for left, and 'L' for right. These shortcuts allow efficient line and character jumping, enhancing quick navigation across a document, which is crucial for examining text structure or making fast edits .
Concatenating files using the 'cat' command involves listing file names in sequence, for example, 'cat file1.txt file2.txt > combined.txt'. This process merges content from multiple files into a single output, allowing for streamlined data handling. The significance lies in simplifying file management by consolidating information, facilitating easier data processing and storage .
The 'expr' command performs arithmetic operations on integers, including addition, subtraction, multiplication, division, and finding remainders. It's typically used for simple calculations in shell scripts or command-line interfaces where numerical processing of input data is required. For instance, 'expr 5 + 3' yields an output of 8 .
The `who` command displays the users currently logged into the system, showing details such as login name, terminal, and login time. In contrast, the `whoami` command specifically returns the current user's name, identifying the identity under which the current session is running. This difference highlights `who` as a tool for system-wide user information, while `whoami` focuses on the individual user's identity .
To print specific columns using `awk`, the command 'awk \'{print $N}\' filename.txt' is used, where N is the column number you want to print. For instance, 'awk \{print $1,$3\}' filename.txt' prints the first and third columns. This involves specifying the column numbers directly within the print action of the `awk` command, which processes the input file line by line .
The 'grep -w' option enhances search capabilities by ensuring that only exact matches of the keyword are returned, distinguishing between whole word patterns from similar sequences within words. This option is particularly useful in scenarios where partial matches could lead to false positives, such as searching for the word 'cat' without returning lines containing 'catalog' .
The 'awk' command prints lines containing a specific pattern using syntax like 'awk '/pattern/' filename.txt'. This approach filters input lines and outputs those matching the pattern. By embedding regex patterns, 'awk' becomes a powerful tool for selective data extraction, useful for analyzing specific data points within large datasets .
In Command Mode, vi interprets inputs as commands, allowing the user to navigate or modify text, but not enter it. Pressing '[Esc]' enters Command Mode. Insert Mode allows for text input and is activated by typing 'i'. Exiting Insert Mode requires pressing the '[Esc]' key, placing the user back in Command Mode. These modes affect text editing by providing distinct functional roles, with Command Mode handling navigation and commands, while Insert Mode handles text entry .
The 'grep' command enhances search capabilities through options like '-i' for case insensitivity, '-v' for inverting matches, and '-c' for counting occurrences. For example, using 'grep -i "Keyword" filename.txt' makes the search case insensitive, finding 'keyword' and 'Keyword'. 'grep -v "Keyword" filename.txt' reverses the search to show lines not containing 'Keyword'. 'grep -c "Keyword" filename.txt' counts how many times 'Keyword' appears .
The 'pwd' command outputs the full path of the current working directory, serving as a navigation point identifier within the file system. Its importance stems from providing users with essential location information, which aids in accurate navigation and file management, ensuring that commands are run in the correct directory context .