Gibt es eine Möglichkeit path / to / Datei mit ls + awk, sed, grep oder ähnliche Werkzeuge zu bekommen?
Frage
Ich möchte rekursiv ein Verzeichnis suchen, und Ausgang:
Dateiname Datum Pfad Größe
Ich habe alles, aber Weg ... die eine $$$$ buster ist ....
Hier ist mein Befehl so weit:
ls -lThR {DIRECTORY_NAME_HERE} | awk '/^-/ {print $10 " " $6 " " $7 " " $8 " " $5}'
Ich wünschte, es gäbe einen Weg, diesen Befehl zu kombinieren mit:
find ./{DIRECTORY_NAME_HERE} -type f
, die nur zeigt / path / to / Dateinamen selbst ... keine andere Metadaten afaik.
Alle Ideen ... hoffentlich ohne eine Programmiersprache zu benötigen?
Bearbeiten : Hier ist die genaue Ausgabe ich suchte Datei angenommen wird 5 Bytes:
myfile.txt 2. Dezember 10.58 / path 5
UPDATE : Hier ist der Befehl, den ich in Liquidation mit:
find ./{DIRECTORY_NAME_HERE} -type f -ls |
while read f1 blocks perms blocks owner group size mon day third file;
do echo `basename $file` `ls -lrt $file | tr -s " " | cut -d" " -f6-8` `dirname $file` `ls -lrt $file | tr -s " " | cut -d" " -f-5`; done
Wenn jemand es verbessern können, das wäre großartig, aber das funktioniert ...
Lösung
Have you tried find ./delete -type f -ls
(note the -ls
-- that's the key :-) )? You should then be able to pipe the results through awk
to filter out the fields you want.
Edit... Another way you could do it is with a while loop, e.g.:
find ./delete -type f -ls | while read f1 blocks perms blocks owner group size mon day third file
do
echo `basename $file` `dirname $file`
done
and add the bits you need into that.
Andere Tipps
You can also use the -printf feature of find to show just the right properties of a file that you want:
find {DIRECTORY_NAME_HERE} -type f -printf '%f %Tb %Td %TH:%TM %h %s\n'
I get results like this:
config Nov 10 10:02 /etc/w3m 1185
mailcap Nov 10 10:02 /etc/w3m 44
hosts.allow Apr 29 05:25 /etc 580
rsyslog.conf Feb 24 10:26 /etc 1217
user-dirs.conf Apr 16 15:03 /etc/xdg 414
user-dirs.defaults Apr 16 15:03 /etc/xdg 418
I'd use Perl for this task:
#!/opt/local/bin/perl -w
use File::Find;
use POSIX qw(strftime);
find(\&wanted, ($DIRECTORY_NAME_HERE));
sub wanted {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime) = stat;
printf("%s %s %s %d\n", $_,
strftime("%b %e %H:%M %Y", localtime($mtime)),
$File::Find::dir,
$size);
}