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 38 of 134
How to use tmux on Linux?
Tmux is a terminal multiplexing utility for Unix systems that provides an interface between several programs running simultaneously on one computer. It allows users to detach from terminal sessions without killing them and reattach later, making it invaluable for remote work and long-running tasks. Tmux operates through sessions, windows, and panes — sessions contain multiple windows, and windows can be split into multiple panes. All commands use a prefix key (default: Ctrl-b) followed by another key. Installation Install tmux on Debian-based Linux systems using the apt package manager − sudo apt-get update sudo apt-get install ...
Read MoreLoad Environment Variables in a Cron Job
When crontab runs a command, it doesn't read any environment variables from files like ~/.bashrc, ~/.bash_profile, etc. Because cron runs tasks from a non-interactive, non-login shell, it operates with a minimal environment. Some applications require specific environment variables to function correctly, making it necessary to load them explicitly in cron jobs. This article explores different methods for loading environment variables in crontab to ensure your scheduled tasks have access to the required configuration. Setting the BASH_ENV Variable We can set environment variables for shell scripts by using the BASH_ENV variable. When BASH_ENV is set, bash executes the ...
Read MoreMove all files except one on Linux
When working with Linux, you may need to move multiple files from one directory to another while keeping specific files in their original location. This is a common task for file organization, cleanup operations, or selective backups. Linux provides several methods to accomplish this using different command-line approaches. Renaming The Unwanted File This method involves temporarily renaming the file you want to keep by adding a dot prefix, making it a hidden file. The mv command with wildcards will ignore hidden files, allowing you to move everything else. # Rename the file to keep as hidden ...
Read MoreChange the Install directory with make install
When building software packages from source, you often need to control where the compiled software gets installed. By default, packages are typically installed in standard system directories like /usr or /usr/local. However, you might want to install to a custom location for testing, creating packages, or installing software for a single user without requiring root privileges. Using ./configure Parameters Most modern software packages use autotools (autoconf/automake) which provides a ./configure script with standardized parameters for controlling installation directories. Common Configure Parameters --prefix= − Base directory for installation (default: /usr or /usr/local) --bindir= − Directory for ...
Read MoreExtracting a substring using Linux bash
Extracting a substring from a string is a fundamental text processing operation in Linux. This involves isolating specific portions of text based on character positions (index-based) or patterns (delimiter-based). We'll explore different methods to extract substrings from strings using the Linux command line, covering both index-based and pattern-based approaches. Index-Based Substring Extraction Index-based extraction involves specifying the starting position and length of the desired substring. Here are four common methods: Using the cut Command The cut command extracts characters from position N to position M using the -c option. Note that cut uses 1-based indexing. ...
Read MoreHow to add a Column of Numbers in Bash?
Bash provides several methods to add up numeric columns in data files. This article explores different approaches including awk, loops, and text processing commands, comparing their performance on column summation tasks. Using the awk Tool The awk command is the most straightforward approach for column arithmetic. It reads each line, accumulates values, and displays the final sum. $ awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv Total is: 49471228 To measure performance, use the time command: $ time awk '{Total=Total+$1} END{print "Total is: " Total}' numbers.csv ...
Read MoreHttps connection using curl on Linux
curl is a versatile command-line tool that supports various protocols including HTTPS for secure web connections. It enables users to transfer data from or to servers and is commonly used for connecting to web servers and retrieving data. This tutorial covers how to use curl to make secure HTTPS connections and handle SSL/TLS certificates properly. What is Curl? Curl is a command-line tool that allows users to transfer data from or to a server using various protocols, including HTTP, HTTPS, FTP, and more. It supports many different types of websites and can be used to connect to any ...
Read MoreCreate a file of certain size in Linux
When using Linux, we often need to create files of specific sizes for testing, development, or system administration tasks. This is particularly useful for testing disk space, creating dummy files for benchmarking, or generating placeholder files of predetermined sizes. There are several efficient methods to achieve this using built-in Linux commands. Each method has its own advantages depending on the specific use case and performance requirements. Available Methods Linux provides multiple utilities for creating files of specific sizes, each with distinct characteristics: Command Speed File Content Best Use Case ...
Read MoreKilling all members of a process group in Linux
As a Linux system administrator, dealing with processes is a frequent task. Generally, they're easy to stop, however in certain cases − when there are large numbers of processes within the same groups − additional steps might be needed. We'll take a closer look at how to manage processes using the concept of process groups and how to terminate all processes that belong to one particular group efficiently. Process Groups A process group in Linux is a collection of related processes that share the same Process Group ID (PGID). Each process group has one group leader whose ...
Read MoreAborting a shell script on any command fails
By utilizing Bash scripts, we can have access to a powerful programming language. Writing such scripts is an efficient way to run several commands one after the other. However, by default, even if one command fails, the others will still be executed, which can lead to unexpected behavior or data corruption. We'll learn how we can add some safeguards so that these errors don't happen. The example code has been tested in Bash and should also work for other POSIX-compatible shell environments. The Problem Let's first take a look at how Bash handles error messages by default. ...
Read More