Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

unix

macos

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:

~/UnixCourse/fileAsst/*.txt

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 =(

UPDATE:

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:

../UnixCourse/fileAsst/*.txt

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 01:03

pob21


1 Answers

try:

$ 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 14:03

Fredrik Pihl