4 strategies to look at documents and file permissions on Linux
[ad_1]
There are a variety of means to see files on Linux, simply because, right after all, documents on Linux are multifaceted. They have names, they have content material, they have entry permissions, and they have dates and occasions connected with their “start” (when they have been at first added to the file system) as well as when they were being previous improved and last accessed. This submit handles the commands that make it possible for you to look at all these details.
Listing data files
The most straightforward and most noticeable way to listing documents is with the ls command. By default, ls will checklist files in the latest listing in title purchase, but you can reverse that by incorporating the -r option.
$ ls | head -3 4letters 4_vowel_phrases 4Vwords $ ls -r | head -3 zoom-mtg zodiac zipfiles.bat
You can record information in a tree-like fashion by working with the tree command. It will exhibit the directory construction in a way that obviously signifies the directory degrees.
$ tree . │ ├── xtra │ │ ├── date │ │ ├── doit │ │ ├── dt │ │ ├── ex │ │ ├── loop
Far more info on listing and viewing files are accessible at these internet pages:
Viewing accessibility permissions
The ls command with the -l solution shows permissions in the “rwx” vogue. By introducing “a” to the choices, it will contain documents and directories that begin with a “,” (normally omitted).
$ ls -l | head -5 complete 120528 -rw-r-----. 1 shs shs 66040 Jul 5 2022 4letters -rw-r-----. 1 shs shs 174 Jul 8 2022 4_vowel_words -rw-r-----. 1 shs shs 174 Jul 8 2022 4Vwords -rw-r-----+ 1 shs shs 131310 Sep 19 2022 5letters $ ls -al | head -5 whole 133480 drwxr-xr-x. 103 shs shs 36864 May possibly 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_text
You can use the getfacl command to contain added file obtain permissions.
$ getfacl 5letters # file: 5letters # operator: shs # group: 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.
Copyright © 2023 IDG Communications, Inc.
[ad_2]
Source link