1

For example, I have four pieces (1.txt, 2.txt, 3.txt, 4.txt) and when the concatenate together (all.txt), that's the file what I want:

cat 1.txt 2.txt 3.txt 4.txt > all.txt

However, I don't want to create the real file (all.txt) because it might be very big, or very slow. However some programs or software only accept one file as its argument. (for example, sh all.txt != sh 1.txt && sh 2.txt && sh 3.txt && sh 4.txt)

How to make such a virtual file? Or how to treat them as one file?

Someone asked a similar question here, however, I have limited permission on my computer and losetup is banned.

Concatenating files to a virtual file on Linux

Patrick Mevzek
  • 10,581
  • 7
  • 35
  • 45

2 Answers2

2

Process substitution in bash (and some other shells).

./someprogram <(cat {1..4}.txt)
2

One solution among multiple ones is to use FIFO pipelines:

$ mkfifo my_virtual_file.txt
$ cat 1.txt 2.txt 3.txt 4.txt > my_virtual_file.txt &
$ my_command my_virtual_file.txt
$ rm my_virtual_file.txt

This may or may not work depending on what my_command does with the file: as with some other solutions, if it needs to seek into the file (that is arbitrarily move forward and backward in the content) then that will fail; instead, if it just reads the file line by line for example, that will work.

Of course the content is available read only, the command would not be able to write to it (or at least that will not work as expected).

Patrick Mevzek
  • 10,581
  • 7
  • 35
  • 45