Mukul Latiyan

Mukul Latiyan

363 Articles Published

Articles by Mukul Latiyan

Page 9 of 37

How to find the most recent file in a directory on Linux?

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

The Linux find command is one of the most widely used utilities that allows us to traverse a file hierarchy. It is primarily used to locate specific files or directories, and we can combine it with other Linux commands or flags to perform complex operations. Let's explore a basic example of the find command to understand how it works. In the example below, I am searching for a file named sample.sh using the find command: find sample.sh Output sample.sh Notice that if the find command locates the file, it prints ...

Read More

How to free Inode usage on Linux?

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

The inode (also known as index node) is a data structure that stores metadata about files and directories in Linux file systems. Each file or directory uses one inode, which contains information like permissions, ownership, timestamps, and pointers to data blocks. When inodes are exhausted, you cannot create new files even if disk space is available. Checking Inode Usage You can check the inode usage on your system using the df command with the -i option − df -i This displays inode information for all mounted filesystems − Filesystem ...

Read More

How to get Linux console window width in Python?

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

In order to get the width and height of the Linux console in Python, there are different modules available that we can make use of. Two of them are the os module and the subprocess module. In the case of the os module, we make use of the popen() method that is used to open a pipe to and from command which will help in retrieving the width and height of the Linux window. Using os.popen() Method Consider the code for the same shown below − import os rowSize, columnSize = os.popen('stty size', 'r').read().split() ...

Read More

How to get only the file name using find command on Linux?

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

The Linux find command is one of the most widely used utilities that allows us to traverse a file hierarchy. It is primarily used to locate specific files or directories, and we can combine it with various flags and options to perform complex operations. Let's explore a basic example of the find command to understand how it works. In the example below, we are searching for a specific file named sample.sh in the current directory: find sample.sh Output sample.sh If the find command locates the file, it prints the file ...

Read More

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
Showing 81–90 of 363 articles
« Prev 1 7 8 9 10 11 37 Next »
Advertisements