girishkumar
girishkumar

Reputation: 33

get a list of files and directories with full path in unix

I am trying to get full path of both the files and directories from a directory. I tried using find but unable to get result.

when I used find /home/demo -type f it only lists files and find /home/demo -type d only lists directories.

Is there a way to get both using Find?

Upvotes: 0

Views: 101

Answers (1)

konsolebox
konsolebox

Reputation: 75478

You can specify the absolute path of a directory. As an example for the current directory:

find "`pwd`"

pwd shows full path of current directory. ` ` summons a subshell in which output can be used as an argument to the command.

A literal example can be:

find /home/user

Update: You can use -o to explicitly target both files and directories. Doing find without an option may include other types besides the two.

find /home/user \( -type f -o -type d \)

Note: -or is synonymous but may not work in other versions of find since it's not POSIX compliant.

Upvotes: 2

Related Questions