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
Articles by Pradeep Elance
Page 24 of 32
All possible permutations of N lists in Python
When we have multiple lists and need to combine each element from one list with each element from another list, we're creating what's called a Cartesian product (not permutations). Python provides several approaches to achieve this combination. Using List Comprehension This straightforward approach uses nested list comprehension to create all possible combinations. The outer loop iterates through the first list, while the inner loop iterates through the second list ? Example A = [5, 8] B = [10, 15, 20] print("The given lists:", A, B) combinations = [[m, n] for m in A for ...
Read MoreWhy should eval be avoided in Bash, and what should I use instead?
eval is a built-in Bash command that concatenates its arguments into a single string, joins them with spaces, then executes that string as a bash command. While powerful, eval poses serious security risks and should generally be avoided. How eval Works Let's see a basic example of eval in action − $ var="echo hello" $ echo $var $ eval $var Running the above code gives us the following result − echo hello hello When eval is applied, the variable expands and gets executed as a command, no longer behaving as ...
Read MoreWhat are the calling conventions for UNIX & Linux system calls on i386 and x86-64
A system call is the fundamental interface between an application and the Linux kernel. When a Unix/Linux program does file I/O, network data transfer, or invokes processes that interact with low-level instructions, system calls are involved. Making these calls usually involves using a library called glibc which contains the functions. Common System Calls Below is a list of some frequently used system calls and their purpose ? Sr.No ...
Read MoreLooping through the content of a file in Bash
Reading file contents line by line is a common requirement in Bash scripting. There are several approaches to accomplish this task, each with its own advantages depending on your specific needs. Creating a Sample File First, let's create a sample file to work with ? # Create the file cat > a_file.txt
Read MoreHow to convert DOS/Windows newline (CRLF) to Unix newline (LF) in a Bash script?
When transferring files between Windows and Unix systems, you'll often encounter issues with end-of-line characters. Windows uses CRLF (Carriage Return + Line Feed) while Unix uses LF (Line Feed) only. This guide shows three methods to convert Windows line endings to Unix format using Bash. Understanding the Problem Windows files use \r (CRLF) for line endings, while Unix systems use (LF). When viewing Windows files on Unix, you may see ^M characters at the end of each line. Method 1: Using dos2unix The dos2unix command is specifically designed for this conversion and comes pre-installed on ...
Read MoreLinux WC Command Examples to Count Number of Lines, Words, Characters
The wc command (word count) is a fundamental Linux utility for counting lines, words, characters, and bytes in files. It's commonly used with the -l option for line counting, but offers several other counting options through various arguments. Available Options Option Command Function 1 wc -c Display number of bytes 2 wc -m Display number of characters 3 wc -w Display number of words 4 wc -l Display number of lines 5 wc -L Display length of longest line ...
Read MoreHow to Search and Remove Directories Recursively on Linux?
Removing directories is a regular process for anyone working on Unix systems. But sometimes we also need to find the directories first and then decide to delete them. One hurdle in deleting directories is doing recursive deletion because by default Unix systems do not allow deleting of a directory if it is not empty. In this article we will see how to find and remove directories recursively using two effective methods. Using find and exec The find command with -exec searches for directories and executes the removal command directly. This method is efficient for finding and deleting directories ...
Read MoreHow to Re-run Last Executed Commands in Linux?
Re-running commands in the Linux terminal is a common task that saves time and effort. Linux provides several built-in methods to execute previously run commands without retyping them. Understanding these shortcuts improves productivity when working with the command line. Viewing Command History Before re-executing commands, you can view your command history using the history command. This displays all previously executed commands with line numbers ? history The output shows numbered commands from your session history ? 1 perl -v 2 sudo apt update 3 cal 4 ls -l 5 curl -s https://ipvigilante.com/122.175.62.177 ...
Read MoreHow to Force User to Change Password at Next Login in Linux?
For security purposes, system administrators often need to force users to change their passwords at the next login. Linux provides several commands to manage password expiration and enforce password changes. This article demonstrates how to force a user to update their password on next login. List System Users First, let's view all users available in the system ? cut -d: -f1 /etc/passwd The output shows all system users ? mail news uucp proxy www-data backup list ... ubuntu uname1 Check Current Password Settings Before making changes, examine the current ...
Read MoreHow to Find User Account Info and Login Details in Linux?
For system administrators, monitoring user account information is essential for security and system management. Linux provides several powerful commands to gather details about users, their login history, group memberships, and current activity. id Command The id command displays user and group identification numbers along with group memberships. It shows details for the current user by default, or you can specify a particular user. id id 2112 Running the above commands gives us the following result ? uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu), 4(adm), 24(cdrom), 27(sudo), 30(dip), 46(plugdev), 113(lpadmin), 128(sambashare) uid=2112(uname1) gid=2112(uname1) groups=2112(uname1) The ...
Read More