How do I list files with full paths in Linux?
Use the find
command. By default it will recursively list every file and folder descending from your current directory, with the full (relative) path.
If you want the full path, use: find "$(pwd)"
.
- If you want to restrict it to files or folders only, use
find -type f
orfind -type d
, respectively. - If you want it to stop at a certain directory depth, use
find -maxdepth 2
, for example.
Read Finding Files for an extensive manual on GNU find
, which is the default on Linux.
$ pwd
/home/victoria
$ find $(pwd) -maxdepth 1 -type f -not -path '*/\.*' | sort
/home/victoria/new
/home/victoria/new1
/home/victoria/new2
/home/victoria/new3
/home/victoria/new3.md
/home/victoria/new.md
/home/victoria/package.json
/home/victoria/Untitled Document 1
/home/victoria/Untitled Document 2
$ find . -maxdepth 1 -type f -not -path '*/\.*' | sed 's/^\.\///g' | sort
new
new1
new2
new3
new3.md
new.md
package.json
Untitled Document 1
Untitled Document 2
Notes:
.
: current folder- remove
-maxdepth 1
to search recursively -type f
: find files, not directories (d
)-not -path '*/\.*'
: do not return.hidden_files
sed 's/^\.\///g'
: remove the prepended./
from the result list
For completeness, the ls -lR /
command will list the name of each file, the file type, file
mode bits, number of hard links, owner name, group name, size, and timestamp of every file (that you have permission to access) from the root directory down. (l
is for long list ie all that info, R
is to recurse through directories, /
starts at the root of the filesystem.)
There are a number of params to make the output info closer to dir /S /A
, but I have to admit I can't work out how to translate the /B
.
For useful info, I would try: ls -lAFGR --si /
where
- l = long list (as mentioned above)
- A = almost all files (doesn't include . and .. in each dir, but does show all hidden files)
- F = show file indicator, (one of
*
for exe files,/
for directories,@
for symbolic links,|
for FIFOs,=
for sockets, and>
for doors) - G = don't show group info (remove this if you want to see it)
- R = recursively list directories (subdirectories) and
- --si = show the file size in human readable eg 1M format (where 1M = 1000B)
ls
can provide an easier to read synopsis of directories and files within those directories, as find
's output can be difficult to scan when files are contained within really long directory structures (spanning multiple lines). The corollary is that each file is listed on its own (ie without directory path information) and you may have to go back a couple of pages/screens to find the directories a particular file is located in.
Also, find doesn't contain the /A information in the DIR command. I've suggested a number of attributes in the command I've shown (that coincidentally show the extra usefulness that you get from linux over a certain proprietary system), but if you read the man
and info
pages on ls
, you will be able to see what to include or not.