{"id":20469056,"url":"https://github.com/ghosts6/optimize_os","last_synced_at":"2026-04-09T12:44:00.763Z","repository":{"id":223462812,"uuid":"760393188","full_name":"Ghosts6/optimize_os","owner":"Ghosts6","description":"c++\u0026python scripts for optimize windows and linux distributions ","archived":false,"fork":false,"pushed_at":"2024-08-28T11:23:54.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T01:49:21.284Z","etag":null,"topics":["apt-get","bash","cpp","linux","python3","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ghosts6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-20T10:37:33.000Z","updated_at":"2024-09-14T07:50:13.000Z","dependencies_parsed_at":"2024-06-16T12:46:22.955Z","dependency_job_id":"9fe0838d-7130-428b-9e42-daf75122bb98","html_url":"https://github.com/Ghosts6/optimize_os","commit_stats":null,"previous_names":["ghosts6/optimize_os"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghosts6%2Foptimize_os","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghosts6%2Foptimize_os/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghosts6%2Foptimize_os/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ghosts6%2Foptimize_os/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ghosts6","download_url":"https://codeload.github.com/Ghosts6/optimize_os/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242031646,"owners_count":20060618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apt-get","bash","cpp","linux","python3","windows"],"created_at":"2024-11-15T14:07:46.307Z","updated_at":"2025-12-30T22:41:20.933Z","avatar_url":"https://github.com/Ghosts6.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"![baner](https://github.com/Ghosts6/Local-website/blob/main/img/Baner.png)\n\n# optimize\n\nInside this repo i place two c++ code and python code to optimize linux and windows os,with help of this files you can optimize your system and make it faster just remind that for using this file you need admin access for windows you need run it as administrator and for linux you need password cuz command run on sudo and for compile codes  you can use this commands 'gpp -o optimize optimize.cpp' or 'g++ -o optimize optimize.cpp' and then you can run it,i also create python code which do same thing for linux but with a bit extra feature\n\n![technology-1283624](https://github.com/Ghosts6/optimize_os/assets/95994481/bdcb655c-64b8-4254-851b-95ca4cfafcde)\n\n\n# 💻windows:\n\nFor windows we use command like sfc ,dism ,del , sconfig and cleanmgr to scan and fix problem and also update os and near them we will remove temp file to optimize system\n```cpp\n#include \u003ccstdlib\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\nusing namespace std;\n\n// Function declarations\nvoid runCommand(const char* command);\nvoid sfcScannow();\nvoid scanHealth();\nvoid checkHealth();\nvoid restoreHealth();\nvoid removeTemp();\nvoid updateOs();\nvoid diskCleanup();\n\nint main() {\n    cout \u003c\u003c \"Running sfc /scannow...\" \u003c\u003c endl;\n    sfcScannow();\n\n    cout \u003c\u003c \"\\nRunning DISM ScanHealth...\" \u003c\u003c endl;\n    scanHealth();\n\n    cout \u003c\u003c \"\\nRunning DISM CheckHealth...\" \u003c\u003c endl;\n    checkHealth();\n\n    cout \u003c\u003c \"\\nRunning DISM RestoreHealth...\" \u003c\u003c endl;\n    restoreHealth();\n\n    cout \u003c\u003c \"\\nRemoving temporary files...\" \u003c\u003c endl;\n    removeTemp();\n\n    cout \u003c\u003c \"\\nUpdating the operating system...\" \u003c\u003c endl;\n    updateOs();\n\n    cout \u003c\u003c \"\\nRunning Disk Cleanup...\" \u003c\u003c endl;\n    diskCleanup();\n\n    cout \u003c\u003c \"\\nFinished optimizing the PC.\" \u003c\u003c endl;\n    return 0;\n}\n\nvoid runCommand(const char* command) {\n    int result = system(command);\n    if (result == 0) {\n        cout \u003c\u003c \"Command executed successfully.\" \u003c\u003c endl;\n    } else {\n        cout \u003c\u003c \"Command execution failed with error code: \" \u003c\u003c result \u003c\u003c endl;\n    }\n}\n\nvoid sfcScannow() {\n    const char* command = \"sfc /scannow\";\n    runCommand(command);\n}\n\nvoid scanHealth() {\n    const char* command = \"dism /Online /Cleanup-Image /ScanHealth\";\n    runCommand(command);\n}\n\nvoid checkHealth() {\n    const char* command = \"dism /Online /Cleanup-Image /CheckHealth\";\n    runCommand(command);\n}\n\nvoid restoreHealth() {\n    const char* command = \"dism /Online /Cleanup-Image /RestoreHealth\";\n    runCommand(command);\n}\n\nvoid removeTemp() {\n    const char* command = \"del /q /f /s %temp%\\*\";\n    runCommand(command);\n}\n\nvoid updateOs() {\n    const char* command = \"sconfig\";\n    runCommand(command);\n}\n\nvoid diskCleanup() {\n    const char* command = \"cleanmgr /sagerun:1\";\n    runCommand(command);\n}\n```\n\n# 🖥️Linux:\n\nHere we have c++ code that i write to optimize linux distribtions include debian ,redhat and arch,inside code we have method to decarle distro and run update command for that distro\n```cpp\n#include \u003ccstdlib\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003csstream\u003e\n\nusing namespace std;\n\n// distribution type\nenum DistributionType {\n    DEBIAN,\n    ARCH,\n    REDHAT,\n    UNKNOWN\n};\n\n// Function declarations\nvoid runCommand(const char* command);\nDistributionType getDistributionType();\n\nint main() {\n    DistributionType targetDistribution = getDistributionType();\n\n    const char* updateCommand;\n    const char* upgradeCommand;\n    const char* autoremoveCommand;\n\n    switch (targetDistribution) {\n        case DEBIAN:\n            updateCommand = \"sudo apt update\";\n            upgradeCommand = \"sudo apt upgrade -y\";\n            autoremoveCommand = \"sudo apt autoremove -y\";\n            break;\n\n        case ARCH:\n            updateCommand = \"sudo pacman -Sy\";\n            upgradeCommand = \"sudo pacman -Syu --noconfirm\";\n            autoremoveCommand = \"sudo pacman -Rns $(pacman -Qtdq) --noconfirm\";\n            break;\n\n        case REDHAT:\n            updateCommand = \"sudo yum update -y\";\n            upgradeCommand = \"sudo yum upgrade -y\";\n            autoremoveCommand = \"sudo yum autoremove -y\";\n            break;\n\n        default:\n            cerr \u003c\u003c \"Unsupported or unidentified distribution\" \u003c\u003c endl;\n            return 1;\n    }\n\n    cout \u003c\u003c \"Updating the system...\" \u003c\u003c endl;\n    runCommand(updateCommand);\n\n    cout \u003c\u003c \"\\nUpgrading the system...\" \u003c\u003c endl;\n    runCommand(upgradeCommand);\n\n    cout \u003c\u003c \"\\nPerforming autoremove...\" \u003c\u003c endl;\n    runCommand(autoremoveCommand);\n\n    cout \u003c\u003c \"\\nFinished updating and optimizing the system.\" \u003c\u003c endl;\n    return 0;\n}\n\nvoid runCommand(const char* command) {\n    int result = system(command);\n    if (result == 0) {\n        cout \u003c\u003c \"Command executed successfully.\" \u003c\u003c endl;\n    } else {\n        cerr \u003c\u003c \"Command execution failed with error code: \" \u003c\u003c result \u003c\u003c endl;\n    }\n}\n\nDistributionType getDistributionType() {\n    const char* lsbReleaseCommand = \"lsb_release -a\";\n    FILE* pipe = popen(lsbReleaseCommand, \"r\");\n\n    if (pipe) {\n        char buffer[128];\n        std::string result = \"\";\n        while (!feof(pipe)) {\n            if (fgets(buffer, 128, pipe) != nullptr)\n                result += buffer;\n        }\n        pclose(pipe);\n\n        // Check if the result contains \"Ubuntu\"\n        if (result.find(\"Ubuntu\") != std::string::npos) {\n            return DEBIAN;\n        }\n\n        // Check if the result contains \"Arch\"\n        if (result.find(\"Arch\") != std::string::npos) {\n            return ARCH;\n        }\n\n        // Check if the result contains \"Red Hat\" or \"CentOS\" or \"Fedora\"\n        if (result.find(\"Red Hat\") != std::string::npos || result.find(\"CentOS\") != std::string::npos || result.find(\"Fedora\") != std::string::npos) {\n            return REDHAT;\n        }\n    }\n\n    return UNKNOWN;\n}\n```\n\n# Optimize.py\n\nthis python code will run update command for linux distribtions just like c++ code but differend is this code also provide log file\nwhich we can access it in same directory and give os data like date,os,kernal and etc  \n```python\nimport subprocess\nimport platform\nimport os\nfrom datetime import datetime\n\ndef run_command(command):\n    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)\n    output, error = process.communicate()\n    return output.decode(), error.decode()\n\ndef system_info():\n    system_info = {\n        \"Date\": str(datetime.now()),\n        \"Platform\": platform.system(),\n        \"Release\": platform.release(),\n        \"Version\": platform.version(),\n        \"Architecture\": platform.architecture(),\n        \"Processor\": platform.processor(),\n    }\n    return system_info\n\ndef log_data(log_data):\n    with open(\"log.txt\", \"a\") as log_file:\n        for key, value in log_data.items():\n            log_file.write(f\"{key}: {value}\\n\")\n        log_file.write(\"\\n\")\n\ndef main():\n    distro_info, _ = run_command(\"lsb_release -a\")\n    print(\"Distro Info:\")\n    print(distro_info)\n\n    system_info = system_info()\n    print(\"\\nSystem Info:\")\n    for key, value in system_info.items():\n        print(f\"{key}: {value}\")\n\n    log_data(system_info)\n\n    distro_info_lower = distro_info.lower()\n    \n    if \"debian\" in distro_info_lower or \"ubuntu\" in distro_info_lower or \"mint\" in distro_info_lower:\n        print(\"\\nRunning commands for Debian-based system:\")\n        run_command(\"sudo apt update \u0026\u0026 sudo apt upgrade -y \u0026\u0026 sudo apt autoremove -y\")\n\n    elif \"redhat\" in distro_info_lower or \"centos\" in distro_info_lower:\n        print(\"\\nRunning commands for Red Hat-based system:\")\n        run_command(\"sudo yum update -y \u0026\u0026 sudo yum upgrade -y \u0026\u0026 sudo yum autoremove -y\")\n\n    elif \"arch\" in distro_info_lower:\n        print(\"\\nRunning commands for Arch Linux:\")\n        run_command(\"sudo pacman -Syu --noconfirm\")\n\n    else:\n        print(\"\\nError,unsupported os.\")\n\nif __name__ == \"__main__\":\n    main()\n\n```\n# Cmd:\n\ni also place folder `cmd/` for my cmd scripts that i wrote them  when i was part of it team and i use them to improve my efficiency at work and its include script like optimize,update and etc \n\noptimize:\n```cmd\n@echo off\n\necho Optimizing and boosting system performance...\necho This may take some time.\n\nREM Clear temporary files\necho Clearing temporary files...\ndel /q \"%temp%\\*\" \u003enul 2\u003e\u00261\necho Temporary files cleared successfully.\n\nREM Run Disk Cleanup\necho Running Disk Cleanup...\ncleanmgr /sagerun:1 \u003enul 2\u003e\u00261\necho Disk Cleanup completed.\n\nREM Run Disk Defragmentation\necho Running Disk Defragmentation...\ndefrag C: /v \u003enul 2\u003e\u00261\necho Disk Defragmentation completed.\n\nREM Run System File Cleanup\necho Running System File Cleanup...\nsfc /scannow \u003enul 2\u003e\u00261\necho System File Cleanup completed.\n\necho System optimization complete.\n\npause\n```\n# 🛠️ Fixing apt \u0026 dpkg:\n\nThis script attempts to fix any issues with apt or dpkg on your system.\nTo use this script:\n1. Make it executable: chmod +x fix-apt-dpkg-issues.sh\n2. Run the script: ./fix-apt-dpkg-issues.sh\n\n```sh\n#!/bin/bash\n\nfix_missing() {\n    echo \"Updating package lists and fixing missing dependencies...\"\n    sudo apt-get update --fix-missing\n}\n\nfix_broken_packages() {\n    echo \"Fixing broken packages...\"\n    sudo apt-get install -f\n}\n\nreconfigure_packages() {\n    echo \"Reconfiguring all packages...\"\n    sudo dpkg --configure -a\n}\n\nclean_package_cache() {\n    echo \"Cleaning up package cache...\"\n    sudo apt-get clean\n}\n\nautoremove_packages() {\n    echo \"Removing unnecessary packages...\"\n    sudo apt-get autoremove\n}\n\nautoclean_package_cache() {\n    echo \"Removing old downloaded package files...\"\n    sudo apt-get autoclean\n}\n\nupdate_and_upgrade() {\n    echo \"Updating and upgrading the system...\"\n    sudo apt-get update \u0026\u0026 sudo apt-get upgrade -y\n}\n\nfix_corrupted_dpkg() {\n    echo \"Attempting to fix corrupted dpkg status...\"\n    sudo mv /var/lib/dpkg/status /var/lib/dpkg/status.old\n    sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status\n}\n\nfix_missing\nfix_broken_packages\nreconfigure_packages\nclean_package_cache\nautoremove_packages\nautoclean_package_cache\nupdate_and_upgrade\nfix_corrupted_dpkg\n\necho \"All tasks completed. Your system should be fixed now!\"\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosts6%2Foptimize_os","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghosts6%2Foptimize_os","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosts6%2Foptimize_os/lists"}