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
Open Source Articles
Page 59 of 123
Move All Files Including Hidden Files Into Parent Directory in Linux
In Linux, hidden files (also called dotfiles) are files whose names begin with a dot (.) character. These files typically store configuration data or system settings that should be handled carefully. When you need to move all files from a subdirectory to its parent directory, including these hidden files, Linux provides several effective methods. Using the mv Command The mv command is the standard tool for moving files and directories from one location to another. It can also be used to rename files and directories. Moving Visible Files Only To move all visible files from a ...
Read MoreSearch Within Specific File Types Using grep on Linux
The grep command in Linux is a powerful text search utility that allows you to search for specific patterns within files. When working with large directory structures containing various file types, you can combine grep with specific options to search only within files of particular types, making your searches more targeted and efficient. Basic File Type Search with grep To search for a specific pattern within a specific file type, use the --include option with the -r (recursive) flag. This combination allows you to search through directories while filtering by file extension. grep -r 'example' --include='*.txt' ...
Read MoreRead the Source Code of Shell Commands on Linux
Reading the source code of shell commands on Linux helps developers understand how commands work internally and learn system programming techniques. Most Linux commands are compiled binaries, so you cannot simply view their source code with text editors like you would with script files. Understanding Command Types Before searching for source code, it's important to identify the type of command using the type command − type ls type cd type echo This will show whether a command is a binary executable, shell builtin, alias, or function. Only binary executables and scripts have readable source ...
Read MoreWhat Does cd do on Linux
The cd command stands for "change directory" and is used to navigate the file system on a Linux computer. When used with a specific directory path as an argument, cd will change the current working directory to that location. For example, the command cd /home/user/documents will change the current working directory to the "documents" folder located within the "user" folder in the root directory. If you use cd command without any argument it will take you to your home directory. Basic cd Command Usage Here are the most common ways to use the cd command − ...
Read MoreCheck if Directory is Mounted in Bash on Linux
Checking if a directory is mounted is a common system administration task in Linux. There are several reliable methods to determine whether a specific directory serves as a mount point, each with different advantages and use cases. Using the mount Command The mount command is the most traditional method to check mounted filesystems. To check if a specific directory is mounted, combine it with grep − mount | grep "/mnt/data" If the directory is mounted, this returns information about the mount point, filesystem type, and source device. If not mounted, no output is displayed. ...
Read MoreMapping Hostnames with Ports in /etc/hosts
The /etc/hosts file is a simple text file used to map hostnames to IP addresses locally on a system. It provides hostname resolution by bypassing DNS servers, allowing administrators to define custom IP-to-hostname mappings. Each line represents a single mapping with the IP address followed by one or more hostnames separated by spaces. Understanding the Hosts File Structure The hosts file is located at /etc/hosts on Unix-like systems and C:\Windows\System32\drivers\etc\hosts on Windows. It follows a simple format where each line contains an IP address followed by hostnames: 192.168.1.100 myserver.local 127.0.0.1 localhost ::1 localhost When ...
Read MoreNegate an if Condition in a Bash Script in Linux
To negate an if condition in a Bash script in Linux, you can use the ! operator (logical NOT). This operator reverses the truth value of a condition — if the condition would normally be true, negation makes it false, and vice versa. For example, instead of checking if [ $x -eq 5 ], you can use if [ ! $x -eq 5 ] to execute commands when the variable is not equal to 5. Basic Negation Syntax The ! operator is placed inside the test brackets, immediately after the opening bracket: if [ ! condition ...
Read MoreEncrypting and Decrypting Directory in Linux
Directory encryption in Linux provides essential security for protecting sensitive data from unauthorized access. There are several methods available, each with different strengths and use cases. This guide covers the most popular utilities for encrypting and decrypting directories. GPGtar for Archive Encryption GPGtar is a utility that combines tar archiving with GPG encryption, allowing you to encrypt entire directories as compressed archives. It uses GNU Privacy Guard (GPG) to encrypt files within a tar archive, making it ideal for securing large numbers of files at once. Creating an Encrypted Archive To create an encrypted tar archive ...
Read MoreWhen to Use an Alias vs Script vs a New Function in Bash
When working with Bash, it's important to understand the differences between using an alias, a script, and a function. Each has its own unique use case and can be used to accomplish different tasks efficiently. Aliases An alias is a way to create a shortcut for a command or series of commands. They are defined using the alias keyword followed by the desired shortcut and the command it should reference. For example, the following creates an alias for the ls -la command − alias ll='ls -la' This allows the user to type ll instead ...
Read MoreUsing sed With a Literal String Instead of an Input File
The sed (Stream Editor) command is a powerful text processing tool that typically operates on files. However, it can also process literal strings directly without requiring input files. This capability is particularly useful for quick text transformations, scripting, and pipeline operations where you need to manipulate text data on-the-fly. Using the Echo Command with Pipes The most common method to use sed with a literal string is by piping the output of the echo command to sed. This approach allows you to process text directly from the command line. echo "This is an old string" | ...
Read More