diff --git a/.flake8 b/.flake8 index b80f7f4..1af2286 100644 --- a/.flake8 +++ b/.flake8 @@ -2,7 +2,8 @@ ignore: E402, E501, - E701 + E701, + F401 exclude = .git venv diff --git a/GUIDE.md b/GUIDE.md index 5db60e9..6a8048d 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -39,9 +39,12 @@ for example, `-c` and `-f`, to separate scripts into folders. 4 -c -gtl: gnome terminal profile load 4 -f -bf: bf (backup folder) 4 -f -c: clean (clean system of logs and trash) +4 -f -d: check for duplicate files 4 -f -del: del (delete file or directory) +4 -f -dir: directory size calculator 4 -f -e: exists (check if file or dir exists) 4 -f -ext: check file extensions inside a folder +4 -f -f: check file permissions 4 -f -fd: fd (number of files and folders) 4 -f -fl: file updated 4 -f -fs: file size diff --git a/docs/source/commands.md b/docs/source/commands.md index 97f3474..1b5297d 100644 --- a/docs/source/commands.md +++ b/docs/source/commands.md @@ -39,9 +39,12 @@ for example, `-c` and `-f`, to separate scripts into folders. 4 -c -gtl: gnome terminal profile load 4 -f -bf: bf (backup folder) 4 -f -c: clean (clean system of logs and trash) +4 -f -d: check for duplicate files 4 -f -del: del (delete file or directory) +4 -f -dir: directory size calculator 4 -f -e: exists (check if file or dir exists) 4 -f -ext: check file extensions inside a folder +4 -f -f: check file permissions 4 -f -fd: fd (number of files and folders) 4 -f -fl: file updated 4 -f -fs: file size diff --git a/man/tilux.1 b/man/tilux.1 index 591576e..c77ad01 100644 --- a/man/tilux.1 +++ b/man/tilux.1 @@ -86,15 +86,24 @@ bf (backup folder). .BR 4 " " -f " " -c clean (clean system of logs and trash). .TP +.BR 4 " " -f " " -d +check for duplicate files. +.TP .BR 4 " " -f " " -del del (delete file or directory). .TP +.BR 4 " " -f " " -dir +directory size calculator. +.TP .BR 4 " " -f " " -e exists (check if file or dir exists). .TP .BR 4 " " -f " " -ext check file extensions inside a folder. .TP +.BR 4 " " -f " " -f +check file permissions. +.TP .BR 4 " " -f " " -fd fd (number of files and folders). .TP diff --git a/sys/file_folder/dir_size_calculator.py b/sys/file_folder/dir_size_calculator.py new file mode 100755 index 0000000..b4da37d --- /dev/null +++ b/sys/file_folder/dir_size_calculator.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import os +import sys +import time + + +def calculate_directory_size(directory): + total_size = 0 + for root, dirs, files in os.walk(directory): + for file in files: + file_path = os.path.join(root, file) + if os.path.isfile(file_path): + total_size += os.path.getsize(file_path) + return total_size + + +def main(): + directory = input("Enter the directory to calculate its size (default is current directory): ") or '.' + + if os.path.exists(directory): + print(f"Total directory size: {calculate_directory_size(directory)} bytes") + else: + print(f"{directory} doesn't exist.") + + +if __name__ == '__main__': + if len(sys.argv) == 2: + import tools.catch_exception + from tools.logos import Logo + + Logo('Dir size calculator') + + time.sleep(1) + main() diff --git a/sys/file_folder/duplicate_file.py b/sys/file_folder/duplicate_file.py new file mode 100755 index 0000000..8ad1922 --- /dev/null +++ b/sys/file_folder/duplicate_file.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import os +import sys +import time +import hashlib + + +def find_duplicate_files(directory): + file_hashes = {} + duplicates = [] + + exclude_dirs = [ + '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.github', '.idea', '.mypy_cache', '.tox', '.venv', + '$RECYCLE.BIN', '__pycache__', '_Build', '_Pvt_Extensions', '_UpgradeReport_Files', 'AppData', + 'ClientBin', 'cover', 'coverage', 'develop-eggs', 'dist', 'doc', 'docs/_build', 'docs/build', 'eggs', 'ENV', + 'env', 'env.bak', 'GeneratedArtifacts', 'Generated_Code', 'htmlcov', 'lib64', 'lib/bundler/man', 'local', + 'logs', 'modulesbin', 'node_modules', 'pkg', 'profile_default', 'public', 'publish', 'sdist', 'share/python-wheels', + 'spec/reports', 'target', 'tempbin', 'test/tmp', 'test/version_tmp', 'tmp', 'var', 'vendor/bundle', 'venv', + 'venv.bak' + ] + + for root, dirs, files in os.walk(directory): + for exclude_dir in exclude_dirs: + if exclude_dir in dirs: + dirs.remove(exclude_dir) + for file in files: + file_path = os.path.join(root, file) + with open(file_path, 'rb') as f: + file_hash = hashlib.md5(f.read()).hexdigest() + if file_hash in file_hashes: + duplicates.append((file_path, file_hashes[file_hash])) + else: + file_hashes[file_hash] = file_path + + return duplicates + + +def main(): + directory = input("Enter the directory to search (default is current directory, leave blank for default): ") or '.' + + if not os.path.isdir(directory): + print(f"{directory} doesn't exist.") + return + + duplicate_files = find_duplicate_files(directory) + if duplicate_files: + print("\nDuplicate files found:") + for file1, file2 in duplicate_files: + time.sleep(.2) + print(f"{file1} - {file2}") + else: + print("No duplicate files found.") + + +if __name__ == '__main__': + if len(sys.argv) == 2: + import tools.catch_exception + from tools.logos import Logo + + Logo('Duplicate files') + + time.sleep(1) + main() diff --git a/sys/file_folder/extension_f.py b/sys/file_folder/extension_f.py index 8642e80..833b2c9 100755 --- a/sys/file_folder/extension_f.py +++ b/sys/file_folder/extension_f.py @@ -5,9 +5,9 @@ import time -def check_files_with_extension(directory='.', extension=''): +def check_files_with_extension(directory, extension=''): exclude_dirs = [ - '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.idea', '.mypy_cache', '.tox', '.venv', + '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.github', '.idea', '.mypy_cache', '.tox', '.venv', '$RECYCLE.BIN', '__pycache__', '_Build', '_Pvt_Extensions', '_UpgradeReport_Files', 'AppData', 'ClientBin', 'cover', 'coverage', 'develop-eggs', 'dist', 'doc', 'docs/_build', 'docs/build', 'eggs', 'ENV', 'env', 'env.bak', 'GeneratedArtifacts', 'Generated_Code', 'htmlcov', 'lib64', 'lib/bundler/man', 'local', @@ -16,6 +16,8 @@ def check_files_with_extension(directory='.', extension=''): 'venv.bak' ] + found_extension = False + for root, dirs, files in os.walk(directory): for exclude_dir in exclude_dirs: if exclude_dir in dirs: @@ -24,19 +26,25 @@ def check_files_with_extension(directory='.', extension=''): if file.endswith(extension): file_path = os.path.join(root, file) with open(file_path, 'r'): + found_extension = True print(f"Found file: {file_path}") time.sleep(.2) + if not found_extension: + print(f"Extension '{extension}' files not found.") + def main(): - directory = input("Enter the directory to search (default is current directory): ") + directory = input("Enter the directory to search (default is current directory, leave blank for default): ") or '.' + + if not os.path.isdir(directory): + print(f"{directory} doesn't exist.") + return + extension = input("Enter the file extension to check: ") if len(sys.argv) == 2: ce.__input__(extension) print() - if not directory: - directory = '.' - check_files_with_extension(directory, extension) @@ -45,7 +53,7 @@ def main(): import tools.catch_exception as ce from tools.logos import Logo - Logo('Check file extension') + Logo('File extension') time.sleep(1) main() diff --git a/sys/file_folder/file_permissions.py b/sys/file_folder/file_permissions.py new file mode 100755 index 0000000..f7cc511 --- /dev/null +++ b/sys/file_folder/file_permissions.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import os +import sys +import time + + +def check_file_permissions(directory): + exclude_dirs = [ + '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.github', '.idea', '.mypy_cache', '.tox', '.venv', + '$RECYCLE.BIN', '__pycache__', '_Build', '_Pvt_Extensions', '_UpgradeReport_Files', 'AppData', + 'ClientBin', 'cover', 'coverage', 'develop-eggs', 'dist', 'doc', 'docs/_build', 'docs/build', 'eggs', 'ENV', + 'env', 'env.bak', 'GeneratedArtifacts', 'Generated_Code', 'htmlcov', 'lib64', 'lib/bundler/man', 'local', + 'logs', 'modulesbin', 'node_modules', 'pkg', 'profile_default', 'public', 'publish', 'sdist', 'share/python-wheels', + 'spec/reports', 'target', 'tempbin', 'test/tmp', 'test/version_tmp', 'tmp', 'var', 'vendor/bundle', 'venv', + 'venv.bak' + ] + + for root, dirs, files in os.walk(directory): + for exclude_dir in exclude_dirs: + if exclude_dir in dirs: + dirs.remove(exclude_dir) + for file in files: + file_path = os.path.join(root, file) + permissions = oct(os.stat(file_path).st_mode & 0o777) + time.sleep(.2) + print(f"File: {file_path}, Permissions: {permissions}") + + +def main(): + directory = input("Enter the directory to search (default is current directory, leave blank for default): ") or '.' + + if not os.path.isdir(directory): + print(f"{directory} doesn't exist.") + return + + print() + check_file_permissions(directory) + + +if __name__ == '__main__': + if len(sys.argv) == 2: + import tools.catch_exception + from tools.logos import Logo + + Logo('File permissions') + + time.sleep(1) + main() diff --git a/sys/file_folder/keyword.py b/sys/file_folder/keyword.py index 1eba816..a3f3e97 100755 --- a/sys/file_folder/keyword.py +++ b/sys/file_folder/keyword.py @@ -5,9 +5,9 @@ import time -def find_files_with_keyword(directory='.', keyword=''): +def find_files_with_keyword(directory, keyword=''): exclude_dirs = [ - '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.idea', '.mypy_cache', '.tox', '.venv', + '.bundle', '.cache', '.config', '.eggs', '.env', '.git', '.github', '.idea', '.mypy_cache', '.tox', '.venv', '$RECYCLE.BIN', '__pycache__', '_Build', '_Pvt_Extensions', '_UpgradeReport_Files', 'AppData', 'ClientBin', 'cover', 'coverage', 'develop-eggs', 'dist', 'doc', 'docs/_build', 'docs/build', 'eggs', 'ENV', 'env', 'env.bak', 'GeneratedArtifacts', 'Generated_Code', 'htmlcov', 'lib64', 'lib/bundler/man', 'local', @@ -16,6 +16,8 @@ def find_files_with_keyword(directory='.', keyword=''): 'venv.bak' ] + found_keyword = False + for root, dirs, files in os.walk(directory): for exclude_dir in exclude_dirs: if exclude_dir in dirs: @@ -25,19 +27,25 @@ def find_files_with_keyword(directory='.', keyword=''): with open(file_path, 'r', encoding='utf-8', errors='ignore') as f: file_contents = f.read() if keyword in file_contents: + found_keyword = True print(f"Found keyword '{keyword}' in file: {file_path}") time.sleep(.2) + if not found_keyword: + print(f"Keyword '{keyword}' not found in any files.") + def main(): - directory = input("Enter the directory to search (default is current directory): ") + directory = input("Enter the directory to search (default is current directory, leave blank for default): ") or '.' + + if not os.path.isdir(directory): + print(f"{directory} doesn't exist.") + return + keyword = input("Enter the keyword or phrase to search for: ") if len(sys.argv) == 2: ce.__input__(keyword) print() - if not directory: - directory = '.' - find_files_with_keyword(directory, keyword) @@ -46,7 +54,7 @@ def main(): import tools.catch_exception as ce from tools.logos import Logo - Logo('Files by Keyword') + Logo('Files by keyword') time.sleep(1) main() diff --git a/tools/tilux/command_options.rb b/tools/tilux/command_options.rb index a1b2624..4088710 100755 --- a/tools/tilux/command_options.rb +++ b/tools/tilux/command_options.rb @@ -45,9 +45,12 @@ '-f': { '-bf': -> { TiluxHelpers.sys("bash #{PATH}/sys/file_folder/bf.sh tilux") }, '-c': -> { TiluxHelpers.sys("bash #{PATH}/sys/file_folder/clean.sh tilux") }, + '-d': -> { TiluxHelpers.sys("python3 #{PATH}/sys/file_folder/duplicate_file.py tilux") }, '-del': -> { TiluxHelpers.sys("ruby #{PATH}/sys/file_folder/del.rb tilux") }, + '-dir': -> { TiluxHelpers.sys("python3 #{PATH}/sys/file_folder/dir_size_calculator.py tilux") }, '-e': -> { TiluxHelpers.sys("ruby #{PATH}/sys/file_folder/exists.rb tilux") }, '-ext': -> { TiluxHelpers.sys("python3 #{PATH}/sys/file_folder/extension_f.py tilux") }, + '-f': -> { TiluxHelpers.sys("python3 #{PATH}/sys/file_folder/file_permissions.py tilux") }, '-fd': -> { TiluxHelpers.sys("ruby #{PATH}/sys/file_folder/fd.rb tilux") }, '-fl': -> { TiluxHelpers.sys("ruby #{PATH}/sys/file_folder/file_updated.rb tilux") }, '-fs': lambda do diff --git a/tools/tilux/print_options.rb b/tools/tilux/print_options.rb index ac4557d..11bd1dd 100755 --- a/tools/tilux/print_options.rb +++ b/tools/tilux/print_options.rb @@ -55,9 +55,12 @@ def systemf_print puts '::FF::' puts '-bf: bf (backup folder)' puts '-c: clean (clean system of logs and trash)' + puts '-d: check for duplicate files' puts '-del: del (delete file or directory)' + puts '-dir: directory size calculator' puts '-e: exists (file or directory)' puts '-ext: check file extensions inside a folder' + puts '-f: check file permissions' puts '-fd: fd (number of files and folders)' puts '-fl: file updated' puts '-fs: file size' @@ -128,9 +131,12 @@ def help_print puts '4 -c -gtl: gnome terminal profile load' puts '4 -f -bf: bf (backup folder)' puts '4 -f -c: clean (clean system of logs and trash)' + puts '4 -f -d: check for duplicate files' puts '4 -f -del: del (delete file or directory)' + puts '4 -f -dir: directory size calculator' puts '4 -f -e: exists (check if file or dir exists)' puts '4 -f -ext: check file extensions inside a folder' + puts '4 -f -f: check file permissions' puts '4 -f -fd: fd (number of files and folders)' puts '4 -f -fl: file updated' puts '4 -f -fs: file size'