Linux list files attributes

Can you show/list all extended-attributes and how?

The -m ^ matches start of any string without need for escaping the parameter and double dash — is needed as a separator in case the filename or directory starts with a dash.

This is technically not correct. Try using getfattr to list xattrs in the system namespace on an NTFS filesystem mounted via the ntfs-3g driver. Even as root they are not listed. However, one can get the value of the xattr, eg. system.ntfs_acl , if specifying the name of the xattr explicitly via the -n parameter. I’ve yet to see a way to have the system xattrs listed.

getfattr is not present in my debian distribution. I use this instead:

That is different attributes. «lsattr» lists «file attributes» which is a specific set of attributes available on ext* file systems. «getfattr» lists «extended attributes» which is a kind of name-value pairs available on several file systems. See the respective manual pages for details.

This is misleading. The getfattr command is an official part of Ubuntu, and presumably Debian, but is in the attr package, which is not installed by default. Use apt install attr to get it. And it is indeed different than lsattr as noted by Göran.

I-node flags (ext2 extended file attributes) is derived from the ext2 file system, but nowadays it is also available on other file systems. A minor supplement to @GöranUddeborg’s comment.

On a MacOs the Unix flavor is Darwin which is derived from BSD. In this version of Unix, use the command xattr to list (or create, write, or clear) the extended attributes.

xattr will just list the names of the attributes

xattr -l will list their names and values

xattr -h for a more succinct help message

man xattr for a detailed help message ( ZZ to exit the help)

The command to list all extended attributes is ls -l@ .

An example (from my mac, linux/BSD will look different):

felixphew-mbp:/ felixphew$ ls -l@ total 45 drwxrwxr-x+ 63 root admin 2142 27 Dec 17:49 Applications drwxr-xr-x+ 62 root wheel 2108 16 Nov 06:25 Library drwxr-xr-x@ 2 root wheel 68 10 Sep 06:47 Network com.apple.FinderInfo 32 drwxr-xr-x+ 4 root wheel 136 1 Nov 14:02 System drwxr-xr-x 6 root admin 204 28 Dec 07:36 Users drwxrwxrwt@ 3 root admin 102 30 Dec 06:40 Volumes com.apple.FinderInfo 32 drwxr-xr-x@ 39 root wheel 1326 11 Nov 07:06 bin com.apple.FinderInfo 32 drwxrwxr-t@ 2 root admin 68 10 Sep 06:47 cores com.apple.FinderInfo 32 dr-xr-xr-x 3 root wheel 4306 30 Dec 06:40 dev lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:56 etc -> private/etc com.apple.FinderInfo 32 dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 home -rw-r--r--@ 1 root wheel 313 1 Oct 16:12 installer.failurerequests com.apple.FinderInfo 32 dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 net drwxr-xr-x@ 3 root wheel 102 12 Aug 07:19 opt com.apple.FinderInfo 32 drwxr-xr-x@ 6 root wheel 204 1 Nov 14:05 private com.apple.FinderInfo 32 drwxr-xr-x@ 59 root wheel 2006 18 Nov 07:46 sbin com.apple.FinderInfo 32 drwxr-xr-x@ 3 root wheel 102 22 Dec 07:46 srv com.apple.FinderInfo 32 lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 tmp -> private/tmp com.apple.FinderInfo 32 drwxr-xr-x@ 13 root wheel 442 23 Nov 11:20 usr com.apple.FinderInfo 32 lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 var -> private/var com.apple.FinderInfo 32 
felixphew-mbp:/ felixphew$ ls -l total 45 drwxrwxr-x+ 63 root admin 2142 27 Dec 17:49 Applications drwxr-xr-x+ 62 root wheel 2108 16 Nov 06:25 Library drwxr-xr-x@ 2 root wheel 68 10 Sep 06:47 Network drwxr-xr-x+ 4 root wheel 136 1 Nov 14:02 System drwxr-xr-x 6 root admin 204 28 Dec 07:36 Users drwxrwxrwt@ 3 root admin 102 30 Dec 06:40 Volumes drwxr-xr-x@ 39 root wheel 1326 11 Nov 07:06 bin drwxrwxr-t@ 2 root admin 68 10 Sep 06:47 cores dr-xr-xr-x 3 root wheel 4306 30 Dec 06:40 dev lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:56 etc -> private/etc dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 home -rw-r--r--@ 1 root wheel 313 1 Oct 16:12 installer.failurerequests dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 net drwxr-xr-x@ 3 root wheel 102 12 Aug 07:19 opt drwxr-xr-x@ 6 root wheel 204 1 Nov 14:05 private drwxr-xr-x@ 59 root wheel 2006 18 Nov 07:46 sbin drwxr-xr-x@ 3 root wheel 102 22 Dec 07:46 srv lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 tmp -> private/tmp drwxr-xr-x@ 13 root wheel 442 23 Nov 11:20 usr lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 var -> private/var 

Источник

Читайте также:  Install telegram linux debian

Stat Command: Display Attributes of Files and Directories

You can get file permissions, size, mtime, ctime, atime, ownership and several other file attribute information using the stat command in Linux.

What if I told you there is a better way to check file attributes? It’s a simple but useful command called stat.

stat command in Linux

Stat Command

The stat command lists important attributes of files and directories. It can also display information on the filesystem, instead of the files.

There are only a few options with stat command:

  • -f : Show the information for the filesystem instead of the file
  • -L : Follow symbolic links and show information on the file they point to
  • -t : Terse mode prints the information in a single line

Using stat command to get file information

Here’s a sample output if you use the stat command without any options:

stat sample.txt File: sample.txt Size: 426 Blocks: 8 IO Block: 4096 regular file Device: 10302h/66306d Inode: 8259907 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/abhishek) Gid: ( 1000/abhishek) Access: 2020-01-06 09:48:02.908946552 +0530 Modify: 2020-01-05 10:16:33.225203223 +0530 Change: 2020-01-06 19:51:28.737207649 +0530 Birth: -

Let me explain the output to you:

  • File: Name of the file.
  • Size: Size of the files in bytes.
  • Blocks: Number of filesystem blocks the file needs on the disk.
  • IO Block: Size of a filesystem block. It is usually 4 KB.
  • File type: It could be file, directory, link, sockets.
  • Device: The device number (ID of the hard drive) in hexadecimal and decimal.
  • Inode: The inode number. Read more about inodes in Linux.
  • Links: Number of hard links to the file.
  • Access: File permissions in absolute mode and symbolic mode.
  • Uid: User id and the user name of the file owner
  • Gid: Group id and group name of the file owner.
  • Access: This access is about access timestamp (last time the file was accessed), also called atime.
  • Modify: The modify timestamp (last time the file was modified), also called mtime.
  • Change: The change timestamp (last time the file was called), also called ctime. Read this article to know more about atime, mtime and ctime.
  • Birth: Original creation date of the file. This is not used in Linux.
Читайте также:  Installing programs in ubuntu linux

If you use the terse mode with option -t, you’ll see pretty much the same information (some orders could be different) in a single line but without any description of which field is what.

[email protected]:$ stat -t sample.txt sample.txt 426 8 81b4 1000 1000 10302 8259907 1 0 0 1578284282 1578199593 1578320488 0 4096

Get filesystem information with stat command

You can use the -f option to display information of the filesystem instead of the file itself.

[email protected]:$ stat -f sample.txt File: "sample.txt" ID: 65205b688c8b079c Namelen: 255 Type: ext2/ext3 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 61142095 Free: 41522899 Available: 38399635 Inodes: Total: 15597568 Free: 15279217

As you can see in the output, it gives you the following information:

  • File: Name of the file.
  • ID: Filesystem ID in hexadecimal.
  • Namelen: Maximum length for file names.
  • Type: Filesystem type.
  • Block size: The amount of data to request read requests for optimum data transfer rates.
  • Fundamental block size: Size of a block on filesystem
  • Total blocks, free blocks and available blocks (for non-root users)
  • Number of total inodes and free inodes

Use stat command with multiple files

You can run the stat command with multiple files.

You can provide their names individually like this:

You can also provide a file name pattern:

I hope you liked this handy little command. Stay tuned for more Linux command learning.

Источник

How to Show File Attributes in Linux

Linux provides us the access control by file and directory permissions on three levels which are user, group, and other. These file permissions provide the basic level of security and access control.

Linux also has advanced access control features like ACLs (Access Control Lists) and attributes. Attributes define the properties of files. This guide describes what these attributes are and how we can access them.

Attributes in Linux

Some filesystems support additional attributes (other than those described in the preceding sections). In particular, some Linux-native filesystems support several attributes that you can adjust with the chattr command. The files and directories can have the following attributes:

Define each file attributes

The detailed meaning of these attributes according to the manual page is:

  • a — append only: this attribute allows a file to be added to, but not to be removed. It prevents accidental or malicious changes to files that record data, such as log files.
  • c — compressed: it causes the kernel to compress data written to the file automatically and uncompress it when it’s read back.
  • d — no dump: it makes sure the file is not backed up in backups where the dump utility is used
  • e — extent format: it indicates that the file is using extents for mapping the blocks on disk.
  • i — immutable: it makes a file immutable, which goes a step beyond simply disabling write access to the file. The file can’t be deleted, links to it can’t be created, and the file can’t be renamed.
  • j — data journaling: it ensures that on an Ext3 file system the file is first written to the journal and only after that to the data blocks on the hard disk.
  • s — secure deletion: it makes sure that recovery of a file is not possible after it has been deleted.
  • t — no tail-merging: Tail-merging is a process in which small data pieces at a file’s end that don’t fill a complete block are merged with similar pieces of data from other files.
  • u — undeletable: When a file is deleted, its contents are saved which allows a utility to be developed that works with that information to salvage deleted files.
  • A — no atime updates: Linux won’t update the access time stamp when you access a file.
  • D — synchronous directory updates: it makes sure that changes to files are written to disk immediately, and not to cache first.
  • S — synchronous updates: the changes on a file are written synchronously on the disk.
  • T — and top of directory hierarchy: A directory will be deemed to be the top of directory hierarchies for the purposes of the Orlov block allocator.
Читайте также:  One device manager linux

How to list file attribute using lsattr command

Some Linux-native filesystems support several attributes that you can list with the lsattr command. To list attribute of files and sub-directory of the current directory, do

$ lsattr -----a-----------e- ./file1 ----i------------e- ./hello_dir -----------------e- ./usrcopy -----------------e- ./special_characters -----------------e- ./file3 -----------------e- ./contents -----------------e- ./hard_link -----------------e- ./usrlisting

Here we can see that the directory ‘hello_dir’ is immutable, and the file named ‘file1’ is append only file.

You can list the attribute of the contents of a particular directory with lsattr command followed with a file or directory name as the argument.

$ lsattr script-test/ -------------e-- script-test/password-gen.sh -------------e-- script-test/continue.sh -------------e-- script-test/hello -------------e-- script-test/folder1

As the ls -l command, the -d option with lsattr will list the attributes of the directory itself instead of the files in that directory.

$ # lsattr -d script-test/ -------------e-- script-test/

The -R option will list the attributes of a directory recursively. It means that it will show the attributes of the sub-directories’s contents

$ lsattr -R script-test/ -------------e-- script-test/password-gen.sh -------------e-- script-test/continue.sh -------------e-- script-test/hello -------------e-- script-test/folder1 script-test/folder1: ----i--------e-- script-test/folder1/file1

You can see that, it shows the attributes of the content of ‘folder1’ too

You can have the version of the program with the -V option

$ lsattr -V lsattr 1.42.9 (28-Dec-2013) -------------e-- ./jdk-8u65-linux-x64.tar.gz -------------e-- ./ttyrec-1.0.6-1.i586.rpm.1 -------------e-- ./bootstrap

Conclusion

Although there are quite a few attributes that can be used, you should be aware that most attributes are rather experimental and only of any use if an application is employed that can work with the given attribute.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Источник

Оцените статью
Adblock
detector