file
1. file.1.man
Manpage of FILE
FILE
Section: User Commands (1)Updated: Chronione prawem autorskim ale dystrybuowalne
Index Return to Main Contents
NAZWA
file - określenie typu plikuSKŁADNIA
file [ -bciknsvzL ] [ -f nazwapliku ] [ -m lista ] plik ...plik -C [ -m plikmag ]
OPIS
Ta strona podręcznika opisuje wersję 3.37 polecenia file.file sprawdza każdy ze swoich argumentów, próbując go sklasyfikować. Istnieją trzy zestawy testów, które są wykonywane w następującej kolejności: testy systemu plików, testy liczb magicznych, testy języka. Pierwszy zakończony powodzeniem test powoduje wypisanie typu pliku.
Wypisany typ będzie zwykle zawierał jedno ze słów text (plik zawiera tylko znaki drukowalne i kilka spośród znaków sterujących oraz prawdopodobnie można go bezpiecznie czytać na terminalu ASCII ), executable (wykonywalny -- plik zawiera wyniki kompilacji w formacie zrozumiałym dla jądra pewnego Uniksa lub innego systemu) lub data (dane) oznaczające cokolwiek innego (zwykle jest to binarny, niedrukowalny plik). Wyjątkami są ogólnie znane formaty plików (pliki core, archiwa tar), o których wiadomo, że zawierają dane binarne. Podczas modyfikacji pliku /usr/share/misc/magic lub też samego programu zachowaj te słowa kluczowe. Wielu polega na tym, że dla wszystkich czytelnych plików wypisywane jest słowo ,,text''. Nie należy więc robić tego, co zrobiono w Berkeley - zmieniono tam ,,shell commands text'' na ,,shell script''. Należy też zauważyć, że plik /usr/share/misc/magic jest tworzony mechanicznie z wielu małych plików z podkatalogu Magdir dystrybuowanych źródeł niniejszego programu.
Testy systemu plików są oparte o sprawdzanie wartości zwracanej przez funkcję systemową stat(2). Program sprawdza czy plik jest pusty oraz czy jest jakiegoś rodzaju plikiem specjalnym. Powinno się dać rozpoznać wszystkie rodzaje plików występujące w danym systemie (gniazda, dowiązania symboliczne, nazwane potoki (FIFO), itd.), o ile te rodzaje plików będą zdefiniowane w systemowym pliku nagłówkowym sys/stat.h.
Testy liczb magicznych służą do sprawdzania plików, które zawierają dane w określonym formacie. Kanonicznym tego przykładem jest wykonywalne binarium (skompilowany program) a.out, którego format jest zdefiniowany w a.out.h i prawdopodobnie w exec.h w standardowym katalogu plików nagłówkowych. Pliki te zawierają ,,liczby magiczne'' w określonym miejscu w pobliżu początku pliku. Liczby te informują uniksowy system operacyjny o tym, że plik jest wykonywalnym binarium oraz który z możliwych typów binariów reprezentuje. Koncepcja ,,liczb magicznych'' została jako rozszerzenie zastosowana również do plików z danymi. Można tak opisać każdy plik posiadający niezmienny identyfikator przy małym i określonym przesunięciu względem początku pliku. Informacje identyfikujące te pliki są odczytywane ze skompilowanego pliku liczb magicznych /usr/share/misc/magic.mgc lub z /usr/share/misc/magic, gdy skompilowany plik nie istnieje.
Jeśli plik nie pasuje do żadnego z wpisów w pliku liczb magicznych, dokonywane jest sprawdzenie czy jest to plik tekstowy. Rozpoznawane są zestawy znaków: ASCII, ISO-8859-x, 8-bitowe rozszerzenia ASCII niezgodne z ISO (używane w systemach Macintosh i IBM PC), Unicode w kodowaniu UTF-8, Unicode w kodowaniu UTF-16 oraz EBCDIC. Sprawdzane są zakresy i ciągi bajtów, które stanowią drukowalny tekst w każdym z tych zestawów znaków. Jeśli plik przejdzie któryś z tych testów, zgłaszany jest odpowiadający mu zestaw znaków. Pliki w ASCII, ISO-8859-x, UTF-8 oraz w rozszerzeniach ASCII są identyfikowane jako ,,text'', gdyż są one na ogół czytejne na dowolnym terminalu; pliki w UTF-16 i EBCDIC stanowią jedynie ,,character data'' (dane znakowe), gdyż jeśli zawierają one tekst, tekst ten wymaga przed przeczytaniem konwersji. Dodatkowo, file będzie próbował określić inne charakterystyki plików tekstowych. Jeśli wiersze są zakończone znakami CR, CRLF lub NEL, zamiast standardowego uniksowego LF, zostanie to zgłoszone. Zostaną również zidentyfikowane pliki zawierające wbudowane sekwencje unikowe lub wielokrotnego drukowania.
Po określeniu przez file zestawu znaków używanego w pliku tekstowym, spróbuje on odgadnąć w jakim języku plik został napisany. Testy językowe składają się z poszukiwań określonych łańcuchów znakowych (por. names.h), które mogą pojawić się gdziekolwiek w kilku pierwszych blokach pliku. Na przykład słowo kluczowe .br wskazuje, że plik jest najprawdopodobniek plikiem wejściowym dla programu troff(1) podobnie, jak struct wskazuje na program w C. Testy te są mniej godne zaufania niż poprzednie dwie grupy, więc są wykonywane na końcu. Testy językowe testują również niektóre pliki zbiorcze (jak archiwa tar(1)).
Plik, który nie może zostać określony jako jako zapisany w jednym z powyższych zestawów znaków, jest po prostu określany jako ,,data'' (dane).
OPCJE
- -b
- Nie podawanie nazw plików na początku wierszy wynikowych (tryb skrócony).
- -c
- Powoduje sprawdzanie wydruku przetworzonej postaci pliku magicznego. Jest to zwykle używane w połączeniu z aby odpluskwić plik liczb magicznych przed jego zainstalowaniem.
- -C
- Zapisuje plik wynikowy magic.mgc, który zawiera wstępnie przetworzoną wersję pliku.
- -f nazwapliku
- Odczytuje nazwy testowanych plików z nazwapliku (po jednym w wierszu) przed listą argumentów. Obecna musi być albo nazwapliku albo przynajmniej jeden argument będący nazwą pliku; aby testować standardowe wejście, należy użyć argumentu ,,-''jako nazwy pliku.
- -i
- Powoduje wypisywanie przez polecenie file łańcuchów stanowiących typy MIME, zamiast bardziej tradycyjnej postaci czytelnej dla człowieka. Zatem może ono raczej wypisać ,,text/plain; charset=us-ascii'' zamiast ,,ASCII text''. Aby ta opcja działała, file zmienia sposób w jaki obsługuje rozpoznane pliki (takie jak wiele typów plików tekstowych, katalogi itd.) oraz posługuje się alternatywnym plikiem ,,liczb magicznych''. (Zobacz sekcję ,,PLIKI'', poniżej.)
- -k
- Nie zatrzymuje się po znalezieniu pierwszego dopasowania, kontynuuje testowanie.
- -m lista
- Podaje alternatywną listę plików z liczbami magicznymi. Może to być pojedynczy plik lub rozdzielona dwukropkami lista plików.
- -n
- Wymusza wyprowadzenie danych wyjściowych po sprawdzeniu każdego pliku. Jest to przydatne jedynie podczas sprawdzania listy plików. W zamierzeniu ma być przydatne programom, które wymagają wyprowadzania typów plików w potoku.
- -v
- Drukuje informacje o wersji i kończy.
- -z
- Próbuje zaglądać do plików skompresowanych.
- -L
- powoduje, że program podąża za dowiązaniami symbolicznymi, podobnie jak w przypadku opcji ls(1) o identycznej nazwie (na systemach, które obsługują dowiązania symboliczne).
- -s
- Normalnie, file próbuje czytać i określać rodzaj pliku jedynie dla tych argumentów, które są plikami zgłoszonymi przez stat(2) jako zwykłe pliki. Pozwala to uniknąć problemów, gdyż czytanie plików specjalnych może mie nieprzyjemne konsekwencje. Podanie opcji -s powoduje, że file czyta również argumenty będące plikami specjalnymi urządzeń blokowych i znakowych. Jest to przydatne do określania rodzaju systemu plików w przypadku danych na surowych partycjach dysków, stanowiących pliki specjalne urządzeń blokowych. Opcja ta powoduje również, że file nie zważa na zgłaszany przez stat(2) rozmiar pliku, gdyż w niektórych systemach funkcja ta zgłasza zero dla surowych partycji dysków.
PLIKI
/usr/share/misc/magic.mgc - domyślna skompilowana lista liczb magicznych/usr/share/misc/magic - domyślna lista liczb magicznych
/usr/share/misc/magic.mime - domyślna lista liczb magicznych, służąca do wypisywania typów MIME w przypadku podania opcji -i.
ŚRODOWISKO
Zmienna środowiskowa MAGIC ustawia domyślny plik liczb magicznych.ZOBACZ TAKŻE
magic(5) - opis formatu pliku liczb magicznych.strings(1), od(1), hexdump(1) - narzędzia do testowania plików nietekstowych.
ZGODNOŚĆ ZE STANDARDAMI
Program ten prawdopodobnie wykracza poza definicję FILE(CMD) z definicji interfejsu Systemu V (System V Interface Definition). Wydaje się tak przynajmniej z tego, co można zrozumieć z tamtejszego niejasnego języka... Zachowanie programu jest w większości zgodne z zachowaniem programu z Systemu V o tej samej nazwie. Wersja niniejsza zna więcej magii, więc będzie dawała w wielu wypadkach inne (dokładniejsze) wyniki.
Jedną z istotnych różnic między tą wersją i wersją z Systemu V, jest to,
że niniejsza
wersja traktuje białe znaki jako separatory, więc spacje w łańcuchach
wzorców muszą być chronione (przez odwrotny ukośnik). Na przykład,
>10 string language impress (imPRESS data)
w istniejącym pliku magicznym musiało by być zmienione na
>10 string language\ impress (imPRESS data)
Dodatkowo, w tej wersji, jeśli łańcuch wzorca zawiera odwrotny ukośnik, to
musi być on chroniony. Na przykład
0 string \begindata Andrew Toolkit document
w istniejącym pliku magicznym musiało by być zmienione na
0 string \\begindata Andrew Toolkit document
Wersja 3.2 SunOS i późniejsze pochodzące z Sun Microsystems zawierają
polecenie
file(1),
wywodzące się z polecenia z System V, lecz z pewnymi rozszerzeniami. Moja
wersja różni się od Sun-owskiej tylko małymi szczegółami. Zawiera ona
rozszerzenie operatora `&', używanego jako np.
>16 long&0x7fffffff >0 not stripped
KATALOG MAGICZNY
Wpisy w pliku liczb magicznych pochodzą z wielu źródeł, głównie z USENET-u i zgłoszone przez różnych autorów. Christos Zoulas (adres poniżej) będzie zbierał dodatkowe lub poprawione wpisy pliku liczb magicznych. Zebrane wpisy będą okresowo dystrybuowane.Kolejność wpisów w pliku magicznym jest istotna. Zależnie od używanego systemu, kolejność, w której są ułożone, może być nieprawidłowa. Jeśli stare polecenie file używa pliku magicznego, warto zachować stary plik magiczny dla porównania (zmieniając jego nazwę na /usr/share/misc/magic.orig).
PRZYKŁADY
$ file file.c file /dev/hda
file.c: C program text
file: ELF 32-bit LSB executable, Intel 80386, version 1,
dynamically linked, not stripped
/dev/hda: block special
$ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10}
/dev/hda: x86 boot sector
/dev/hda1: Linux/i386 ext2 filesystem
/dev/hda2: x86 boot sector
/dev/hda3: x86 boot sector, extended partition table
/dev/hda4: Linux/i386 ext2 filesystem
/dev/hda5: Linux/i386 swap file
/dev/hda6: Linux/i386 swap file
/dev/hda7: Linux/i386 swap file
/dev/hda8: Linux/i386 swap file
/dev/hda9: empty
/dev/hda10: empty
$ file -i file.c file /dev/hda
file.c: text/x-c
file: application/x-executable, dynamically linked (uses shared libs), not stripped
/dev/hda: application/x-not-regular-file
HISTORIA
Polecenie file istniało w każdym systemie UNIX od przynajmniej wersji Research Version 6 (strona podręcznika man z 16 stycznia 1975). Wersja z Systemu V wprowadziła jedną istotną główną zmianę: zewnętrzną listę typów liczb magicznych. Spowolniło to trochę program, lecz uczyniło go bardziej elastycznym.Program ten, oparty na wersji z Systemu V, został napisany przez Iana Darwina <ian@darwinsys.com> bez zaglądania do innych źródeł.
John Gilmore przerobił mocno ten kod, czyniąc go lepszym niż pierwsza wersja. Geoff Collyer znalazł kilka nietrafności i dostarczył trochę wpisów w pliku liczb magicznych. Zmiana obsługi operatora ,,&'' przez Roba McMahona, cudcv@warwick.ac.uk, w 1989.
Guy Harris, guy@netapp.com, wykonał wiele zmian w okresie od 1993 do dzisiaj.
Podstawowy rozwój i konserwację w okresie od 1990 do dzisiaj prowadzi Christos Zoulas (christos@astron.com).
Zmodyfikowany przez Chrisa Lowtha, chris@lowth.com, w 2000: Obsługa opcji ,,-i'' powodującej wyprowadzanie łańcuchów typów MIME oraz korzystającej z alternatywnego pliku liczb magicznych i wbudowanej logiki.
Zmodyfikowany przez Erica Fischera (enf@pobox.com), w lipcu 2000, aby rozpoznawał kody znaków i próbował zidentyfikować język plików nie-ASCII.
Lista osób, które wniosły wkład do katalogu "Magdir" (źródła pliku /etc/magic) jest za długa, aby ją ty przytaczać. Wiecie kim jesteście; dziękujemy.
NOTKA PRAWNA
Copyright (c) Ian F. Darwin, Toronto, Canada, 1986-1999. Na standardowej licencji Berkeley Software Distribution; znajduje się ona w pliku LEGAL.NOTICE dystrybyowanych źródeł.Pliki tar.h oraz is_tar.c zostały napisane przez Johna Gilmore'a a pochodzą z jego ogólnie dostępnego programu tar, i nie podlegają powyższej licencji.
BŁĘDY
Musi istnieć lepszy sposób na zautomatyzowanie konstrukcji pliku liczb magicznych ze wszystkiego w Magdir. Jaki to sposób? Co więcej, plik magiczny powinien być kompilowany do binarium (powiedzmy, ndbm(3) lub jeszcze lepiej, do ASCII o stałej długości łańcuchów znakowych do użytku w heterogenicznych środowiskach sieciowych) w celu szybszego uruchamiania. Wtedy program działałby tak szybko, jak program o tej samej nazwie z Wersji 7, z elastycznością wersji z Systemu V.file używa kilku algorytmów, które przedkładają szybkość nad dokładność, więc może zostać zmylony co do zawarotści plików tekstowych.
Obsługa plików tekstowych (przede wszystkim dla języków programowania) jest uproszczona, nieefektywna a do aktualizacji wymaga rekompilacji.
Powinnna istnieć klauzula ,,else'', aby obsłużyć kontynuacje linii.
Plik liczb magicznych i słowa kluczowe powinny obsługiwać wyrażenia regularne. Używanie przez nie znaku ASCII TAB jako separatora pól jest paskudne i utrudnia edycję plików, ale jest już zakorzenione.
Może być zalecanym zezwolenie na występowanie wielkich liter w słowach kluczowych, np. polecenia troff(1) vs makra stron podręcznika man. Obsługa wyrażeń regularnych ułatwiłaby to.
Program nie identyfikuje poprawnie FORTRANu. Powinno być możliwe rozpoznawanie FORTRANu przez wyszukanie pewnych słów kluczowych, które pojawiają się po wcięciach na początku linii. Obsługa wyrażeń regularnych ułatwiłaby to.
Lista słów kluczowych w ascmagic prawdopodobnie przynależy do pliku liczb magicznych. Można to zrobić poprzez użycie jakiegoś słowa kluczowego, w rodzaju ,,*'' jako wartości przesunięcia w pliku.
Inną optymalizacją byłoby sortowanie pliku magicznego w ten sposób, by można było przelecieć wszystkie testy pierwszego bajtu, pierwszego słowa, pierwszego podwójnego słowa itd., gdy tylko zostanie on załadowany. Narzekania na konflikty we wpisach plików magicznych. Ustalenie zasady, że wpisy w pliku liczb magicznych są sortowane w oparciu o przesunięcie w badanym pliku, nie zaś o pozycję wewnątrz pliku magicznego?
Program powinien umożliwić ocenę, ,,jak dobre'' było zgadnięcie. Kończymy na usuwaniu zgadnięć (np. ,,From '' jako pierwsze 5 znaków w pliku), ponieważ nie są one tak dobre jak inne zgadnięcia (np. ,,Newsgroups:'' vs ,,Return-Path:''). Jednak wciąż, jeśli inne nie będą pasować, powinno być możliwe użycie pierwszych zgadnięć.
Program ten jest wolniejszy niż polecenia file niektórych dystrybutorów. Nowa obsługa kodów wieloznakowych czyni go jeszcze wolniejszym.
Ta strona podręcznika man, a szczególnie ta sekcja, jest zbyt długa.
DOSTĘPNOŚĆ
Najnowszą oryginalną wersję programu tego autora można pobrać z anonimowego ftp z ftp.astron.com z katalogu /pub/file/file-X.YY.tar.gz
Index
- NAZWA
- SKŁADNIA
- OPIS
- OPCJE
- PLIKI
- ŚRODOWISKO
- ZOBACZ TAKŻE
- ZGODNOŚĆ ZE STANDARDAMI
- KATALOG MAGICZNY
- PRZYKŁADY
- HISTORIA
- NOTKA PRAWNA
- BŁĘDY
- DOSTĘPNOŚĆ
This document was created by man2html using the manual pages.
Time: 00:24:51 GMT, November 20, 2008
2. file.9.man
Manpage of file
file
Section: Tcl Built-In Commands (n)Updated: 8.3
Index Return to Main Contents
NAME
file - Manipulate file names and attributesSYNOPSIS
file option name ?arg arg ...?DESCRIPTION
This command provides several operations on a file's name or attributes. Name is the name of a file; if it starts with a tilde, then tilde substitution is done before executing the command (see the manual entry for filename for details). Option indicates what to do with the file name. Any unique abbreviation for option is acceptable. The valid options are:
- file atime name ?time?
- Returns a decimal string giving the time at which file name was last accessed. If time is specified, it is an access time to set for the file. The time is measured in the standard POSIX fashion as seconds from a fixed starting time (often January 1, 1970). If the file doesn't exist or its access time cannot be queried or set then an error is generated. On Windows, FAT file systems do not support access time.
- file attributes name
- file attributes name ?option?
- file attributes name ?option value option value...?
-
-
This subcommand returns or sets platform specific values associated
with a file. The first form returns a list of the platform specific
flags and their values. The second form returns the value for the
specific option. The third form sets one or more of the values. The
values are as follows:
On Unix, -group gets or sets the group name for the file. A group id can be given to the command, but it returns a group name. -owner gets or sets the user name of the owner of the file. The command returns the owner name, but the numerical id can be passed when setting the owner. -permissions sets or retrieves the octal code that chmod(1) uses. This command does also has limited support for setting using the symbolic attributes for chmod(1), of the form [ugo]?[[+-=][rwxst],[...]], where multiple symbolic attributes can be separated by commas (example: u+s,go-rw add sticky bit for user, remove read and write permissions for group and other). A simplified ls style string, of the form rwxrwxrwx (must be 9 characters), is also supported (example: rwxr-xr-t is equivalent to 01755).
On Windows, -archive gives the value or sets or clears the archive attribute of the file. -hidden gives the value or sets or clears the hidden attribute of the file. -longname will expand each path element to its long version. This attribute cannot be set. -readonly gives the value or sets or clears the readonly attribute of the file. -shortname gives a string where every path element is replaced with its short (8.3) version of the name. This attribute cannot be set. -system gives or sets or clears the value of the system attribute of the file.
On Macintosh, -creator gives or sets the Finder creator type of the file. -hidden gives or sets or clears the hidden attribute of the file. -readonly gives or sets or clears the readonly attribute of the file. Note that directories can only be locked if File Sharing is turned on. -type gives or sets the Finder file type for the file.
-
This subcommand returns or sets platform specific values associated
with a file. The first form returns a list of the platform specific
flags and their values. The second form returns the value for the
specific option. The third form sets one or more of the values. The
values are as follows:
- file channels ?pattern?
- If pattern isn't specified, returns a list of names of all registered open channels in this interpreter. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match.
- file copy ?-force? ?--? source target
- file copy ?-force? ?--? source ?source ...? targetDir
-
- The first form makes a copy of the file or directory source under the pathname target. If target is an existing directory, then the second form is used. The second form makes a copy inside targetDir of each source file listed. If a directory is specified as a source, then the contents of the directory will be recursively copied into targetDir. Existing files will not be overwritten unless the -force option is specified. When copying within a single filesystem, file copy will copy soft links (i.e. the links themselves are copied, not the things they point to). Trying to overwrite a non-empty directory, overwrite a directory with a file, or overwrite a file with a directory will all result in errors even if -force was specified. Arguments are processed in the order specified, halting at the first error, if any. A -- marks the end of switches; the argument following the -- will be treated as a source even if it starts with a -.
- file delete ?-force? ?--? pathname ?pathname ... ?
- Removes the file or directory specified by each pathname argument. Non-empty directories will be removed only if the -force option is specified. When operating on symbolic links, the links themselves will be deleted, not the objects they point to. Trying to delete a non-existent file is not considered an error. Trying to delete a read-only file will cause the file to be deleted, even if the -force flags is not specified. If the -force option is specified on a directory, Tcl will attempt both to change permissions and move the current directory 'pwd' out of the given path if that is necessary to allow the deletion to proceed. Arguments are processed in the order specified, halting at the first error, if any. A -- marks the end of switches; the argument following the -- will be treated as a pathname even if it starts with a -.
- file dirname name
-
Returns a name comprised of all of the path components in name
excluding the last element. If name is a relative file name and
only contains one path element, then returns ``.'' (or ``:''
on the Macintosh). If name refers to a root directory, then the
root directory is returned. For example,
-
-
file dirname c:/
Note that tilde substitution will only be performed if it is necessary to complete the command. For example,
-
file dirname ~/src/foo.c
-
file dirname ~
-
-
- file executable name
- Returns 1 if file name is executable by the current user, 0 otherwise.
- file exists name
- Returns 1 if file name exists and the current user has search privileges for the directories leading to it, 0 otherwise.
- file extension name
- Returns all of the characters in name after and including the last dot in the last element of name. If there is no dot in the last element of name then returns the empty string.
- file isdirectory name
- Returns 1 if file name is a directory, 0 otherwise.
- file isfile name
- Returns 1 if file name is a regular file, 0 otherwise.
- file join name ?name ...?
-
Takes one or more file names and combines them, using the correct path
separator for the current platform. If a particular name is
relative, then it will be joined to the previous file name argument.
Otherwise, any earlier arguments will be discarded, and joining will
proceed from the current argument. For example,
-
-
file join a b /foo bar
Note that any of the names can contain separators, and that the result is always canonical for the current platform: / for Unix and Windows, and : for Macintosh.
-
-
- file link ?-linktype? linkName ?target?
- If only one argument is given, that argument is assumed to be linkName, and this command returns the value of the link given by linkName (i.e. the name of the file it points to). If linkName isn't a link or its value cannot be read (as, for example, seems to be the case with hard links, which look just like ordinary files), then an error is returned. If 2 arguments are given, then these are assumed to be linkName and target. If linkName already exists, or if target doesn't exist, an error will be returned. Otherwise, Tcl creates a new link called linkName which points to the existing filesystem object at target, where the type of the link is platform-specific (on Unix a symbolic link will be the default). This is useful for the case where the user wishes to create a link in a cross-platform way, and doesn't care what type of link is created. If the user wishes to make a link of a specific type only, (and signal an error if for some reason that is not possible), then the optional -linktype argument should be given. Accepted values for -linktype are "-symbolic" and "-hard". When creating links on filesystems that either do not support any links, or do not support the specific type requested, an error message will be returned. In particular Windows 95, 98 and ME do not support any links at present, but most Unix platforms support both symbolic and hard links (the latter for files only), MacOS supports symbolic links and Windows NT/2000/XP (on NTFS drives) support symbolic directory links and hard file links.
- file lstat name varName
- Same as stat option (see below) except uses the lstat kernel call instead of stat. This means that if name refers to a symbolic link the information returned in varName is for the link rather than the file it refers to. On systems that don't support symbolic links this option behaves exactly the same as the stat option.
- file mkdir dir ?dir ...?
- Creates each directory specified. For each pathname dir specified, this command will create all non-existing parent directories as well as dir itself. If an existing directory is specified, then no action is taken and no error is returned. Trying to overwrite an existing file with a directory will result in an error. Arguments are processed in the order specified, halting at the first error, if any.
- file mtime name ?time?
- Returns a decimal string giving the time at which file name was last modified. If time is specified, it is a modification time to set for the file (equivalent to Unix touch). The time is measured in the standard POSIX fashion as seconds from a fixed starting time (often January 1, 1970). If the file doesn't exist or its modified time cannot be queried or set then an error is generated.
- file nativename name
- Returns the platform-specific name of the file. This is useful if the filename is needed to pass to a platform-specific call, such as exec under Windows or AppleScript on the Macintosh.
- file normalize name
-
- Returns a unique normalized path representation for the file-system object (file, directory, link, etc), whose string value can be used as a unique identifier for it. A normalized path is an absolute path which has all '../', './' removed. Also it is one which is in the ``standard'' format for the native platform. On MacOS, Unix, this means the segments leading up to the path must be free of symbolic links/aliases (but the very last path component may be a symbolic link), and on Windows it also means we want the long form with that form's case-dependence (which gives us a unique, case-dependent path). The one exception concerning the last link in the path is necessary, because Tcl or the user may wish to operate on the actual symbolic link itself (for example 'file delete', 'file rename', 'file copy' are defined to operate on symbolic links, not on the things that they point to).
- file owned name
- Returns 1 if file name is owned by the current user, 0 otherwise.
- file pathtype name
- Returns one of absolute, relative, volumerelative. If name refers to a specific file on a specific volume, the path type will be absolute. If name refers to a file relative to the current working directory, then the path type will be relative. If name refers to a file relative to the current working directory on a specified volume, or to a specific file on the current working volume, then the path type is volumerelative.
- file readable name
- Returns 1 if file name is readable by the current user, 0 otherwise.
- file readlink name
- Returns the value of the symbolic link given by name (i.e. the name of the file it points to). If name isn't a symbolic link or its value cannot be read, then an error is returned. On systems that don't support symbolic links this option is undefined.
- file rename ?-force? ?--? source target
- file rename ?-force? ?--? source ?source ...? targetDir
-
- The first form takes the file or directory specified by pathname source and renames it to target, moving the file if the pathname target specifies a name in a different directory. If target is an existing directory, then the second form is used. The second form moves each source file or directory into the directory targetDir. Existing files will not be overwritten unless the -force option is specified. When operating inside a single filesystem, Tcl will rename symbolic links rather than the things that they point to. Trying to overwrite a non-empty directory, overwrite a directory with a file, or a file with a directory will all result in errors. Arguments are processed in the order specified, halting at the first error, if any. A -- marks the end of switches; the argument following the -- will be treated as a source even if it starts with a -.
- file rootname name
- Returns all of the characters in name up to but not including the last ``.'' character in the last component of name. If the last component of name doesn't contain a dot, then returns name.
- file separator ?name?
- If no argument is given, returns the character which is used to separate path segments for native files on this platform. If a path is given, the filesystem responsible for that path is asked to return its separator character. If no file system accepts name, an error is generated.
- file size name
- Returns a decimal string giving the size of file name in bytes. If the file doesn't exist or its size cannot be queried then an error is generated.
- file split name
-
Returns a list whose elements are the path components in name. The
first element of the list will have the same path type as name.
All other elements will be relative. Path separators will be discarded
unless they are needed ensure that an element is unambiguously relative.
For example, under Unix
-
-
file split /foo/~bar/baz
-
-
- file stat name varName
- Invokes the stat kernel call on name, and uses the variable given by varName to hold information returned from the kernel call. VarName is treated as an array variable, and the following elements of that variable are set: atime, ctime, dev, gid, ino, mode, mtime, nlink, size, type, uid. Each element except type is a decimal string with the value of the corresponding field from the stat return structure; see the manual entry for stat for details on the meanings of the values. The type element gives the type of the file in the same form returned by the command file type. This command returns an empty string.
- file system name
- Returns a list of two elements, the first of which is the name of the filesystem to use for the file, and the second an arbitrary string representing the filesystem-specific nature or type of the location within that filesystem. If a filesystem only supports one type of file, the second element may be null. For example the native files have a first element 'native', and a second element which is a platform-specific type name for the file's system (e.g. 'NTFS', 'FAT', etc), or possibly the empty string if no further information is available or if this is not implemented. A generic virtual file system might return the list 'vfs ftp' to represent a file on a remote ftp site mounted as a virtual filesystem through an extension called 'vfs'. If the file does not belong to any filesystem, an error is generated.
- file tail name
- Returns all of the characters in name after the last directory separator. If name contains no separators then returns name.
- file type name
- Returns a string giving the type of file name, which will be one of file, directory, characterSpecial, blockSpecial, fifo, link, or socket.
- file volumes
- Returns the absolute paths to the volumes mounted on the system, as a proper Tcl list. On the Macintosh, this will be a list of the mounted drives, both local and network. N.B. if two drives have the same name, they will both appear on the volume list, but there is currently no way, from Tcl, to access any but the first of these drives. On UNIX, the command will always return "/", since all filesystems are locally mounted. On Windows, it will return a list of the available local drives (e.g. {a:/ c:/}).
- file writable name
- Returns 1 if file name is writable by the current user, 0 otherwise.
PORTABILITY ISSUES
- Unix
- These commands always operate using the real user and group identifiers, not the effective ones.
EXAMPLES
This procedure shows how to search for C files in a given directory that have a correspondingly-named object file in the current directory:-
proc findMatchingCFiles {dir} { set files {} switch $::tcl_platform(platform) { windows { set ext .obj } unix { set ext .o } } foreach file [glob -nocomplain -directory $dir *.c] { set objectFile [file tail [file rootname $file]]$ext if {[file exists $objectFile]} { lappend files $file } } return $files }
Rename a file and leave a symbolic link pointing from the old location to the new place:
-
set oldName foobar.txt set newName foo/bar.txt # Make sure that where we're going to move to exists... if {![file isdirectory [file dirname $newName]]} { file mkdir [file dirname $newName] } file rename $oldName $newName file link -symbolic $oldName $newName
SEE ALSO
filename(n), open(n), close(n), eof(n), gets(n), tell(n), seek(n), fblocked(n), flush(n)KEYWORDS
attributes, copy files, delete files, directory, file, move files, name, rename files, stat
Index
This document was created by man2html using the manual pages.
Time: 00:24:51 GMT, November 20, 2008





