Search code examples
bashsessiontmux

Bash: Using asterisk in any bash command in home directory exits with error "Unrecognized options --list-sessions"


Title. This same/similar error seems to occur with any command in bash if I:

  1. Am in my home directory, i.e. after cd ~. It doesnt occur in other places.
  2. Have an asterisk/wildcard in the command matching all of the files+dirs. It doesnt happen without the asterisk as far as I can tell.

Examples:

me@mypc:~$ ls *
ls: unrecognized option '--list-sessions'
Try 'ls --help' for more information.
me@mypc:~$ ls
...
Desktop
Downloads
...
(prints all directories)
me@mypc:~$ ls ./*
(prints all subdirectory subdirectories)
me@mypc:~$ ls .*
...
.vscode:
argv.json  extensions

.wine:
dosdevices  drive_c  system.reg  userdef.reg  user.reg
...
(prints all subdirectories with their contents)

me@mypc:~$ du -sch *
du: unrecognized option '--list-sessions'
Try 'du --help' for more information.
me@mypc:~$ du -sch .*
du: cannot read directory './.dbus': Permission denied
du: cannot read directory './.pgadmin': Permission denied
66G .
du: cannot read directory '../postgres/.gnupg': Permission denied
64K ..
66G total

me@mypc:~$ grep "\-\-list-sessions" *
grep: unrecognized option '--list-sessions'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

And so on. The list-sessions flag seems reminiscent of this tmux command:

me@mypc:~$ tmux list-sessions
error connecting to /tmp/tmux-1000/default (No such file or directory)
me@mypc:~$ whereis tmux
tmux: /usr/bin/tmux /usr/share/man/man1/tmux.1.gz

The list-sessions error in other commands persists with and without running tmux server. Thanks for your help!


Solution

  • I'm guessing you have a file in your home directory named --list-sessions and the *, when expanded, is causing your command (eg, ls, du) to treat the file name as an option:

    Consider ...

    $ mkdir /tmp/ttt
    $ cd /tmp/ttt
    $ touch -- '--list-sessions'
    $ ls -a
    --list-sessions  ./  ../
    
    $ ls *
    dir: unknown option -- list-sessions
    Try 'dir --help' for more information.
    $ ls -- *                               # disable further command line option processing
    --list-sessions
    
    $ du -k *
    du: unknown option -- list-sessions
    Try 'du --help' for more information.
    $ du -k -- *                            # disable further command line option processing
    0       --list-sessions
    

    NOTE: The -- used in the above commands disables further command line option processing, eg, What does double dash mean?