0

Can i use ls - t | xargs > output.txt by being outside the directory for example

I want to access /home/123/script/final directory and then perform the above function. Something like this:

ls - t | xargs  /home/123/script/final > output.txt

but getting permission denied error

  • 1
    Welcome to the U&L SE. Can you explain what you are trying to accomplish with ls and xargs? Do you simply want to list the files inside the /home/123/script/final folder? – Haxiel Jan 16 at 12:32
1

Do you know what the commands you execute actually do?

You want to list the files of that specific directory, so you need to give that as a parameter to ls, not to xargs.

ls -t /home/123/script/final | xargs > output.txt
  • Hi panki the above command is not working still show no such file or directory but i do have the final folder – Rahul Rawat Jan 16 at 12:24
  • The directory must exist for ls to be able to list its contents, obviously. Also, you need the required permissions. – Panki Jan 16 at 12:25
0

No xargs necessary - redirect ls output immediately to the destination. If you want all file names in one line, try the --format=across option - if available.

0

I want to access /home/123/script/final directory and then perform the above function. Something like this: ls - t | xargs /home/123/script/final > output.txt but getting permission denied error

There are a few problems:

  1. You need to have the right to access to that home directory.
  2. The ls command is ls -lt and not ls - t

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.