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 43 of 134
Specify an Editor for Crontab on Linux
The default editor for crontab on Linux is the vi editor. However, this can be changed by setting the VISUAL or EDITOR environment variable to the desired editor before running the crontab command. For example, to use nano as the editor for crontab, the command would be − export VISUAL=nano; crontab -e or export EDITOR=nano; crontab -e This will open the crontab file in nano for editing. Methods to Change Crontab Editor Temporary Change To temporarily change the editor for a single crontab session, set the environment variable inline ...
Read MoreStoring a Command in a Variable in a Shell Script
In shell scripting, you can store a command in a variable to improve code organization and reusability. This technique allows you to define commands once and execute them multiple times throughout your script. Basic Command Storage The basic syntax for storing a command in a variable is − variable_name="command" For example − current_date="date" list_files="ls -la" To execute the stored command, you need to use command substitution or eval − # Using eval (less secure) eval $current_date # Using command substitution (preferred) $($current_date) Storing Commands in ...
Read MoreRunning Script or Command as Another User in Linux
There are several ways to run a script or command as another user in Linux. The most common methods are using the su command (switch user), the sudo command (superuser do), and the runuser command. Each approach has different use cases, security implications, and requirements. These commands are essential for system administration tasks where you need to execute operations with different user privileges without logging out and back in as another user. Using su Command The su command allows you to switch to another user's account. The basic syntax is: su [options] [username] ...
Read MoreRunning Multi-Line Shell Code at Once From Single Prompt
Running multi-line shell code at once allows you to execute complex commands and scripts efficiently without typing each line individually. There are several techniques to accomplish this, from creating shell scripts to using command-line operators and here-documents. Shell Script Method The most common approach is creating a shell script file. Use any text editor to write your code and save it with a .sh extension: #!/bin/bash echo "Hello, World!" echo "This is a shell script." Execute the script using: bash script.sh Here-Document (EOF) Method The here-document technique uses the
Read MoreRemove Lines Which Appear in File B From Another File A in Linux
Removing lines from one file that appear in another file is a common task in Linux system administration and data processing. This operation, also known as set difference, can be accomplished using several command-line utilities, each with its own advantages and use cases. Using the grep Command The grep command is the most straightforward approach for this task. It uses pattern matching to filter lines. grep -v -f fileB.txt fileA.txt > outputFile.txt This command uses the -v option to invert the match (show non-matching lines) and -f to specify the file containing patterns to ...
Read MoreWhat are the fundamental differences between Windows and Linux?
Windows and Linux are two of the most widely used operating systems, each with distinct philosophies, architectures, and target audiences. Understanding their fundamental differences helps users choose the right platform for their needs. Windows Windows is a proprietary operating system developed by Microsoft. It evolved from the Disk Operating System (DOS) and has become the most popular desktop operating system worldwide. Windows is designed with user-friendliness in mind, featuring a graphical user interface that requires minimal technical knowledge to operate effectively. Modern Windows versions are standalone operating systems that no longer require DOS as a foundation, though ...
Read MoreHow to create a process in Linux?
A process is a program loaded into memory and currently executing. In simple terms, a process is a program in execution state that the operating system manages and schedules for CPU time. Creating Processes with fork() System Call In Linux, a new process is created using the fork() system call. This system call creates a new process by making an exact copy of the calling process's address space. The original process becomes the parent process, while the newly created process becomes the child process. When fork() is called, both parent and child processes continue execution from the ...
Read MoreInit process on UNIX and Linux systems
The Init process is the parent of all processes in UNIX and Linux systems, executed by the kernel during system boot. Its primary role is to create processes from configuration stored in /etc/inittab. Init spawns getty processes on terminal lines for user logins and controls all autonomous system processes required for proper operation. After reading /etc/inittab, init determines how the system should be configured for each runlevel and sets the default runlevel. Init then starts all background processes after establishing the system's operational state. Process Hierarchy Process Tree Structure ...
Read MoreLinux Process Monitoring
In Linux, the top command is a powerful utility used to monitor running processes in real-time. It displays an ordered list of active processes and updates regularly, showing critical system information like CPU usage, memory consumption, swap memory, cache size, buffer size, process IDs (PIDs), users, and commands. This tool is essential for system administrators to identify processes consuming high memory and CPU resources. How Top Command Works The top command provides a dynamic view of the system's running processes. It refreshes every few seconds by default and sorts processes by CPU usage, with the most resource-intensive processes ...
Read MoreWhat's the difference between a context switch, a process switch and a thread switch in Linux?
Context switching is the fundamental mechanism that allows a multitasking operating system to share a single CPU among multiple processes and threads. It involves storing the current execution state so that it can be restored later, enabling seamless resumption from the same point. Types of Context Switches There are three main types of context switches in Linux, each with different overhead costs and complexity levels. Context Switch (General) A context switch is the general term for saving the current execution state (registers, program counter, stack pointer) of a running task and loading the state of another ...
Read More