How can I generate a list of files with their absolute path in Linux?
If you give find
an absolute path to start with, it will print absolute paths. For instance, to find all .htaccess files in the current directory:
find "$(pwd)" -name .htaccess
or if your shell expands $PWD
to the current directory:
find "$PWD" -name .htaccess
find
simply prepends the path it was given to a relative path to the file from that path.
Greg Hewgill also suggested using pwd -P
if you want to resolve symlinks in your current directory.
List file using ls command in Linux with full path
You can use
ls -lrt -d -1 "$PWD"/{*,.*}
It will also catch hidden files.
Show full path when using options
What about this trick...
ls -lrt -d -1 $PWD/{*,.*}
OR
ls -lrt -d -1 $PWD/*
I think this has problems with empty directories but if another poster has a tweak I'll update my answer. Also, you may already know this but this is probably be a good candidate for an alias given it's lengthiness.
[update] added some tweaks based on comments, thanks guys.
[update] as pointed out by the comments you may need to tweek the matcher expressions depending on the shell (bash vs zsh). I've re-added my older command for reference.
using 'ls' with options and folder and get full path
You can use find
:
find PATH_TO_FOLDER -maxdepth 1 -type f -printf "%p\n"
List all files (with full paths) in a directory (and subdirectories), order by access time
find . -type f -exec ls -l {} \; 2> /dev/null | sort -t' ' -k +6,6 -k +7,7
This will find all files, and sort them by date and then time. You can then use awk
or cut
to extract the dates and files name from the ls -l
output
How to get full path of a file?
Use readlink:
readlink -f file.txt
How can I get a recursive full-path listing, one line per file?
If you really want to use ls
, then format its output using awk:
ls -R /path | awk '
/:$/&&f{s=$0;f=0}
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
NF&&f{ print s"/"$0 }'
Related Topics
Show Special Characters in Unix While Using 'Less' Command
How Can Objdump Emit Intel Syntax
Fast Linux File Count for a Large Number of Files
The Difference Between Initrd and Initramfs
Postgresql Won't Start: "Server.Key" Has Group or World Access
How to Get the Nvidia Driver Version from the Command Line
How to Delete First Two Lines and Last Four Lines from a Text File with Bash
Macros for Gcc/G++ to Differentiate Linux and MAC Osx
How to Find Out Why My Storage Space on Amazon Ec2 Is Full
Linux Command or Script Counting Duplicated Lines in a Text File
When to Use Pipes VS When to Use Shared Memory
Execute a Shell Script Everyday at Specific Time
How Is It Possible That Kill -9 for a Process on Linux Has No Effect
How to Extract Filename.Tar.Gz File
How to Request a File But Not Save It with Wget
How Does the 'Ls' Command Work in Linux/Unix