Friday, April 26, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 3226  / 1 Year ago, tue, november 22, 2022, 9:06:02

I have a folder that has more than 500 videos and the folder's size is about 80 GB.


I want to move 30GB of the videos to another folder, but how?


I'm using terminal and can't install a GUI.


More From » command-line

 Answers
6

Unselectively(automatically)


I don't know of a single command-line tool that can do this ... But, you can use a script to move files until a certain total size has been moved e.g. like this(Run the script only once ... If you run it again it will move the specified size again from the remaining files):


#!/bin/bash

sourc_dir="/path/to/directory" # Set the path to the source directory "no trailing /"
dest_dir="/path/to/directory" # Set the path to the destination directory "no trailing /"
move_size="30" # Set the total size of files to move in Gigabytes

# Don't edit below this line
move_size=$(( move_size * 1000000 ))
current_size=$(du -sk "$sourc_dir" | awk '{printf "%d", $1}')
remaining_size=$(( current_size - move_size ))

for f in "$sourc_dir"/*; do
[ -f "$f" ] || continue
new_size=$(du -sk "$sourc_dir" | awk '{printf "%d", $1}')
(( new_size <= remaining_size )) && exit
mv -n -- "$f" "$dest_dir"/
done

Or even a one-liner(no script-file needed) that you can run in the terminal e.g. like so:


for f in /path/to/source/*; do [ -f "$f" ] || continue; (( size >= (30*(1000**3)) )) && break || (( size += $(stat --printf "%s" "$f") ))  && mv -n -- "$f" /path/to/destination/; done

You might want to unset size to be able to rerun it in the same shell instance.


Selectively(manually)


You can always specify a shell pattern or pipe from a search tool based on filenames, sizes, types ... etc.


Or, more conveniently, you can use a console-based file-manager that supports multiple file selection like e.g. the well known and feature rich GNU Midnight Commander that is available from the Ubuntu official repositories and can be installed like so:


sudo apt install mc

and to run it type mc and hit Enter ... You'll then be presented with a navigable UI where you can use the Insert keyboard key to select multiple files ... You will be able to see the total size of the selected files and their count in real time like so:


enter image description here


Once you have finished selecting all the files you want to move, hit the F6 keyboard key to open the move/rename dialog and enter the destination directory then choose [< OK >] to move the selected files at once like so:


enter image description here


Or even the less known with less features fff (Fucking Fast File-Manager) :-) ... That is interestingly written in bash ... Although it supports multiple file selection, you might need to customize it a bit to be able to see total selected files size e.g. as a quick patch, you can change line 159 in the source fff file from this:


local mark_ui="[${#marked_files[@]}] selected (${file_program
  • }) [p] ->"

  • to this:


    local mark_ui="[${#marked_files[@]}] $(for f in "${marked_files[@]}"; do (( tsize += $(stat --printf "%s" "$f") )); done; tsize=$((tsize/(1000**2))); printf '[%d M]' "$tsize";) selected (${file_program[*]}) [p] ->"

    Then you can simply run that file like so(No installation needed):


    bash fff

    Or view help on usage like so:


    bash fff -h

    Then all you have to do is simply navigate to your source directory and start selecting files to move with the m(lower case) keyboard key like so:


    enter image description here


    When finished selecting files, navigate to the destination directory and move the previously selected files to it by hitting the p(lower case) keyboard key.


    [#43] Thursday, November 24, 2022, 1 Year  [reply] [flag answer]
    Only authorized users can answer the question. Please sign in first, or register a free account.
    jectedrin

    Total Points: 491
    Total Questions: 105
    Total Answers: 111

    Location: Netherlands
    Member since Mon, Jun 7, 2021
    3 Years ago
    ;