LS doesn't list files or directories (it doesn't list anything at all)


I’m a bit of a Linux noob, so pardon any glaring ignorance ahead of time.

I just finished a fresh minimal (e.g. command line only, no GUI) nixos-install of ver. 23.05.3242 but following a reboot I noticed that ls doesn’t list anything at all. No error message, files, directories, nadda.

The issue seems similar to this issue here: Can't ls anymore but there’s some key differences resulting in that post not being the remedy for my issue.

Some context

During the manual install process I followed the Manual Install part of the guide step-by step: NixOS 23.05 manual | Nix & NixOS

I generated the default configuration.nix file via nixos-generate-config --root /mnt

I am able to use nano to navigate to /etc/nixos/configuration.nix , confirming there’s at least one directory that should show /etc/ and it’s contents

Logged in as root

type ls returns
ls is aliased to 'ls --color=tty'

readlink $(which ls) returns

Note ^ the above alpha numeric value after /store/ is truncated because I’m transposing it from my offline machine beside me that only has the minimal install of nixOS feshly installed on it. I can’t copy and paste from it to the machine I’m currently typing on.

It could be I’m misunderstanding how minimal of an install this is and some basic linux commands aren’t included until I tweak the config file a certain way.

Any help to get ls working for me is much appreciated!

What does type -a ls say?

Hi abathur!

type -a ls returns

ls is aliased to 'ls --color=tty'
ls is /run/current-system/sw/bin/ls

Did you modify the default configuration at all?

ls doesn’t list anything, it is from core-utils, and it doesn’t have a weird alias…
Well, here goes some dumb low-hanging fruit questions.

Does the program exit or is it hanging? If it does exit, was the exit code abnormal? Are you certain ls is supposed to find anything in the working directory (could it be read permissions?)? If the exit code was 0, and you know ls should list something, could you try with different flags, especially the -a flag and --color=never (surely, it should list . and ..)?

Turns out I likely don’t have anything in my working directly.

No error code and no hanging when typing ls and no modifying of configuration.nix so digging further…

When running ls -a I do see . and .. in addition to .bash_history .lesshst .nix-channels .nix-defexpr .nix-profile .w3m

I then ran

cd /

then ls and I could see the bin boot dev etc home, etc…that was I expecting

Turns out I was expecting to be in /, but I was in ~ and turns out there’s just nothing in my home directory? Here I was assuming there would be something to list in ~

Turns out it was a simple solve after all.

I’m continuing to learn so want to ask two questions here to close up the thread and keep me on my journey:

  1. What usually gets installed to ~ ie: when should I expect to see info in ~ (As a reminder, I’m a Linux noob)

  2. How do I scroll in the nixOS terminal. Does it require another piece of software to allow scrolling in tty? Often I’ll type --help in the tty (not in a program like Emacs, where I do know how to scroll) and the output is beyond the screen and no variation of CTRL + SHIFT + PAGE UP, or CTRL + SHIFT + ARROW KEY, or CTRL + P, or E, or other unix/emacs type commands triggers a scroll

I imagine lots of my questions will be answered by digging deeper, installing programs, etc… It is the minimal install after all. Which I’m continuing to stick with to learn from. It’s been really fun so far. Emacs is next on the list to install.

I won’t have as much time to play around further until next weekend but I really appreciate the help so far. I’m happy to be part of this community!

Well there we go. That’s what my “dumb” questions are for! People tend to question whether or not the tool is working properly and don’t bother to question whether or not we’re using it properly or have the proper expectations of what it should do.

  1. A lot of desktops and graphical programs will create directories in HOME (Documents, Downloads, etc.) but, since you’re in a TTY and can’t really use graphical programs, that didn’t happen and you didn’t create any files or directories yourself; thus, HOME had only hidden files and directories which were created by bash, less, nix, and w3m (and the omnipresent . and .. which represent the current directory and parent directory, respectively). Any file starting with . won’t be shown unless ls is run with the -a or -A flag (ls --help will fill in the details). I hope you can extrapolate an answer from that. Also, I would encourage you to investigate the XDG Base Directory Specification, which will give you a little idea of how to find some things.

  2. Well, for too-long help texts you can use --help | less which will allow you to use arrow/vim keys to read (and even search with / or ?!) the full text. I recommend installing and learning to use zellij which will seriously boost your TTY escapades. Or, you know, you could use a graphical environment and terminal, but where’s the fun in that? :wink:

I couldn’t agree more. No harm in asking the “obvious” questions - they certainly provided value in this situation.

  1. I absolutely can extrapolate an answer from this. Thank you. I’ll brush on the XDG Base Directory Specification this weekend

  2. zellij looks wonderful. I’ll aim to get a jumpstart learning this this weekend.

Or, you know, you could use a graphical environment and terminal, but where’s the fun in that?

My thoughts exactly!

Thanks again everyone in this thread for the assistance :man_bowing:

1 Like