Steeldriver done beat me to it, and more elegantly. I'm not gonna be in his class for a decade at least. But since I already wrote and tested this, I'll post it, FWIW. The following code is to be put in a script. Then you run the script in a terminal with the sole argument being the directory containing the files you want to deal with. If you wanted to run it from a gui file browser, you'd need to invoke it with something like
xterm -e /path/to/this_script.sh $f,
f being whatever variable the file browser passes on the /path/to/directory as.
So open a plain text file with an editor, something like geany, leafpad, or (shudder) gedit.
Copy the code below into it, starting with the "#!/bin/bash two lines below this.
##### Do NOT copy this line, start with the next line beginning "#!"
# repeats until you enter a valid directory
# you might add a test to make sure you have adequate permissions.
while [ ! -d "$DIr" ] || [ $DIr = / ]; do
read -p "$DIr is not a valid argument. Enter a
directory other than '/' with files you want to process:" DIr
# canonicalizes directory name
DIr="$(readlink -f "$DIr")"
for FILE in $DIr/*; do
BASE_NAME_minus_ext="$(echo -n "$BASENAMe" | rev | cut -d'.' -f2- | rev)"
# If you want 'em all in a single list, instead use:
# echo "$BASENAMe" >> "$DIr/List_of_names_minus_extensions"
echo "$BASENAMe" > "$DIr"/"$BASE_NAME_minus_ext"
##### Do NOT copy this line. Copy through and including "done" just above. No more.
Save the file with a convenient name, like "list.sh", without the quote marks. Move it to one of the directories in your path. You can display the path with the command:
That will return a string which is a bunch of directories seperated by colons ( the ":" character). The individual directory names all begin with a "/". They do NOT include the ":". Any of those directories will do. If it is in your path, I suppose the most conventional one would be:
but it really doesn't matter as long as it is one of them. If you did that with a graphical file browser (like Nautilus, Thunar, or Pcmamfm), right click on the script (i.e. the file you just created and moved) and click "properties" and then "permissions" if that is a separate tab. Set it as executable by you. All sorts of ways to do that. Most convenient is to set as owned by your user name and the group of the same name and check executable, readable and writable by owner and group but none of those by other.
If you are doing this from command line:
chmod -v ug+r+w+x /usr/local/bin/list.sh
using whichever of the directories on the path you put the file in and whatever filename you gave it.
Or, if that fails, do these 2, one at a time, in order:
sudo chown your_user_name:your_user_name /usr/local/bin/list.sh
sudo chmod -v ug+r+w+x /usr/local/bin/list.sh
Now you should have an executable script that can be invoked by typing it's name into a terminal and pressing enter, either plain like this:
or with the name of the directory you want it to act on like this:
If you don't include the full /path/to/directory_you_want_acted_upon, it will make a reasonable guess about where to find it. It might guess wrong. If you want to save yourself keystrokes you can give the script a shorter name like "lis" or if you want to make it easier to remember what it does, you can give it a longer name like "list_files_within_without_extensions.sh. The ".sh" ending is a common convention for script names just so you will know what the file is by looking at its name. you can name it anything, even "George Humperdink, III" if you want to, but spaces and commas tend to cause trouble.
Some more thoughts:
In light of your response to sudodus, I must caution, do NOT use sudo to run either his command or my script. I can't think of any good reason for movies to be owned by root or in a directory owned by root. They absolutely should NOT be run in a viewer by root. We don't have much of a malware problem in the 'nix ecosystem, but invoking media players, even pic viewers, as root, is asking for trouble and if enough people ask for trouble, someone will provide it. Therefore the files MUST be readable by a plain user, and it would be darned awkward to keep them in a directory that wasn't readable, writable, and "executable" by a plain user. If either his command or my script fails in a way that sudo would have prevented, then you need to change the perms of the files or the directory they are in. Using sudo would be like setting fire to the furniture because the AC has made the room too cold. It will just give you MORE permission problems by creating root owned list files. Never use sudo unless you HAVE to, and then only if it makes sense. If it doesn't make sense to have to use sudo, then fix the problem, don't work around it.
Also, yes his command will work for other extensions if you make the logical changes in it. The script works for any extensions as is.
You'll note near the middle is a commented out line regarding whether you want this to make one list in the directory it acts on or make a separate text file for each movie. Putting a "#" mark at the beginning of a line is referred to as "commenting out" the line. It means it is a comment for humans to read and bash will ignore it. You can make the script work either way by changing which of the pair of lines is commented. One should be commented, and the other not commented.