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
Copy a directory to an existing directory Linux?
Copying directories is one of the most common operations in Linux system administration. The cp command is typically used for this purpose, but copying a directory into an existing directory requires specific techniques to handle content merging properly. This article explores different methods to recursively copy directory contents into an existing target directory, both with and without overwriting existing files. Understanding the Problem When copying a directory to an existing directory, we need to distinguish between two scenarios: Copying directory contents − Merge files from source into target Copying the entire directory − Create a ...
Read MoreUse ./ (Dot Slash) to execute script file?
In Linux, ./ (dot slash) is used to execute script files located in the current directory. The dot (.) represents the current working directory, and the forward slash (/) is the path separator, so ./script.sh tells the shell to run the script from the current location. What Does Dot Slash Mean? The dot (.) in Linux represents the current working directory. When combined with the forward slash (/), it creates a relative path that points to files in your current location. For example: $ ls -l -rwxr-xr-x 1 user1 user1 156 Jun 12 19:09 script.sh -rw-r--r-- ...
Read MoreWhat 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 More