Skip to content

Instantly share code, notes, and snippets.

@StudioEtrange
Last active November 6, 2025 10:28
Show Gist options
  • Select an option

  • Save StudioEtrange/175755cb5d469f380fc5a041692e7b21 to your computer and use it in GitHub Desktop.

Select an option

Save StudioEtrange/175755cb5d469f380fc5a041692e7b21 to your computer and use it in GitHub Desktop.
Various files and folders manipulation

Various files and folders manipulation tips

Various files and folders manipulation

Flat folder content

move all files, folder and subfiles of a root folder inside this root folder in a flatten way

Move files outside its folder

  • windows :

    cd /D X:\FOLDER
    for /D %A in ("*") do @for %B in ("%~fA"\*.*) do move /y "%B" "%~dpB..\"
    

Move files inside its own folder

  • linux :

    cd /FOLDER
    for f in *; do mkdir "${f%.*}"; mv "$f" "${f%.*}"; done
    

Delete empty folders

  • windows :

    set "FOLDER=X:\FOLDER"
    for /r "%FOLDER%" /d %F in (.) do @dir /b "%F" | findstr "^" >nul || echo %~fF && rmdir /Q "%~fF"
    

linux : list top files and folders

list top 10 biggest files into a folder and subfolders

folder="/"
find "${folder:-/}" -type f -exec du -Sh {} + 2>/dev/null | sort -rh | head -n 10

list top 10 biggest folders of a folder

folder="/"
du -Sh "${folder:-/}" 2>/dev/null | sort -rh | head -10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment