The ls command even has options for that. Sometimes a condensed file listing is more appropriate for the task at hand. rwxr-x- 1 shs shs 200 Aug 24 09:42 ckacct <= most recently used The "u" enforces the "by access date" listing order. To list files by access date (most recently accessed first), use the -ltu options. To sort files by the associated groups, you can pass the output from a long listing to the sort command and tell it to sort on column 4. If you’re curious about the difference, look at the output of the stat command. If you change permissions on a file and nothing else, -c will put that files at the top of the ls output while -t will not. The -c (change) and -t (modification) options will not always give the same results. Note that file change and modification times are different. I use this alias to show me a list of the files that I’ve most recently updated: $ alias recent='ls -ltr | tail -8' Add the -r option to get the most recently updated files showing up last in the list. Use the -t option to list files in order of age – how new they are. This sorting technique is useful for sorting file contents as well, not just listing files. Just be careful to add an “n” – -k5n – if you’re sorting on a field which is numeric or you'll be sorting in alphanumeric order. In fact, you can sort on any field this way (e.g., year). Srwxr-xr-x 1 root root 0 Aug 21 17:12 ntf_listenerc0c6b8b4567ĭrwxr-xr-x 2 root root 4096 Aug 21 17:12 hsperfdata_root ^ | If you want to list files by owner (e.g., in a shared directory), you can pass the output of the ls command to sort and pick out the owner column by adding -k3 to sort on the third field. Add the -r option to reverse this (i.e., ls -lSr). Notice that the default is to show the largest files first. When listing files by size, it's generally helpful to see that the command is doing what you asked. Note, however, that this won't actually show you the sizes (along with other file details) unless you also add the -l (long listing) option. If you want to list files in size order, add the -S option. You will get a listing like this one: $ ls -d */ġ/ backups/ modules/ projects/ templates/ If you want to list only directories, you can use the -d option. Listing directories onlyīy default, the ls command will show both files and directories. For example, it will list files without extensions first (in alphanumeric order) followed by files with extensions like. If you add the -X option, ls will sort files by name within each extension category. There is, however, a command option that can list files by extension. The ls command doesn’t analyze file types by content, but works with file names. This will be like turning the normal listing upside down. To reverse the listing of files by name, add the -r (reverse) option. Pipe the output of ls to the more command if you want to review your listing a screenful at a time. rw-rw-r- 1 shs shs 284003 Aesthetics_Thank_You.pdf You can choose the ls (no details) or ls -l (lots of details) to determine your view. Listing files by name (alphanumeric order) is, after all, the default. The easiest way to list files by name is simply to list them using the ls command.
0 Comments
Leave a Reply. |