There are a amount of ways to watch documents on Linux, due to the fact, just after all, information on Linux are multifaceted. They have names, they have content material, they have entry permissions, and they have dates and times linked with their “delivery” (when they were originally added to the file method) as well as when they have been very last transformed and past accessed. This put up handles the commands that make it possible for you to perspective all these information.
Listing files
The easiest and most obvious way to listing information is with the ls command. By default, ls will listing information in the recent directory in identify get, but you can reverse that by including the -r possibility.
$ ls | head -3 4letters 4_vowel_words and phrases 4Vwords $ ls -r | head -3 zoom-mtg zodiac zipfiles.bat
You can list information in a tree-like vogue by applying the tree command. It will display screen the listing framework in a way that clearly indicates the directory ranges.
$ tree . │ ├── xtra │ │ ├── date │ │ ├── doit │ │ ├── dt │ │ ├── ex │ │ ├── loop
Additional facts on listing and viewing documents are offered at these web pages:
Viewing obtain permissions
The ls command with the -l option displays permissions in the “rwx” style. By introducing “a” to the alternatives, it will include files and directories that begin with a “,” (or else omitted).
$ ls -l | head -5 whole 120528 -rw-r-----. 1 shs shs 66040 Jul 5 2022 4letters -rw-r-----. 1 shs shs 174 Jul 8 2022 4_vowel_words and phrases -rw-r-----. 1 shs shs 174 Jul 8 2022 4Vwords -rw-r-----+ 1 shs shs 131310 Sep 19 2022 5letters $ ls -al | head -5 complete 133480 drwxr-xr-x. 103 shs shs 36864 May perhaps 6 11:43 . drwxr-xr-x. 25 root root 4096 Feb 17 11:36 .. -rw-r-----. 1 shs shs 66040 Jul 5 2022 4letters -rw-r-----. 1 shs shs 174 Jul 8 2022 4_vowel_phrases
You can use the getfacl command to involve additional file entry permissions.
$ getfacl 5letters # file: 5letters # proprietor: shs # team: shs consumer::rw- person:popeye:r-- <===== group::r-- mask::r-- other::---
Notice that the command output above shows one user (popeye) who has read access to the file without being a member of the associated group or the file having access permission for everyone.
More information on Linux permissions is available at these pages:
Examining file content
The cat, head and tail commands allow you to view file content. While cat will display the entire contents, you can pass the output to the more command to view a screenful at a time. The head and tail commands display lines at the top and bottom of text files.
$ cat alert REMINDER: This server will be shutting down @ 6PM tonight. Please finish your work by 5:45 and log off. $ cat 5letters | more aahed aalii aalst aalto aamsi … $ head -5 4letters 1080 10th AAAA AAAL AAAS $ tail -5 4letters zuza ZWEI zyga zyme Zysk
You can use the grep command to pick out lines that contain some content that you are looking for and nothing else. The grep command below displays only lines that begin with a “z”.
$ grep ^z 4letters | tail -5 zulu zuni zuza zyga zyme
More coverage on the head and tail commands can be viewed in this head and tail commands video.
The od command will display file contents in a very different fashion. It displays the characters along with their octal values – useful for troubleshooting.
$ od -bc alert 0000000 122 105 115 111 116 104 105 122 072 040 124 150 151 163 040 163 R E M I N D E R : T h i s s 0000020 145 162 166 145 162 040 167 151 154 154 040 142 145 040 163 150 e r v e r w i l l b e s h 0000040 165 164 164 151 156 147 040 144 157 167 156 040 100 040 066 120 u t t i n g d o w n @ 6 P 0000060 115 040 164 157 156 151 147 150 164 056 040 120 154 145 141 163 M t o n i g h t . P l e a s 0000100 145 040 146 151 156 151 163 150 040 171 157 165 162 012 011 167 e f i n i s h y o u r n t w 0000120 157 162 153 040 142 171 040 065 072 064 065 040 141 156 144 040 o r k b y 5 : 4 5 a n d 0000140 154 157 147 040 157 146 146 056 012 l o g o f f . n 0000151
More details on the grep command are available at The many faces of grep
Viewing file access times
The stat command displays the date of a file’s "birth" and when it was last changed and last accessed.
$ stat 4letters File: 4letters Size: 66040 Blocks: 136 IO Block: 4096 regular file Device: 8,17 Inode: 3015994 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ shs) Gid: ( 1000/ shs) Context: unconfined_u:object_r:user_home_t:s0 Access: 2023-05-06 12:14:49.279689941 -0400 Modify: 2022-07-05 10:06:54.798552673 -0400 Change: 2022-07-05 10:06:54.798552673 -0400 Birth: 2022-07-05 10:06:40.039362108 -0400
The date -r command can also be used to show a file’s last modification time, though it does so in a different format than the stat command.
$ date -r 4letters Tue Jul 5 10:06:54 AM EDT 2022
Wrap-up
A handy variety of Linux commands can help you see anything about files that you want to see. Try the commands in this post and you may find they they’re a lot more useful than you expected.