I am not an advanced linux user and I have a hard time wrapping my head around some new concepts. I recently read about xargs command and wanted to test some examples. One of them confused me like hell.

The theory was this: If I can start editing a non existent file in vim (with vim someFile) and create it only after it is edited (with :qw) then I could use echo and xargs to do the same job:

echo "someFile" | xargs vim

xargs will get the output of echo from stdout and will pass it as an argument to vim. It appears however this leads to the following error -

Vim: Warning: Input is not from a terminal

The strangest thing is that a second after the error is printed vim will open the file but when I save it and exit vim my terminal is totally bugged. I need to close the tmux pane in order to fix the terminal. After all this the file will be created and the content will be as expected. It is obvious something is not right here but I have absolutely no idea why.

I found this question in StackOverflow but it does not answer mine.

  • 1
    It's not an error, it's a warning that happens if vim is reading from a pipe. You are basically running vim someFile, while reading the empty output of xargs. I don't understand why this bugs your terminal though.
    – Panki
    Commented Jan 17, 2023 at 11:38
  • @Panki What exacly do you mean by "while reading the empty output of xargs"? As per my understanding xargs takes the stdout text and converts it to an argument for the vim command.
    – dimitar.d
    Commented Jan 17, 2023 at 11:50
  • The reset command will fix the terminal. You may need to use ctrl-j instead of enter.
    – user10489
    Commented Jan 17, 2023 at 12:11
  • Sorry, I mixed up xargs and echo. vim is getting nothing on stdin from echo because xargs is parsing that.
    – Panki
    Commented Jan 17, 2023 at 12:25
  • @Panki Yes, I expact exactly that. I don't understand why vim fileName and echo fileName | xargs vim behave differently when they need to be do the same thing in a different way. Is that correct or am I missing something.
    – dimitar.d
    Commented Jan 17, 2023 at 14:53

1 Answer 1


stty sane will correct your terminal issue.

The reason this is happening is that xargs is not opening your tty in the child process.

You need to add the -o option in xargs for "open tty".

echo "sane" | xargs -o stty

This runs stty sane connected to your terminal. It produces no error.

echo "sane" | xargs stty

This produces an error on BSD:

stty: stdin isn't a terminal

and on Linux:

stty: 'standard input': Inappropriate ioctl for device

This worked for me:

echo /etc/hosts | xargs -o vim
  • Hi James, echo someFileName | xargs -o vim leads to the following error - xargs: invalid option -- 'o'
    – dimitar.d
    Commented Jan 17, 2023 at 14:59
  • 1
    It's because I have an older version. I will update now and try again.
    – dimitar.d
    Commented Jan 17, 2023 at 15:00
  • What OS? What version of xargs? What does this say for you: % xargs --help| grep tty -o, --open-tty Reopen stdin as /dev/tty in the child process Commented Jan 17, 2023 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .