Mac OS X-Äquivalent des Ubuntu-Befehls "tree"
Gibt es ein Äquivalent zum Ubuntu tree
befehl für Mac OS X?
12 answers
Sie können den Befehl tree
auch auf macOS erhalten. Wenn Sie Homebrew:
brew install tree
Wenn Sie Homebrew nicht installiert haben, versuchen Sie es mit einem Ansatz unten.
Installieren eines Paketmanagers Ansatz
Folgen Sie den Anweisungen auf diesen Websites, um Homebrew zu installieren, MacPorts oder Fink. Installieren Sie nicht mehr als einen Paketmanager gleichzeitig!
Folgen Sie der Eingabeaufforderung für das, was Sie installiert.
Für Homebrew: brew install tree
Für MacPorts: sudo port install tree
Für Fink: fink install tree
Installation von source-Ansatz
-
Installieren Sie die Xcode-Befehlszeilentools, indem Sie
xcode-select --install
ausführen. -
Ändern Sie das Makefile, damit es funktioniert, was auch in der Antwort von @apuche unter erklärt wird. Kommentieren Sie die Linux-Optionen und kommentieren Sie das macOS optionen sollten ausreichen.
-
Dann führe
./configure
aus, dannmake
. -
Jetzt müssen Sie die Binärdatei
tree
an einen Speicherort verschieben, der sich in Ihrem ausführbaren Pfad befindet. Beispiel:sudo mkdir -p /usr/local/bin sudo cp tree /usr/local/bin/tree
-
Bearbeiten Sie nun
~/.bash_profile
, um Folgendes einzuschließen:export PATH="/usr/local/bin:$PATH"
-
Lade die Shell neu und jetzt sollte
which tree
auf/usr/local/bin/tree
zeigen.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-08-20 07:18:53
Nicht genau das gleiche, aber ein schneller Weg auf dem Mac ist:
find .
Und das war ' s. Es werden alle Dateipfade im aktuellen Verzeichnis als Liste aufgelistet.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2014-05-02 13:40:18
Oder wenn Ihr Administrator Sie keine derbrew
, fink
, port
tools Sie können es immer aus der Quelle erstellen:
curl -O ftp://mama.indstate.edu/linux/tree/tree-1.5.3.tgz
tar xzvf tree-1.5.3.tgz
cd tree-1.5.3/
ls -al
Bearbeiten Sie das Makefile, um den Linux-Teil zu kommentieren und den OSX-Bereich auszukommentieren:
# Linux defaults:
#CFLAGS=-ggdb -Wall -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
#CFLAGS=-O2 -Wall -fomit-frame-pointer -DLINUX -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
#LDFLAGS=-s
# Uncomment for OS X:
CC=cc
CFLAGS=-O2 -Wall -fomit-frame-pointer -no-cpp-precomp
LDFLAGS=
XOBJS=strverscmp.o
Optional: Erzwingen der Farbausgabe
Und während Sie gerade dabei sind, können Sie, wenn Sie den Baum zwingen möchten, die Ausgabe immer zu kolorieren, immer die Methode main
der Datei tree.c
bearbeiten und force_color=TRUE;
vor setLocale(LC_TYPE,"");
Drücke endlich make
und du bist fertig Gebäude tree
für mac.
Tribut geht an [[22]}Shaun Chapman für seinen ursprünglichen Beitrag auf seinem Blog.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-01-12 03:19:56
Sie sollten wahrscheinlich homebrew verwenden. Wenn Sie tun:
brew install tree
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-06-30 16:30:36
Es gibt keinen formalen tree
Befehl an sich, aber Sie können dies tun:
Speichern Sie das folgende Skript in /usr/local/bin/tree -
#!/bin/bash
SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g'
if [ "$#" -gt 0 ] ; then
dirlist="$@"
else
dirlist="."
fi
for x in $dirlist; do
find "$x" -print | sed -e "$SEDMAGIC"
done
Ändern Sie die Berechtigungen, damit Sie sie ausführen können:
chmod 755 /usr/local/bin/tree
Natürlich müssen Sie möglicherweise /usr/local/bin
erstellen:
sudo mkdir -p /usr/local/bin/tree
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-01-21 22:17:18
Eine Alternative mit find
und awk
:
#!/bin/bash
find . -print 2>/dev/null | awk '!/\.$/ { \
for (i=1; i<NF; i++) { \
printf("%4s", "|") \
} \
print "-- "$NF \
}' FS='/'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2013-01-28 08:22:49
Ich habe hier eine einfache Lösung gefunden: http://murphymac.com/tree-command-for-mac/
Also füge Folgendes zu deinem hinzu .bashrc
, .bash_profile
oder an einem anderen Ort wird es funktionieren:
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
Wenn Sie nun einen Befehl tree
hinzufügen, wird Folgendes gedruckt:
# ~/my-html-app [13:03:45]$ tree
.
|____app.js
|____css
| |____main.css
| |____theme.css
|____index.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-10-16 15:06:27
Hier ist eine Ruby-Skriptlösung, die einen schönen Unicode-Baum zusammen mit nützlichen Metadaten erzeugt.
#!/usr/bin/env ruby
def tree_hierarchy( root, &children )
queue = [[root,"",true]]
[].tap do |results|
until queue.empty?
item,indent,last = queue.pop
kids = children[item]
extra = indent.empty? ? '' : last ? '└╴' : '├╴'
results << [ indent+extra, item ]
results << [ indent, nil ] if last and kids.empty?
indent += last ? ' ' : '│ '
parts = kids.map{ |k| [k,indent,false] }.reverse
parts.first[2] = true unless parts.empty?
queue.concat parts
end
end
end
def tree(dir)
cols = tree_hierarchy(File.expand_path(dir)) do |d|
File.directory?(d) ? Dir.chdir(d){ Dir['*'].map(&File.method(:expand_path)) } : []
end.map do |indent,path|
if path
file = File.basename(path) + File.directory?(path) ? '/' : ''
meta = `ls -lhd "#{path}"`.split(/\s+/)
[ [indent,file].join, meta[0], meta[4], "%s %-2s %s" % meta[5..7] ]
else
[indent]
end
end
maxs = cols.first.zip(*(cols[1..-1])).map{ |c| c.compact.map(&:length).max }
tmpl = maxs.map.with_index{ |n,i| "%#{'-' if cols[0][i][/^\D/]}#{n}s" }.join(' ')
cols.map{ |a| a.length==1 ? a.first : tmpl % a }
end
puts tree(ARGV.first || ".") if __FILE__==$0
Sie können die Zeile meta = …
ändern, um verschiedene Metadaten zu extrahieren, die angezeigt werden sollen, und die geteilten Teile in der nächsten Zeile von Hand auswählen. Mit etwas mehr Arbeit können Sie beliebige ls-Argumente übergeben, um die anzuzeigenden Metadaten auszuwählen.
Beispielausgabe (sieht im OS X-Terminal schöner aus als die Schriftart beim Stapelüberlauf):
phrogz$ tree UCC_IVI/
UCC_IVI/ drwxr-xr-x 510B Nov 20 11:07
├╴docs/ drwxr-xr-x 102B Nov 20 19:21
│ └╴CANMessages.txt -rwxr-xr-x 2.2K Nov 20 19:21
│
├╴effects/ drwxr-xr-x 204B Nov 19 17:19
│ ├╴Depth Of Field HQ Blur.effect -rwxr-xr-x 2.4K Nov 19 17:19
│ ├╴FXAA.effect -rwxr-xr-x 1.6K Nov 17 15:38
│ ├╴HDRBloomTonemap.effect -rwxr-xr-x 11K Nov 17 15:38
│ └╴SMAA1X.effect -rwxr-xr-x 4.4K Nov 19 17:19
│
├╴fonts/ drwxr-xr-x 136B Nov 17 15:38
│ ├╴Arimo-Regular.ttf -rwxr-xr-x 43K Nov 17 15:38
│ └╴OFL.txt -rwxr-xr-x 4.3K Nov 17 15:38
│
├╴maps/ drwxr-xr-x 238B Nov 19 17:19
│ ├╴alpha-maps/ drwxr-xr-x 136B Nov 17 15:38
│ │ ├╴rounded-boxes-3.png -rwxr-xr-x 3.6K Nov 17 15:38
│ │ └╴splatter-1.png -rwxr-xr-x 35K Nov 17 15:38
│ │
│ ├╴effects/ drwxr-xr-x 136B Nov 19 17:19
│ │ ├╴AreaTex-yflipped.dds -rwxr-xr-x 175K Nov 19 17:19
│ │ └╴SearchTex-yflipped.png -rwxr-xr-x 180B Nov 19 17:19
│ │
│ ├╴IBL/ drwxr-xr-x 136B Nov 17 15:38
│ │ ├╴028-hangar.hdr -rwxr-xr-x 1.5M Nov 17 15:38
│ │ └╴FieldAirport.hdr -rwxr-xr-x 1.5M Nov 17 15:38
│ │
│ ├╴icons/ drwxr-xr-x 238B Nov 19 17:19
│ │ ├╴icon_climate.dds -rwxr-xr-x 683K Nov 19 17:19
│ │ ├╴icon_music.dds -rwxr-xr-x 683K Nov 19 17:19
│ │ ├╴icon_navigation.dds -rwxr-xr-x 683K Nov 19 17:19
│ │ ├╴icon_phone.dds -rwxr-xr-x 683K Nov 19 17:19
│ │ └╴icon_surroundView.dds -rwxr-xr-x 683K Nov 19 17:19
│ │
│ └╴materials/ drwxr-xr-x 102B Nov 19 17:19
│ └╴spherical_checker.png -rwxr-xr-x 11K Nov 19 17:19
│
├╴materials/ drwxr-xr-x 102B Nov 19 17:19
│ └╴thin_glass_refractive.material -rwxr-xr-x 6.0K Nov 19 17:19
│
├╴models/ drwxr-xr-x 136B Nov 19 17:19
│ ├╴BokehParticle/ drwxr-xr-x 136B Nov 19 17:19
│ │ ├╴BokehParticle.import -rwxr-xr-x 739B Nov 19 17:19
│ │ └╴meshes/ drwxr-xr-x 102B Nov 19 17:19
│ │ └╴Mesh.mesh -rwxr-xr-x 1.1K Nov 19 17:19
│ │
│ └╴Glass_Button/ drwxr-xr-x 136B Nov 19 17:19
│ ├╴Glass_Button.import -rwxr-xr-x 1.2K Nov 19 17:19
│ └╴meshes/ drwxr-xr-x 136B Nov 19 17:19
│ ├╴GlassButton.mesh -rwxr-xr-x 44K Nov 19 17:19
│ └╴Icon.mesh -rwxr-xr-x 1.8K Nov 19 17:19
│
├╴scripts/ drwxr-xr-x 204B Nov 19 17:19
│ ├╴App.lua -rwxr-xr-x 764B Nov 17 15:38
│ ├╴CANSim.lua -rwxr-xr-x 29K Nov 17 15:38
│ ├╴ObjectWiggler.lua -rwxr-xr-x 3.7K Nov 19 17:19
│ └╴PathWiggler.lua -rwxr-xr-x 2.9K Nov 17 15:38
│
├╴states/ drwxr-xr-x 170B Nov 19 18:45
│ ├╴app-camera.scxml -rwxr-xr-x 2.4K Nov 20 11:07
│ ├╴app-navigation.scxml -rwxr-xr-x 590B Nov 19 18:32
│ └╴logic.scxml -rwxr-xr-x 4.2K Nov 19 18:59
│
├╴tests/ drwxr-xr-x 102B Nov 17 15:38
│ └╴interface-navigation.scxml-test -rwxr-xr-x 83B Nov 17 15:38
│
├╴UCC_IVI.uia -rwxr-xr-x 630B Nov 19 17:32
├╴UCC_IVI.uia-user -rwxr-xr-x 832B Nov 20 17:22
├╴UCC_IVI.uip -rwxr-xr-x 1.5K Nov 17 15:38
└╴UCC_Menu.uip -rwxr-xr-x 33K Nov 19 17:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2014-11-27 19:24:48
Hinzufügen eines kleinen Punktes zu @apuche ' s Antwort für OSX El Capitan rootless Feature. make install
schlägt fehl, da wir nicht in das Verzeichnis /usr/bin
schreiben dürfen.
vikas@MBP:~/Downloads/tree-1.7.0$ sudo make install
Password:
install -d /usr/bin
install: chmod 755 /usr/bin: Operation not permitted
install -d /usr/share/man/man1
if [ -e tree ]; then \
install tree /usr/bin/tree; \
fi
install: /usr/bin/tree: Operation not permitted
make: *** [install] Error 71
vikas@MBP:~/Downloads/tree-1.7.0$
Um dies zu überwinden, bearbeiten Sie einfach Makefile
, um prefix = /usr/local
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-04-13 12:45:30
Es ist nicht so hübsch wie gnu Baum ... aber es ist wirklich einfach, in bash zu alias ... Sie können sogar ein wenig Farbe hinzufügen, indem Sie die G-Option auf osx ls Farbe heften.
alias tree='find . -type d | ls -lARG'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-06-08 07:30:13
Installieren Sie Xcode
Get-Command Line Tools -
xcode-select --install
- Homebrew installieren
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Baum installieren
brew install tree
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-10-16 15:06:16
Spät zum Spiel, aber ich hatte die gleiche Frage. Aufgrund von Arbeitsplatzbeschränkungen konnte ich kein Paket von der Quelle oder über einen Paketmanager eines Drittanbieters installieren.
Dies ist meine Implementierung:
#!/usr/bin/env bash
#
# Faux tree command.
#
# Recursive directory/file listing of present working directory (PWD),
# with summary count of directories and files.
# Argument:
# Directory of interest,
# e.g.: tree /Users/foo/foo_dir
# Output:
# Recursive directory/file listing of named directory,
#
# Argument:
# Directory of interest, with user-defined level of resursive depth,
# e.g.: tree /System/Library 2
# Output:
# Recursive directory/file listing of named directory, stopping at
# user defined depth of recursion, e.g. 2
tree () {
[ -n "$2" ] && local depth="-maxdepth $2";
find "${1:-.}" "${depth}" -print 2> /dev/null | sed -e 's;
[^/]*/;|____;g;s;____|; |;g'
}
Fügen Sie einfach die Funktion zu /Users/foo/.profile
oder .bash_profile
,
aktualisieren Sie dann das Profil mit: source .profile
oder: source .bash_profile
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2021-01-07 17:41:14