List MP4 by " file '*.mp4' " to a .txt
I want create a .txt with all mp4 files of a folder, but vertically and with
file '/root/mp4/*.mp4'line by line. In Windows it's like
(for %i in (*.mp4) do @echo file '%i') > files.txt 3 3 Answers
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; doneIf you don't need file in front of each filename, you can use:
ls path/to/files/*.mp4 > files.txtResult 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
.txtfiles, yours will.mp4. - This is run from the folder of interest, if you need to target another please change the line
for i in ./*.mp4tp for i in /path/to/files/*.mp4`.
Run this in terminal tried and tested on ubuntu 20
printf "file %s\n" *.mp4 > files.txt More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"