Operating System Articles

Page 85 of 171

How to get the last dirname/filename in a file path argument in Bash?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 1K+ Views

Working with file paths is a common task in Bash scripting, and extracting the last component (filename) or parent directory name from a path is frequently needed. Bash provides several utilities to manipulate file paths effectively, with basename and dirname being the most commonly used commands. Getting the Last Filename with basename The basename command extracts the final component from a file path, removing all preceding directory components. This is useful when you need just the filename from a complete path. Basic Usage basename /path/to/file.txt file.txt Working with Environment Variables ...

Read More

How to get the start time of a long running Linux Process?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 1K+ Views

Whenever we want to get an update about a specific process or different processes, we make use of the ps command which is short for "Process Status". This command tells us about the state of current processes, their characteristics, and much more. When combined with several flags and options, we can enhance the ps command to output the start time of different processes running on a Linux machine. This is particularly useful for monitoring long-running processes and system diagnostics. Basic Commands to Display Process Start Time The command to print the start time of processes varies slightly ...

Read More

How to grep a string in a directory and all its subdirectories in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 4K+ Views

The grep command in Linux is used to search for specific patterns or strings within files. It is one of the most essential Linux utilities for filtering and finding text content across files and directories. The pattern we search for is typically called a regular expression, and grep can search through single files, multiple files, or entire directory structures. Basic Syntax grep [options] pattern [files] Common Options Option Description -r or -R Search recursively through directories and subdirectories -n Display line numbers with matched ...

Read More

How to grep and replace a word in a file on Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 4K+ Views

While there are plenty of ways to print and make use of specific words from a particular file in a Linux directory, when we talk about grepping a particular word and then replacing it with some other word, we need to use specific Linux utility commands. The two Linux utility commands that we must be aware of are − find − used to locate a particular file or directory sed − short for stream editor and is used to perform functions like searching, editing and replacing Basic Grep and Replace Operation To solve the ...

Read More

How to grep multiline search patterns in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 2K+ Views

In Linux, searching for multiline patterns requires special techniques beyond the basic grep command. While grep is designed primarily for single-line pattern matching, we can use various approaches and tools to search across multiple lines effectively. The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It displays lines that contain the pattern we are trying to search, where the pattern is referred to as a regular expression. Basic Grep Syntax grep [options] pattern [files] Common options include − -c : Count of ...

Read More

How to grep string without filenames in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 6K+ Views

The grep command is a powerful tool for searching patterns in files. By default, when searching multiple files, grep displays the filename along with each matching line. However, sometimes you only want to see the matching lines without the filenames cluttering the output. Let's see a simple example where we grep a pattern in multiple files in a directory. Default grep Behavior with Multiple Files grep -i 'lp' Sample* Sample: The sample was printed via the internet. Sample: I believe lp cares about what the device is. Sample1: This was printed via the ...

Read More

How to insert a text at the beginning of a file in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 3K+ Views

In Linux, there are several ways to insert text at the beginning of a file. The most common and efficient method uses the sed command, which stands for stream editor. This command performs various operations like find, replace, insert, and delete on files without opening them in an editor. Using the sed Command The sed command can modify files in-place using the -i flag, making it perfect for inserting text at the beginning of files. Let's explore this with a practical example. Example Setup Consider a directory d1 containing text files. First, let's check the directory ...

Read More

How to install the latest version of Git on CentOS 7.x/6.x?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 943 Views

Installing the latest version of Git on CentOS can be accomplished through multiple approaches. CentOS repositories often contain older versions of Git, so these methods help you install more recent versions with enhanced features and security updates. Approach 1: Using IUS Community Repository The IUS Community Repository provides updated packages for Enterprise Linux distributions. This is the most straightforward method for getting a recent Git version. Commands yum install epel-release yum remove git rpm -U https://centos7.iuscommunity.org/ius-release.rpm yum install git2u git --version Output immukul@192 lib % git --version git version 2.29.2 ...

Read More

How to invert a grep expression on Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 12K+ Views

The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display the lines that contain the pattern that we are trying to search. To invert a grep expression means to display all lines that do NOT match the specified pattern, which is accomplished using the -v option. Basic Grep Syntax grep [options] pattern [files] Common Grep Options -c : Lists only a count of the lines that match a pattern -h : Displays ...

Read More

How to iterate over a list of files with spaces in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 17-Mar-2026 559 Views

In order to iterate over a list of files we will need to make use of the find command that Linux provides us with. When dealing with filenames containing spaces, special handling is required to avoid issues with word splitting. Linux find statement is one of the most widely used commands that allows us to walk a file hierarchy. It is used to find specific files or directories and we can append different flags and options to enhance functionality or perform complex operations. Basic Find Command Example Let's start with a simple example of the find statement: ...

Read More
Showing 841–850 of 1,707 articles
« Prev 1 83 84 85 86 87 171 Next »
Advertisements