List MP4 by " file '*.mp4' " to a .txt
I'm not sure I understand the goal right, but if you want every line to read
file '/full/path/to/filename.mp4'
I suggest to use find
this way:
find ~+ -type f -name "*.mp4" -printf "file\t'%p'\n"
This searches the current working directory (~+
is expanded to the full path by bash
's Tilde Expansion) for files whose name matches *.mp4
and prints them in the specified format: "file" followed by a tab and the filename enclosed in single quotes followed by a newline character – if you want a space instead of the tab, simply substitute \t
by a space. If you want to store the output in a file files.txt
, just add >files.txt
to the command line. Note that this will silently overwrite any existing files.txt
, if you want to append to the file use >>files.txt
instead.
Example output
$ find ~+ -type f -name "*.mp4" -printf "file\t'%p'\n"
file '/home/dessert/test/a.mp4'
file '/home/dessert/test/b.mp4'
$ find ~+ -type f -name "*.mp4" -printf "file\t'%p'\n" >files.txt
$ cat files.txt
file '/home/dessert/test/a.mp4'
file '/home/dessert/test/b.mp4'
If you however want files.txt
to contain the output of file 'some.mp4'
, you can use file
directly:
file *.mp4 >files.txt # with relative paths
file ~+/*.mp4 >files.txt # with absolute paths
You can use:
for i in ./*.mp4; do echo "file" \'$(realpath ${i#*\/})\' >> files.txt; done
If you don't need file
in front of each filename, you can use:
ls path/to/files/*.mp4 > files.txt
Result from first command:
file '/home/george/Documents/askubuntu/disk_use.txt'
file '/home/george/Documents/askubuntu/efi_info.txt'
file '/home/george/Documents/askubuntu/empty.txt'
file '/home/george/Documents/askubuntu/fam.txt'
Note:
- I used
.txt
files, yours will.mp4
. - This is run from the folder of interest, if you need to target another please change the line
for i in ./*.mp4
tp for i in /path/to/files/*.mp4`.