Recent Posts

Featured image for About Bash Profile And Bash.Rc On Mac OS

About Bash Profile And Bash.Rc On Mac OS

The macOS Terminal.app uses a series of scripts and configuration files to set up the shell environment before you see the command prompt. Here’s an overview of these files and how they are executed:

  1. /etc/profile: This is a system-wide configuration file that is executed for all users when they start a new shell session. It sets up environment variables and configurations that are applicable to all users.

  2. /etc/bashrc: This file is also system-wide and is typically sourced (executed) by /etc/profile. It can contain additional configurations and environment variables that apply to all users and all shell sessions.

  3. /etc/bashrc_Apple_Terminal: This is a macOS-specific extension of the /etc/bashrc file. It contains configurations that are specifically intended for Terminal.app.

  4. ~/.bash_profile: This is a user-specific configuration file that is executed when a user logs in. If this file exists, it takes precedence over other configuration files. Users can use this file to set up their own custom environment variables and configurations.

  5. ~/.bash_login: If ~/.bash_profile does not exist, the shell looks for ~/.bash_login and executes it if it’s present. This file is another option for users to customize their shell environment.

  6. ~/.profile: If neither ~/.bash_profile nor ~/.bash_login exists, the shell will use ~/.profile for user-specific configurations.

  7. ~/.bashrc: Users can optionally choose to source (execute) ~/.bashrc from their ~/.bash_profile. This allows them to keep common configurations in ~/.bashrc and have them applied to both login and non-login shell sessions.

Featured image for Moving Files from Google Drive Except Google Drive Files

Moving Files from Google Drive Except Google Drive Files

If you want to move all files from Google Drive except for the ones with specific Google extensions (.gshortcut, .gdoc, .gsheet, .gslides, .gform, .gjam, .gmap, .gsite), you can use the rsync command with the --exclude option to specify the file extensions to be excluded. Additionally, you can exclude common system files like “Icon?” and “.DS_Store” to avoid transferring them. Here’s the command to achieve this:

bash
1
rsync -avP --exclude="*.gshortcut" --exclude="*.gdoc" --exclude="*.gsheet" --exclude="*.gslides" --exclude="*.gform" --exclude="*.gjam" --exclude="*.gmap" --exclude="*.gsite" --exclude="Icon?" --exclude=".DS_Store" --remove-source-files "Google Drive (example@gmail.com)/example/" ./temp

Explanation of the command:

Featured image for Running a Shell Script from Finder and Keeping the Filepath

Running a Shell Script from Finder and Keeping the Filepath

If you’re a macOS user and want to run a shell script by double-clicking it in the Finder, you might encounter an issue with the working directory. By default, the working directory of the script becomes the user’s home directory, which can lead to unexpected behavior if your script relies on relative file paths. To ensure that your script runs with the correct working directory, you can include a specific command at the beginning of your script.

Featured image for Running Selenium on Windows 10 from Ubuntu WSL

Running Selenium on Windows 10 from Ubuntu WSL

If you’re trying to run Selenium with Chrome headless on Ubuntu WSL and encountering issues, an alternative approach is to install the Selenium Standalone Server on your Windows 10 machine and then connect to it remotely from the Ubuntu WSL terminal. This can help you overcome the limitations of running Chrome headless directly within WSL.

Here’s a step-by-step guide on how to achieve this:

Step 1: Set Up Selenium Standalone Server on Windows 10

  1. Install Java: Ensure you have Java installed on your Windows 10 machine since Selenium requires it to run. You can download and install Java from the official website.

  2. Download Selenium Standalone Server: Visit the Selenium Downloads page and download the latest version of the Selenium Standalone Server (selenium-server-standalone-x.xx.x.jar).

  3. Start Selenium Server: Open Command Prompt on Windows and navigate to the directory where you’ve downloaded the Selenium Standalone Server JAR file. Run the following command to start the server:

    bash
    1
    
    java -jar selenium-server-standalone-x.xx.x.jar

    Make sure to replace x.xx.x with the actual version number you’ve downloaded.

Featured image for Resizing a File in Ubuntu by a Specific Size and Removing Lines from the Center

Resizing a File in Ubuntu by a Specific Size and Removing Lines from the Center

To resize a file to a specific size and remove lines from the center of the file in Ubuntu, you can use a combination of commands like truncate and head and tail. Here’s how you can achieve this:

  1. Resize the File to 10MB using truncate:

    To resize a file to a specific size, you can use the truncate command with the --size (-s) option. In this case, we want to resize the file other_vhosts_access.log to 10MB:

    bash
    1
    
    truncate --size 10M other_vhosts_access.log

    This command will resize the file other_vhosts_access.log to exactly 10 megabytes. If the file was larger than 10MB, it will be truncated, and if it was smaller, it will be padded with null bytes.

  2. Remove Lines from the Center of the File:

    To remove lines from the center of a file, you can use a combination of head and tail commands. For example, if you want to remove lines from the center of the file, leaving only the first 1000 lines and the last 1000 lines, you can do the following:

    bash
    1
    2
    3
    
    head -n 1000 other_vhosts_access.log > temp.log
    tail -n 1000 other_vhosts_access.log >> temp.log
    mv temp.log other_vhosts_access.log

    Here’s what each command does:

    • head -n 1000 other_vhosts_access.log: This command extracts the first 1000 lines of the original file and redirects them to a temporary file called temp.log.

    • tail -n 1000 other_vhosts_access.log: This command extracts the last 1000 lines of the original file and appends them to the temp.log file.

    • mv temp.log other_vhosts_access.log: Finally, this command renames temp.log to other_vhosts_access.log, effectively replacing the original file with the modified one.

Featured image for Tracing HTTPS Requests Using mitmproxy

Tracing HTTPS Requests Using mitmproxy

Mitmproxy is a powerful tool that allows you to intercept, modify, and inspect network traffic. It’s commonly used for debugging, security testing, and analyzing HTTP/HTTPS traffic. In this article, we’ll explore how to trace HTTPS requests using mitmproxy, both with a regular proxy and a transparent proxy setup.

Prerequisites

Before you start, make sure you have mitmproxy installed. You can install it using pip: