Logo Questions Linux Laravel Mysql Ubuntu Git Menu

UNIX: List files in directory with relative path [closed]





The question is:

What command would you use to list the text files in your fileAsst directory (using a relative path)?

The previous question was:

Give a command to list the names of those text files, using an absolute path to the fileAsst directory as part of your command.

The answer was:


I was wondering how I can list the files in this directory using a relative path. I've tried several commands including:

ls ~/UnixCourse/fileAsst/*.txt|awk -F"/" '{print $NF}'
(cd ~/UnixCourse/fileAsst/*.txt && ls )

and a bunch of others.

But it keeps telling me their invalid. I know it has to be a correct answer because others have gotten past this. But right now I'm stuck and extremely frustrated =(


After going to the CS lab someone helped me figure out the problem. I needed to be in a certain working directory at first, and I wasn't. After switching to that directory all I needed was the command:


and that took care of it for me. Thanks to everyone that helped and I hope this helps someone else.

like image 881
pob21 Avatar asked Mar 24 '23 08:03


1 Answers


$ cd ~/UnixCourse/fileAsst/
$ find .

as a one-liner (executing in a sub-shell)

$ (cd ~/UnixCourse/fileAsst/ && find .)

another approach

$ (cd ~/UnixCourse && ls fileAsst/*.txt

$ ls ~/UnixCourse/fileAsst/*.txt
like image 51
Fredrik Pihl Avatar answered Mar 26 '23 21:03

Fredrik Pihl