0

I'm preparing a batch compiling sh file in Ubuntu. It is using dir command to get a list of files (and some string processing to extract names). But this may not be the best way (but easy enough) of getting list.

Question: do all Linux distros answer "dir" command same?

dir /usr/lib/nvidia-*

/usr/lib/nvidia-396:
alt_ld.so.conf             libnvidia-cfg.so.396.54
bin                libnvidia-compiler.so
ld.so.conf             libnvidia-compiler.so.1
libEGL_nvidia.so.0         libnvidia-compiler.so.396.54

1 Answers1

4

Most Linux distributions will have dir, which comes from coreutils. It will behave in the same way on any distribution which uses coreutils.

The usual caveats about parsing ls also apply to dir; there are probably other, better ways to go about solving the problem you’re trying to solve.

Stephen Kitt
  • 434,908
  • I'm filtering ":" char out from that nvidia folder name and scanning names by splitting whole string by carriage returns, tabs and spaces. I guess anything delimiting with a "----" would not work. I wish there was a command that simply gets whole tree of files into an array in sh file without installing any addon. – huseyin tugrul buyukisik Oct 24 '18 at 17:05
  • I highly recommend asking another question where you explain what you’re trying to do with the list of files ;-). – Stephen Kitt Oct 24 '18 at 17:14
  • You mean, if I'm looking for nvidia's ptx jit driver files, should I ask "how to find nvidia driver files for online-compiling a C++ CUDA code"? Or should I ask "how to get files right into arrays"? – huseyin tugrul buyukisik Oct 24 '18 at 17:15
  • When asking a question here, the best approach is to describe your goal, perhaps from an even higher level than “How to find NVIDIA driver files for ...” Then present what you’ve already tried, which will naturally cover the specifics (“I’m trying to ..., and I thought I could go about it by building an array of files to do ...”). – Stephen Kitt Oct 24 '18 at 17:20
  • Ok. Thank you. I'll add a sh file, its output and what I expected and what I intended next time. – huseyin tugrul buyukisik Oct 24 '18 at 17:26
  • 1
    In your script, you may want to call dir by it's full path, or via env dir. This will prevent your script from using an alias that may have been set up, which behaves differently. – Tim Kennedy Oct 24 '18 at 18:06