Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to 'ls' another directory in unix script?

Tags:

shell

unix

My code

echo $ls | /var/lib/judgem/records/

I'm trying to get the script to show me all the files inside the folder "records"

How do I do that?

like image 700
Dan Avatar asked Mar 19 '14 17:03

Dan


2 Answers

Or, if you want to list the contents of another directory without the full path, i.e. as though you were in the other directory, but without ending up there after the command has finished, you can use a subshell like this:

(cd /var/lib/judgem/records/ && ls)

You will notice you stay in whatever directory you were in but the files are listed without the full path of /var/lib/judgem/records on the front.

like image 58
Mark Setchell Avatar answered Oct 13 '22 21:10

Mark Setchell


Give the directory as the argument to ls:

ls /var/lib/judgem/records
like image 20
Barmar Avatar answered Oct 13 '22 20:10

Barmar