Cut command from lmpthw

in exercise 8 of lmpthw i.e the cut command section, author has asked to try this command:
ls −l | cut −d ’ ’ −f 5−7

i hit that in my terminal to see what it does. now i am wondering if it changes the original files, like it said, ‘it cuts the part of lines from the files’. so i am afraid if i have done any damage to my original files. do those parts get permently deleted from them? if so what shall i do to restore back in their own place?

the ss of the output on my terminal is attached here for the reference.

please explain what did i just do with that command. thank you.

Screenshot from 2020-06-06 14-56-23

Don’t worry. cut doesn’t change any files on its own.

The command you typed has two, actually, three parts.

  1. ls -l simply lists the contents of the directory – in other words it produces some output string that would normally just be printed on the screen.
  2. | The pipe symbol takes the output of the previous command and “pipes” it into the input stream of the following command.
  3. cut -d '' -f 5-7 now takes that input, does its magic with it, and finally prints it.

If you wanted cut to change files you’d have to redirect its output into one.

@florian has the right idea but missed on what cut actually does.

The text from ls is basically like a terrible Excel table. Cut just lets you cut columns out of the table by saying what delimits (-d) the column, and what field (-f) you want.

That’s it. It’s for cutting columns out of output data.

1 Like

Yeah, I thought the question was about the input output thing. Now the magic trick is revealed…

thank you @florian and @zedshaw, that was helpful and comforting! i was kind of little worried.
i should have broken the command before and after the pipe and tried executing. now i am aware and tried that too! interestingly that seems way more clearer now :slight_smile:

1 Like