0

My apologies if this has been asked before. I am using Ubuntu 16.04.3 desktop and would like to be able to output the contents (file names) of a directory into a single text file via terminal/cli.

I think when I used to use DOS, years back, went something like this: dir /w/p > file.txt ..think that was it, but simple and damn handy

Thank you for your time and help with my question

1

The general command for listing directory contents in Linux is ls

LS(1)                            User Commands                           LS(1)

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List  information  about  the FILEs (the current directory by default).
       Sort entries alphabetically if none of -cftuvSUX nor --sort  is  speci‐
       fied.

Probably the nearest equivalent to dir /w will be ls -C (the /p option - pause - doesn't really make sense when writing to a file). So

ls -C > file.txt

In fact, there's a dir command in Linux as well - so you could just do dir > file.txt

See Difference between 'dir' and 'ls' terminal commands?

1
  • Thank you for your help steeldriver, appreciate it. Very true about the /p option, just so use to using it to pause dir output. Take care and thank you again ;)
    – Sean S
    Feb 28 '18 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.