Moving Files

Tags: thunar custom action, zenity, YAD, mv, find
November 11, 2015

To learn how to use Thunar Custom Actions click here.

##Move To

This is a handy action which can move any selected files. A window will appear akin to the save to window in browsers. The program Zenity must be installed for this action to work.

mv %f "'zenity --file-selection --directory'"

Under Appears if selection contains make sure everything is checked.

##Move to Subfolder

This is a handy action which can move any selected files to a subfolder. The subfolder is created automatically, being given a name based on the date and time.

NOW=$(date +"%%Y-%%m-%%d-%%H%%M%%S"); mkdir -p %d/$NOW; for file in %N; do mv -n "$file" -t "$NOW"; done

Under Appears if selection contains make sure everything is checked.

##Move To Subfolder with Custom Name

This is a handy action which can move any selected files to a custom named subfolder. A dialog box will pop up, in which a custom name for the subfolder is entered. The program Zenity must be installed for this action to work.

variable=$(zenity --entry --title="Create folder" --text="Name of the folder"); mkdir -p "$variable"; mv -n %F -t "$variable";

Under Appears if selection contains make sure everything is checked.

##Files Into Folders

Divide files in folder into many folders. Customizable by changing number of files. Useful when dealing with a folder with tons of images, making browsing more manageable. In the bash script below change 1000 in [ $c -eq 1000 ] to a custom number based on the amount of files you want divided among subfolders.

/home/$USER/Scripts/movefilesdir.sh %N

Under Appears if selection contains make sure everything is checked.

###Bash Script

I keep my bash scripts in a folder called “Scripts” in my personal directory. To create the bash script copy the script below and paste it into a text editor. Name the script movefilesdir.sh and save it to the scripts folder you created. Make the script executable by opening up a terminal and navigating to the folder in which the script is stored. Type chmod +x movefilesdir.sh and press Enter. The script will now work when used with Thunar Custom Actions.

Bash Script

##Copy to Custom Named Subfolder

This is a handy action which can copy any selected files to a custom named subfolder. A dialog box will pop up, in which a custom name for the subfolder is entered. The program Zenity must be installed for this action to work.

variable=$(zenity --entry --title="Create folder" --text="Name of the folder"); mkdir -p "$variable"; cp -r -n %F -t "$variable";

Under Appears if selection contains make sure everything is checked.

##Move files from subfolders to parent folder

This is a handy action which will move all files out of subfolders into their parent directory. It should be noted that this works on all subfolders. So if you have 10 subfolders and you right-click on one subfolder and choose this Custom Action then all files in all 10 folders will be moved to the parent folder.

find . - mindepth 2 -type f -exec mv "{}" . \; && fin d . - type d -empty -delete

Under Appears if selection contains make sure just Directories is checked.

}