Make the ls command show the path of each file?

At some time in the past on another *nix system (perhaps HP-UX, AIX, or Linux) I believe I was able to issue an "ls" command with a switch that would show each file on a separate line with the path (perhaps starting with the pwd) prefixed to the file name, but not show separate lines for directories. For example, if the mystery switch is "z", the command "ls -R -z" would show this:


file1

file2

subdir1/file3

subdir1/file4

subdir2/file5

subdir2/file6


Could my mind be manufacturing that recollection? I've searched the OS X man page for ls, but haven't been able to find anything similar.


The "-1" switch does cause one file name to be displayed per line, but shows directories on separate lines instead of prefixed to each file name.


Thanks for any help.

MacBook 5,2 2.0 GHz, 4GB RAM, Mac OS X (10.7)

Posted on Apr 19, 2012 7:40 PM

Reply
12 replies

Apr 19, 2012 8:02 PM in response to Kappy

Kappy wrote:


Could be you remember a Linux command that doesn't exist in BSD Unix.

That could be. I'd find that option useful when searching for a file on a network drive that Spotlight doesn't index. I could issue the ls command, then run the output through grep to search for whatever part of the file name that I remember. I could do that without the path option, but then all I'd know is the full file name, not where it resides.


A few times I've resorted to dumping the entire directory to a file, then searching the output file so that I can see the previous directory line to identify the location of the file.


I suppose some option of the find command could accomplish this, but I use find so seldom that I can never remember its syntax.

Apr 20, 2012 5:52 AM in response to William-Boyd-Jr

The 'find' command can be as simple as


find .


If you want something that is similar to "ls -l" you can use


find . -ls


'find' has lots of features, but it does not need to be complicated for what you want.


If you think you need some 'find' functionality a lot, then put it in a script or a bash shell alias. If nothing else, the shell script will be a reminder of all the options you found useful and may be an aid when you need to create a different 'find' command.

Apr 20, 2012 8:28 AM in response to BobHarris

It seems that this command


find /Volumes/that_network_volume


will do what I want. Thanks for the nudge in that direction.


I understand that the find command is very powerful. The types of find command that I might use most commonly are those with the -exec switch. However, "most commonly" in my case means "rarely", so I can never remember the syntax from one use to the next.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Make the ls command show the path of each file?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.