🔍 See Original Answer on Ask Ubuntu 🔗
Selecting files from different folders
April 18, 2017
November 24, 2022
Copy to clipboard: false
This is a work in progress answer divided into two posts.
bafman (Born Again File Manager) was developed this past long weekend (April 14-17, 2017). It is still a work in progress but it will satisfy requirement to select files across many sub-directories.
This is ideal in situations where you want to copy files in a project without doing a full system backup. There are other applications such as tagging every system configuration file you’ve modified across dozens of different directories.
I’m posting this WIP in hopes of generating interest and gathering suggestions for additional features as I finish bash coding. Yes it’s all written in bash (to the shock of many perhaps) and relies on YAD (Yet Another Dialog) for all the GUI.
Table of Contents
- bafman Begins
- Initial data creation
Update Dirsbutton - generate file statistics for all directories
Hide Dirbutton - remove directory from bafman list
Edit commentsbutton - enter comments for any directory.
Add Dirbutton - Add directory to bafman list
Tag filesbutton - Select the files which will be used by Run command
Initial data creation
When you invoke bafman for the first time this screen appears after a few moments:
This is the main screen. You can click on any column heading to sort in ascending then descending order. You can grab the column divider and move it to adjust column width.
The list of directories is cut down from > 20,000 (the bafman limit) using this command:
tree --noreport -danifI "src*|dev|lib|media|mnt|proc|root|run|sys|tmp|tmpfs|var|usr" / > "$bafmanTemp"
If you are a programmer you might want to see all the “src*” directories and would remove this from the code.
Notice the file counts and sizes are all zero in our display. That is remedied in the next section.
Update Dirs button - generate file statistics for all directories
When you click on the
Update Dirs button you are greeted with this initial warning:
10,000 directories is an extraordinary situation if for example you add the
/usr directory and
/var directory to bafman list. In our example we have 2,365 directories and it takes about 5 minutes to scan all files in them.
While scanning all files in all directories this progress screen appears:
When all is said and done the main screen is updated like this:
Once again it’s important to note you can click on “File Sizes” column to sort on ascending order (smallest on top) and click again for descending order (directories with largest file sizes on top).
Search on directory name is possible by simply typing the directory you want to advance to. For example type
/etc/default and the screen scrolls to that directory.
Hide Dir button - remove directory from bafman list
I noticed I have a directory called
/cdrom2 which I forgot I created during testing the “fake” directory
/cdrom (which you MUST KEEP). So let’s remove
/cdrom2 from the bafman list by clicking the
Hide Dir button:
/cdrom2 has already been removed from the drive so the Modified and Owner fields display as Deleted. These and other fields on this screen are described under the Edit comments section.
For the time-being select the
OK button to hide the sub-directory and then this screen then appears:
It is possible to hide a directory and keep all the sub-directories under it on the bafman list. Then those individual sub-directories can be hidden or kept individually.
Edit comments button - enter comments for any directory.
When working with Linux / Ubuntu directories you have to remember lots of details about them so you can enter some important comments here.
From the main screen type
/etc/default and the screen scrolls to that directory. Double click on it or hit the Space Bar to the select the directory and then click the
Edit comments button:
Appropriate comments have been entered. Note that if you
Hide the directory in the future the comments will be lost. The other fields on the screen are auto-generated every time you click the
Enter comments button and will be saved on the main screen.
Even if you don’t enter a comment coming to this screen and having directory counts generated counts as one transaction. (More on transaction counts later).
Add Dir button - Add directory to bafman list
You can add any directory to the bafman list and it will prompt to automatically add sub-directories as well. In this example we’ll add the directory
/lib which contains hundreds of sub-directories.
When you click the
Add Dir button this screen appears with your home directory selected as default:
As you probably suspected already my real name isn’t WinEunuchs2Unix as this screenshot reveals.
- Click the directory drop down arrow
Other...from the list
- Start typing
After selecting the directory to add, the screen reappears and we’ve typed in an appropriate comment:
OK to add the directory and then you are prompted to add sub-directories under it:
For our example, click
Note: If you attempt to add the entire
/libdirectory and all sub-directories you might get an error message “Unknown button return
code” and if you call bafman from the terminal the following error
line 575: /usr/bin/yad: Argument list too long
If you are running bafman from desktop shortcut you’ll see this error
/var/log/syslog. Remember bash has limits on how large arrays
can be when passing to GUI Yad.
After adding the new directory and sub-directories under it the main screen reappears. Start typing
/lib/systemd and the screen scrolls down to this section:
Here’s an important note: When adding a new directory it is appended to the bottom of bafman’s list. Simply click the Directory Name column heading to resort the list alphabetically.
All the statistics of file counts and file sizes are zero. If it were only a single directory we could simply click
Edit comments button and those stats are generated for us. But it is easier to click
Update Dirs button and go grab a coffee.
When you enter a comment while adding a new directory that comment is inherited by all the sub-directories under it (should you choose to add them at the same time).
Tag files button - Select the files which will be used by Run command
This is the heart of bafman and unfortunately incomplete at this time. Tagging files within the directory has been setup but designs need to be formulated for tagging files within sub-directories under the select directory. Hopefully community input helps in the design.
Let’s get started by navigating to the directory
/home/rick/.local/share/nautilus/scripts, selecting it with double-click and then clicking the
Tag files button:
If you’re like me you’ve invested a lot of time writing your scripts (or documents) so tagging them for subsequent copying is a good idea. This is a short list and we want everything so let’s click the
Tag All button:
The default is regular files only. This is where I need input as to what to do when directories are selected…
Very quickly to wrap things up click the
Untag All button:
The defaults are to untag ALL file types.
Thanks for staying awake and looking forward to your input. The next answer will post the WIP bash code.