Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Linux Articles
Page 37 of 134
What is the sed in-place flag that works both on Mac and Linux?
The sed command in Linux stands for stream editor and is mainly used to perform functions on files, such as searching, replacing, or inserting text. It is a very useful command-line utility available on Linux systems. However, there's an important difference between operating systems: the BSD sed shipped with macOS requires a mandatory argument with the -i flag, while GNU sed on Linux makes this argument optional. The Cross-Platform Solution The most reliable way to make sed work identically on both Mac and Linux is to use the -i flag with a backup extension. This approach works ...
Read MoreRedirect Output to location with Permission denied Error?
The Permission denied error when redirecting output to root-owned files is a common issue in Linux systems. When using sudo command > file, the redirection operator (>) runs under the regular user's privileges, not as root, causing permission failures even when the command itself runs with sudo. Understanding the Problem Consider a file that requires root permissions for writing: kent$ ls -l /opt/output.txt -rw-r--r-- 1 root root 0 May 8 10:43 /opt/output.txt When attempting to redirect output as a regular user: kent$ echo "Linux is awesome!" > /opt/output.txt bash: /opt/output.txt: Permission denied ...
Read MoreHow to Reverse a String using Unix Shell Programming?
Bash is a shell or command line interpreter that serves as a programming language for executing commands and scripts. It allows users of Unix-like systems and Windows (via Windows Subsystem for Linux) to control the operating system using text-based commands. In this article, we will solve the problem of reversing a string using Shell scripting. Given a string input, we need to print its reverse using Shell programming techniques. Input : str = "Hello" Output : "olleH" Explanation : Reverse order of string "Hello" is "olleH". Input : str = "yam" Output : "may" ...
Read MoreKill a process running on a specific port?
Killing a process running on a specific port is a common system administration task in Linux. When a service is running on a port you need to free up, or when a process becomes unresponsive, you need to identify and terminate it. This article covers various methods to find processes by port and terminate them safely. Identifying Processes Using Their Ports Before killing a process, you must first identify which process is using a specific port. The netstat command shows active network connections and listening ports: $ netstat -lntp | grep :80 tcp6 0 0 :::80 ...
Read MoreDisplay specific columns of a file in Linux?
In Linux system administration and data processing, displaying specific columns from text files is a fundamental task. Whether you're analyzing log files, processing CSV data, or extracting information from command outputs, knowing how to select and display specific columns efficiently is essential. This tutorial covers various methods to display columns using the awk and cut commands, two powerful text processing tools available in all Linux distributions. Display Single Column Let's start with a sample file containing the output of the ls -l command in long listing format: $ cat input.txt -rw-r--r-- 1 jarvis jarvis 200M ...
Read MoreCompare two directories in Linux?
Comparing directories in Linux is a common task when managing files, troubleshooting issues, or synchronizing data between locations. There are multiple approaches available, from command-line utilities to graphical tools, each offering different levels of detail and functionality. This guide explores various methods to compare two directories in Linux, ranging from basic command-line tools to advanced GUI applications with visual interfaces. Sample Directory Structure For demonstration purposes, let's create two sample directories with similar but not identical contents: Dir1 ...
Read MoreThe "Argument list too long" Error in Linux Commands
The "Argument list too long" error occurs when a Linux command receives more arguments than the system can handle. This happens when shell glob expansion (like *) expands to thousands of filenames, exceeding the kernel's argument buffer limit defined by ARG_MAX. What Causes the Error? When you use wildcards like *, the shell expands them into individual filenames before passing them to the command. If a directory contains many files, this expansion can exceed system limits. $ ls -lrt | wc -l 230086 $ ls -lrt events* | wc -l -bash: /usr/bin/ls: Argument list too ...
Read MoreRemove symbolic links file in Linux?
Symbolic links (also called soft links) are pointers to files or directories located elsewhere in the filesystem. They provide convenient shortcuts for accessing files without duplicating data. This tutorial demonstrates how to properly remove symbolic links in Linux without affecting the original files. Understanding the Setup Let's start with a directory containing files and their symbolic links. Here's our example structure − $ ls -l total 0 drwxr-xr-x 2 kent kent 40 Apr 26 23:48 aDir/ -rw-r--r-- 1 kent kent 0 Apr 26 23:46 aFile.txt lrwxrwxrwx 1 kent kent 4 Apr 26 23:48 dirLink ...
Read MoreRedirect output of process to a file and streams?
Output redirection allows us to send the output of processes to files and standard streams (stdout and stderr) simultaneously. This is essential for logging, debugging, and monitoring system activities in Unix-like operating systems. The tee Command The tee command is a fundamental Linux utility that reads from standard input and writes to both standard output and one or more files simultaneously. It acts like a T-junction in plumbing, splitting the data flow into multiple directions. Redirect stdout Here's a simple example redirecting the output of the ls command to both stdout and a file: ...
Read MoreExclude directories while using grep command?
The grep command is a powerful text searching utility in Linux that allows you to search for specific patterns within files. When performing recursive searches across directory trees, you may want to exclude certain directories to improve performance or avoid searching through irrelevant content such as log directories, cache folders, or version control directories. The --exclude-dir option provides an efficient way to skip specified directories during recursive grep operations, making your searches faster and more targeted. Exclude Single Directory To exclude a single directory from your grep search, use the --exclude-dir option with the -R (recursive) flag. ...
Read More