In the linux terminal, you need to read the file -data.txt- only with the ls command. Any ideas?

  • one
    The task of course delusional. Why if there is a cat for this? - LFC
  • four
    Define the term read . Looking ahead, if you are talking about the contents of a file, then this cannot be done using the ls command . - 0andriy
  • one
    We must somehow deceive ls so that she would think that this file is a directory. Then she will try to print a list of files from this "directory" and, at least, error messages will contain pieces of text from this file. - Sergey
  • four
    you can always make the right alias. and then even rm will read the files. - KoVadim

1 answer 1

using the ls command

This is where the trick lies.

After all, the program /bin/ls this, of course, does not know how.

but the command executed by the shell can run an arbitrary program. for example, /bin/cat . Well, to determine the actions of the team can be different. for example, using the built-in alias shell command (to create command aliases):

 $ alias ls=/bin/cat 

check:

 $ ls файл здесь будет результат выполнения программы /bin/cat с аргументом "файл", т.е. содержимое этого файла 

or by defining a function. First we delete the alias:

 $ unalias ls 

and create a function. either so:

 $ function ls { /bin/cat $@; } 

either way (just another syntax):

 $ ls () { /bin/cat $@; } 

verification will give a similar result.

  • Well, this is some kind of perverted consciousness that a teacher should have in order to introduce such subtleties into the tasks. So, it is necessary to enter the name on chicaneism, but not on programming or system administration. - 0andriy