Διαφορά μεταξύ των αναθεωρήσεων του «Ls»

Από The Stelios Files
μ
μ
Γραμμή 219: Γραμμή 219:
|| <span style="color:#525252;">'''-p'''</span>
|| <span style="color:#525252;">'''-p'''</span>
|| <span style="color:#525252;">Puts a slash after each file name if that file is a directory. This is useful when you pipe the output of the&nbsp;</span><span style="color:#525252;">'''ls'''</span><span style="color:#525252;">&nbsp;command to the&nbsp;</span><span style="color:#0f62fe;">'''pr'''</span><span style="color:#525252;">&nbsp;command, as follows:</span>
|| <span style="color:#525252;">Puts a slash after each file name if that file is a directory. This is useful when you pipe the output of the&nbsp;</span><span style="color:#525252;">'''ls'''</span><span style="color:#525252;">&nbsp;command to the&nbsp;</span><span style="color:#0f62fe;">'''pr'''</span><span style="color:#525252;">&nbsp;command, as follows:</span>
 
<syntaxhighlight lang="C#"  style="color:#dcdcdc; border: 1px solid; background-color:black;">
<span style="background-color:#1e1e1e;color:#dcdcdc;">ls -p | pr -5 -t -w80</span>
ls -p | pr -5 -t -w80
</syntaxhighlight>
|- style="background-color:#f4f4f4;border-top:0.75pt solid #f4f4f4;border-bottom:0.75pt solid #e0e0e0;border-left:none;border-right:none;padding:0cm;"
|- style="background-color:#f4f4f4;border-top:0.75pt solid #f4f4f4;border-bottom:0.75pt solid #e0e0e0;border-left:none;border-right:none;padding:0cm;"
|| <span style="color:#525252;">'''-q'''</span>
|| <span style="color:#525252;">'''-q'''</span>

Αναθεώρηση της 05:10, 10 Απριλίου 2022

1 Σκοπός

Εμφανίζει τα περιεχόμενα ενός καταλόγου.

2 Σύνταξη

Για να εμφανίσετε τα περιεχόμενα ενός καταλόγου ή το όνομα ενός αρχείου

ls [-1] [-A] [-C] [-E] [-F] [-H|-L] [-N] [-R] [-S] [-X] [-a] [-b] [-c] [-d] [-e] [-f] [-g] [-i] [-k] [-l] [-m] [-n] [-o] [-p] [-q] [-r] [-s] [-t] [-u] [-U] [-x] [Αρχείο...]

Για να εμφανίσετε τα περιεχόμενα του καταλόγου

ls -f [-C] [-d] [-i] [-m] [-s] [-X] [-x] [-1] [-U] [Κατάλογος...]

3 Περιγραφή

Η εντολή ls γράφει στην τυπική έξοδο τα περιεχόμενα κάθε καθορισμένης παραμέτρου καταλόγου ή το όνομα κάθε καθορισμένης παραμέτρου αρχείου, μαζί με όποια άλλη πληροφορία ζητάτε με τις σημαίες. Εάν δεν καθορίσετε μια παράμετρο Αρχείο ή Κατάλογος, η εντολή ls εμφανίζει τα περιεχόμενα του τρέχοντος καταλόγου.

Ο καθορισμός περισσότερων από μία από τις επιλογές στα αμοιβαία αποκλειστικά ζεύγη δεν θεωρείται σφάλμα. Η τελευταία επιλογή που καθορίζεται σε κάθε ζεύγος καθορίζει τη μορφή εξόδου.

Από προεπιλογή, η εντολή ls εμφανίζει όλες τις πληροφορίες με αλφαβητική σειρά κατά όνομα αρχείου. Η αλληλουχία ταξινόμησης καθορίζεται από τη μεταβλητή περιβάλλοντος LANG ή LC_COLLATE.

Όταν η εντολή ls εμφανίζει τα περιεχόμενα ενός καταλόγου, δεν εμφανίζει καταχωρήσεις για αρχεία των οποίων τα ονόματα αρχίζουν με . (κουκκίδα) εκτός αν χρησιμοποιείτε τη σημαία -a ή -A. Εάν η εντολή εκτελείται από τη ρίζα, χρησιμοποιεί τη σημαία -A από προεπιλογή.

Υπάρχουν τρεις κύριοι τρόποι μορφοποίησης εξόδου:* Λίστα με μία καταχώριση ανά γραμμή.

  • Λίστα με τις καταχωρήσεις σε πολλές στήλες καθορίζοντας είτε τη σημαία -C είτε -x. Η σημαία -C είναι η προεπιλεγμένη μορφή όταν η έξοδος είναι σε TTY. Η εντολή ls εμφανίζει έξοδο μιας στήλης εάν τα ονόματα αρχείων ή καταλόγων είναι πολύ μεγάλα.
  • Λίστα με τις καταχωρήσεις σε μια σειρά διαχωρισμένη με κόμμα, με τη σημαία -m.


Για να προσδιορίσετε τον αριθμό των θέσεων χαρακτήρων στη γραμμή εξόδου, η εντολή ls χρησιμοποιεί τη μεταβλητή περιβάλλοντος COLUMNS. Εάν αυτή η μεταβλητή δεν έχει οριστεί, η εντολή λαμβάνει την τρέχουσα τιμή στήλης της οθόνης. Εάν η εντολή ls δεν μπορεί να προσδιορίσει τον αριθμό των θέσεων χαρακτήρων με οποιαδήποτε από αυτές τις μεθόδους, χρησιμοποιεί μια προεπιλεγμένη τιμή 80.

Η λειτουργία που εμφανίζεται με τη σημαία -U είναι η ίδια με τη σημαία -l, εκτός από την προσθήκη ενός 11ου χαρακτήρα που ερμηνεύεται ως εξής:


Είδος Περιγραφή
E
Υποδεικνύει ότι ένα αρχείο έχει πληροφορίες εκτεταμένων χαρακτηριστικών Extended Attributes(EA).
Το EA ενός αρχείου εμφανίζεται χρησιμοποιώντας την εντολή getea.
- Υποδεικνύει ότι ένα αρχείο δεν έχει πληροφορίες εκτεταμένων χαρακτηριστικών.
e Υποδεικνύει ότι ένα αρχείο είναι κρυπτογραφημένο.


Η κρυπτογράφηση υπερισχύει της παρουσίας των λιστών ελέγχου πρόσβασης (Access Control Lists ACL) και άλλων EA.

Η λειτουργία που εμφανίζεται με τις σημαίες -e και -l ερμηνεύεται ως εξής:

Αν ο πρώτος χαρακτήρας είναι:


Είδος Περιγραφή
d Η καταχώρηση είναι ένας κατάλογος.
b Η καταχώρηση είναι ένα ειδικό αρχείο μπλοκ.
c Η καταχώρηση είναι ένα ειδικό αρχείο χαρακτήρων.
l Η καταχώρηση είναι ένας συμβολικός σύνδεσμος και είτε καθορίστηκε η σημαία -N είτε ο συμβολικός σύνδεσμος δεν έδειχνε ένα υπάρχον αρχείο.
p Η καταχώρηση είναι ένα ειδικό αρχείο first-in, first-out (FIFO).
s Η καταχώρηση είναι τοπική πρίζα (socket).
- Η καταχώρηση είναι ένα συνηθισμένο αρχείο.


Οι επόμενοι εννέα χαρακτήρες χωρίζονται σε τρία σετ των τριών χαρακτήρων το καθένα. Το πρώτο σύνολο τριών χαρακτήρων δείχνει την άδεια του ιδιοκτήτη. Το επόμενο σύνολο τριών χαρακτήρων δείχνει την άδεια των άλλων χρηστών στην ομάδα. Το τελευταίο σύνολο τριών χαρακτήρων δείχνει την άδεια οποιουδήποτε άλλου έχει πρόσβαση στο αρχείο. Οι τρεις χαρακτήρες σε κάθε σύνολο υποδεικνύουν, αντίστοιχα, άδεια ανάγνωσης, εγγραφής και εκτέλεσης του αρχείου. Η άδεια εκτέλεσης ενός καταλόγου σάς επιτρέπει να αναζητήσετε έναν κατάλογο για ένα καθορισμένο αρχείο.

Οι άδειες υποδεικνύονται ως εξής:


Είδος Περιγραφή
r Read-Ανάγνωση
w Write (edit)-Καταχώρηση (επεξεργασία)
x Execute (search)- Εκτέλεση (αναζήτηση)
- Corresponding permission not granted-Δεν χορηγήθηκε αντίστοιχη άδεια


Ο χαρακτήρας άδειας εκτέλεσης ομάδας είναι s εάν το αρχείο έχει λειτουργία set-group-ID. Ο τελευταίος χαρακτήρας της λειτουργίας (συνήθως x ή -) είναι T εάν έχει οριστεί το 01000 (οκταδικό) bit της λειτουργίας (δείτε την εντολή chmod για την έννοια αυτής της λειτουργίας). Οι ενδείξεις του set-ID και του 01000 bit της λειτουργίας γράφονται με κεφαλαία (S και T, αντίστοιχα) εάν δεν έχει οριστεί το αντίστοιχο δικαίωμα εκτέλεσης. Η λειτουργία t υποδηλώνει ότι το sticky bit είναι ενεργοποιημένο για το αρχείο ή τον κατάλογο.

Η λειτουργία που εμφανίζεται με τη σημαία -e είναι η ίδια με τη σημαία -l, εκτός από την προσθήκη ενός 11ου χαρακτήρα που ερμηνεύεται ως εξής:


Είδος Περιγραφή
+
Υποδεικνύει ότι ένα αρχείο έχει εκτεταμένες πληροφορίες ασφαλείας. Για παράδειγμα, το αρχείο μπορεί να έχει εκτεταμένα χαρακτηριστικά ACL, TCB ή TP στη λειτουργία.
Οι πληροφορίες ελέγχου πρόσβασης (ACL) ενός αρχείου εμφανίζονται χρησιμοποιώντας την εντολή aclget. Η τιμή των χαρακτηριστικών TCB και TP εμφανίζεται χρησιμοποιώντας την εντολή chtcb.
- Υποδεικνύει ότι ένα αρχείο δεν έχει εκτεταμένες πληροφορίες ασφαλείας.


Όταν παρατίθεται το μέγεθος των αρχείων σε έναν κατάλογο, η εντολή ls εμφανίζει έναν συνολικό αριθμό μπλοκ, συμπεριλαμβανομένων των έμμεσων μπλοκ.

4 Σημαίες

Είδος Περιγραφή
-A Lists all entries except . (dot) and .. (dot-dot).
-a Lists all entries in the directory, including the entries that begin with a . (dot).
-b Displays nonprintable characters in an octal (\nnn) notation.
-c Uses the time of last modification of the i-node for either sorting (when used with the -t flag) or for displaying (when used with the -l flag). This flag has no effect if it is not used with either the -t or -l flag, or both.
-C Sorts output vertically in a multicolumn format. This is the default method when output is to a terminal.
-d Displays only the information for the directory named. Directories are treated like files, which is helpful when using the -l flag to get the status of a directory.
-e Displays the mode (including security information), number of links, owner, group, size (in bytes), time of last modification, and name of each file. If the file is a special file, the size field contains the major and minor device numbers. If the file is a symbolic link, the path name of the linked-to file is printed preceded by a -> (minus, greater than) sign. The attributes of the symbolic link are displayed.
-E Lists extent attributes of a file that exists in Vxfs file systems, such as space reservation, fixed extent size, and extent allocation flag information. You must specify the -l flag with this flag; otherwise, the ls command ignores the -E flag and completes the execution.
-f Lists the name in each slot for each directory specified in the Directory parameter. This flag turns off the -l-t-s, and -r flags, and turns on the -a flag. The order of the listing is the order in which entries appear in the directory.
-F Puts a / (slash) after each file name if the file is a directory, an * (asterisk) if the file can be executed, an = (equal sign) if the file is a socket, a | (pipe) sign if the file is a FIFO, and an @ for a symbolic link. Symbolic links that are named as operands are not followed unless you have specified the -H or -L flag.
-g Displays the same information as the -l flag, except the -g flag suppresses display of the owner and symbolic link information.
-H If a symbolic link referencing a file of type directory is specified on the command line, the ls command shall evaluate the file information and file type to be those of the file referenced by the link, and not the link itself; however, the ls command shall write the name of the link itself and not the file referenced by the link.
-i Displays the i-node number in the first column of the report for each file. If the file system has an internal snapshot, the .snapshot directory and all its contents do not have unique i-node numbers.
-k Sets the block size for -s option and the per-directory block count written for -l-n-g, and -o options to 1024 bytes.
-L Lists the file or directory contents that the link references. This is the default action. Symbolic links are followed. If the -l option is used, the -N option becomes the default, and no symbolic links are followed. When the -l option is used, only the -L option can override the -N default.
-l (Lower case L) Displays the mode, number of links, owner, group, size (in bytes), and time of last modification for each file. If the file is a special file, the size field contains the major and minor device numbers. If the time of last modification is greater than six months ago, the time field is shown in the format month date year where as files modified within six months the time field is shown as month date time format.

If the file is a symbolic link, the path name of the linked-to file is printed preceded by a ->. The attributes of the symbolic link are displayed. The -n-g, and -o flag overrides the -l flag.

Notes:#
A symbolically linked file is followed by an arrow and the contents of the symbolic link.
  1. The performance of the ls command when used with the -l option can be improved by executing the mkpasswd command. This is helpful when a directory contains files owned by different users, such as the /tmp directory.


-m Uses stream output format (a comma-separated series).
-n Displays the same information as the -l flag, except that the -n flag displays the user and the group IDs instead of the user and group names.
-N
Does not follow symbolic links when determining the status of a file.

Note: If both the -L and -N options are used, the last one will dominate. Also, any time a symbolic link is given that includes a / (slash) as the final character, the link will automatically be followed regardless of any options used.

-o Displays the same information as the -l flag, except the -o flag suppresses display of the group and symbolic link information.
-p Puts a slash after each file name if that file is a directory. This is useful when you pipe the output of the ls command to the pr command, as follows:
ls  -p |  pr  -5  -t  -w80
-q Displays nonprintable characters in file names as a ? (question mark).
-r Reverses the order of the sort, giving reverse alphabetic or the oldest first, as appropriate.
-R Lists all subdirectories recursively.
-s Gives size in kilobytes (including indirect blocks) for each entry.
-S Sorts with the primary key being file size (in decreasing order) and the secondary key being file name in the collating sequence (in increasing order).
-t Sorts by time of last modification (latest first) instead of by name. For a symbolic link, the time used as the sort key is that of the symbolic link itself.
-U Displays similar information as the -l flag. Displays the mode (including security information, named extended attribute information and encryption information), number of links, owner, group, size (in bytes), time of last modification, and name of each file. If the file is a special file, the size field contains the major and minor device numbers. If the file is a symbolic link, the path name of the linked-to file is printed preceded by a -> (minus, greater than) sign. The attributes of the symbolic link are displayed.
-u Uses the time of the last access, instead of the time of the last modification, for either sorting (when used with the -t flag) or for displaying (when used with the -l flag). This flag has no effect if it is not used with either the -t or -l flag, or both.
-x Sorts output horizontally in a multi-column format.
-X Prints long user names when used with other flags that display user names. The upper limit is determined by the max_logname ODM attribute in the PdAt and CuAt object classes. If a user name is greater than the max_logname attribute, it will be truncated to the number of characters as specified by the max_logname attribute, less one character.
-1 Forces output into one-entry-per-line format. This is the default when the output is not directed to a terminal.


5 Πηγή