Skip to main content

replacefs

Search and replace CLI tool for strings on the all system

The replacefs tool permits to perform massive and controlled string replacements in files over the all file system in an intuitive and pleasant way. You will be able to replace a defined string to another recursively from a path, or locally in a defined path or in a list of files.

Installation

With pip:
sudo pip3 install replacefs

With yay:
yay -a replace

With yaourt:
yaourt -a replace

Compatibility

python >= 3

Usage

replacefs [-h] [-l] [-r] [-s] [-a] [-c]
        [--initial_string INITIAL_STRING]
        [--destination_string DESTINATION_STRING]
        [--directory_path FOLDER_PATH]
        [--file_paths_list FILE_PATH_01 FILE_PATH_02 ...]
        [--filename_must_end_by END_STRING_01 END_STRING_02 ...]
        [--no_ask_confirmation] [--case_insensitive ]
        [--extension_filter] [--all_extensions]
        [--add_excluded_extensions END_STRING_01 END_STRING_02 ...]
        [--add_excluded_strings STRING_01 STRING_02 ...]
        [--excluded_paths EXCLUDED_PATH_01 EXCLUDED_PATH_01 ...]
        [--binary_exclusion] [--binary_accepted]
        [--symlink_exclusion] [--symlink_accepted] [--end_param]
options:
        -h, --help        show this help message and exit
        -l        perform local replacement in FOLDER_PATH. Enabled by default
        -r        perform recursive replacement from FOLDER_PATH
        -s        perform specific replacement on FILE_PATH_01 FILE_PATH_02 given by --list_files_paths_to_apply
        -a, --ask_confirmation, --ask        ask for confirmation to perform replacement at any INITIAL_STRING occurrence. Enabled by default
        -c, --case_sensitive, --case_respect        respect case when searching for occurrences. Enabled by default
        --initial_string, --initial, --init INITIAL_STRING        precise the string to search and replace
        --destination_string, --destination, --dest DESTINATION_STRING        precise the string to replace the INITIAL_STRING strings found
        --directory_path, --dirpath, --path FOLDER_PATH        precise the path of the directory to perform the replacement from
        --file_paths_list, --file_paths FILE_PATH_01 FILE_PATH_02 ...        precise the list of file paths to perform the replacement on
        --filename_must_end_by, --end_by END_STRING_01 END_STRING_02 ...        precise the list of acceptable end string to filter the files regarding their end names
        --no_ask_confirmation, --no_ask        enable no asking mode. Perform replacement without asking confirmation
        --case_insensitive, --no_case_respect        enable case insensitive. Search for INITIAL_STRING string in insensitive case mode
        --extension_filter, --no_all_extensions        enable blacklist extension filter. The blacklist extension owns more than 60 audio, image and video extensions such as "mp3", "jpg" or "mp4". This mode is enabled by default
        --all_extensions, --no_extension_filter        disable blacklist extension filter.
        --add_excluded_extensions, --filter_extensions END_STRING_01 END_STRING_02 ...        precise the unacceptable end strings to filter the files regarding their end names
        --add_excluded_strings, --filter_strings STRING_01 STRING_02 ...        precise the unacceptable strings to filter the files regarding their names
        --excluded_paths EXCLUDED_PATH_01 EXCLUDED_PATH_01        precise the paths to exclude when searching for the INITIAL_STRING in the file system
        --binary_exclusion, --no_binary        refuse binary files. Enabled by default
        --binary_accepted, --no_binary_exclusion, --binary        accept binary files
        --symlink_accepted, --no_symlink_exclusion, --symlink        refuse symlinks. Enabled by default
        --symlink_exclusion, --no_symlink        accept symlinks
        -end_param, --end        precise the end of a parameter enumeration

Examples

for help:

rp -h
or
replacefs --help

local replace "titi" occurrences to "toto" in current directory:

rp -l titi toto .

recursive replace from the child directory "test":

replacefs -r titi toto test

specific replace in the files "test01" "test/test02":

replacefs -s titi toto test01 test/test02

Black list extensions

All the extensions by default in the blacklist:
"mp3", "MP3", "wav", "WAV", "m4a", "M4A", "aac", "AAC", "mp1", "MP1", "mp2", "MP2", "mpg", "MPG", "flac", "FLAC", "jpg", "JPG", "jpeg", "JPEG", "png", "PNG", "tif", "TIF", "gif", "GIF", "bmp", "BMP", "pjpeg", "PJPEG", "mp4", "MP4", "mpeg", "MPEG", "avi", "AVI", "wma", "WMA", "ogg", "OGG", "quicktime", "QUICKTIME", "webm", "WEBM", "mp2t", "MP2T", "flv", "FLV", "mov", "MOV", "webm", "WEBM", "mkv", "MKV", "class", "CLASS"

use --all_extensions or --no_extension_filter to disable blacklist extension filter. use --add_excluded_extensions or --filter_extensions to add some more

Suggestions

Some useful bash functions with replace:

function replace {
#ex:  replace titi toto

	nb_param="$#"

	if [ "$nb_param" -lt 2 ]; then
		echo -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"
	elif [ "$nb_param" -eq 2 ]; then
		rp -l "$@" .
	elif [ "$nb_param" -eq 3 ]; then
		rp -l "$@"
	elif [ "$nb_param" -gt 3 ]; then
		echo -e "$WARNING specific mode replace"
		rp -s "$@"
	fi
}

function rplocal { replace $@; }

function rprecursive {
#ex:  rprecursive titi toto

	nb_param="$#"

	if [ "$nb_param" -lt 2 ]; then
		echo -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"
	elif [ "$nb_param" -eq 2 ]; then
		rp -r "$@" .
	elif [ "$nb_param" -eq 3 ]; then
		rp -r "$@"
	else
		echo -e "\n\t$WARNING at  most 3 arguments ..."
	fi
}

function rpcaseinsensitive {
#ex:  rpcaseinsensitive titi toto

	nb_param="$#"

	if [ "$nb_param" -lt 2 ]; then
		echo -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"
	elif [ "$nb_param" -eq 2 ]; then
		rp --case_insensitive -l "$@" .
	elif [ "$nb_param" -eq 3 ]; then
		rp --case_insensitive -l "$@"
	elif [ "$nb_param" -gt 3 ]; then
		echo -e "$WARNING specific mode replace"
		rp --case_insensitive -s "$@"
	fi
}

function rpcaseinsensitivelocal { rpcaseinsensitive $@ ; }

function rprecursivecaseinsensitive {
	#ex:  rprecursivecaseinsensitive titi toto

		nb_param="$#"

		if [ "$nb_param" -lt 2 ]; then
			echo -e "\n\t$WARNING needs at least 2 strings arguments such as:\n\t\treplace titi toto"
		elif [ "$nb_param" -eq 2 ]; then
			rp --case_insensitive -r "$@" .
		elif [ "$nb_param" -eq 3 ]; then
			rp --case_insensitive -r "$@"
		else
			echo -e "\n\t$WARNING at  most 3 arguments ..."
		fi
}

Release files for replacefs 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for replacefs 1.2.0
File Size Uploaded
replacefs-1.2.0.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for replacefs 1.2.0
File Interpreter ABI Platform
replacefs-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.9 kB

Release files / replacefs-1.2.0.tar.gz

Download URL replacefs-1.2.0.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4bdab2aa1e5cb4adf874cc9b71f8c2328c4006f66ed0e9775ee2cf7b0dced4ae
BLAKE2b-256 checksum
How to use checksums
47f937a23276478f14d8f04c8fd02e2b309faefa7b4a443d69486c1ab4428f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release files / replacefs-1.2.0-py3-none-any.whl

Download URL replacefs-1.2.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
788fb9d3d08a05c0651798614e41248e3f7b9ecdec940d24fd663cafdc4d72a6
BLAKE2b-256 checksum
How to use checksums
239b02ff1e8b549aabc34c7b6256ae045056bd980d3225cb39400502dafdc1c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

1 release file

1.1.0

1 release file

1.0.15

1 release file

1.0.14

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page