• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

chattr: command not found

by admin

The chattr command is used to change the attributes of a file or directory. The following table describes some of the options of the chattr command.

Option Description
-R Recursively change the attributes of directories and their contents.
-v {version} Set the version number of a file.
+i Mark the file as read-only, or immutable. Requires superuser privileges.
-i Remove the read-only, or immutable, attribute of the file. Requires superuser privileges.

The syntax of the chattr command is:

# chattr [-R] [-v {version}] [+-{attributes}] {file/directory names}

If you encounter the below error while running the chattr command:

chattr: command not found

you may install below package as per your choice of distribution:

Distribution Command
OS X brew install e2fsprogs
Debian apt-get install e2fsprogs
Ubuntu apt-get install e2fsprogs
Alpine apk add e2fsprogs
Arch Linux pacman -S e2fsprogs
Kali Linux apt-get install e2fsprogs
CentOS yum install e2fsprogs
Fedora dnf install e2fsprogs
Raspbian apt-get install e2fsprogs

Removing the -i (immutable) attribute from the files

To Remove “i” attribute use below command.

# chattr -i geek.txt    # Unset "i" attribute

After removing the attribute you will see the permission section will become blank.

# lsattr geek.txt     
--------------- geek.txt

Making a directory immutable using chattr

Now let’s try to Secure a directory by changing it’s attribute recursively using chattr command. Here I have a directory named data and everyone have full access to that directory recursively. Refer the sample output below.

# mkdir data
# chmod -R 777 data/
# ls -l
total 4
drwxrwxrwx. 2 root root 4096 Apr 24 04:25 data

Now set attribute to that directory.

# chattr +i data/
# lsattr 
----i--------e- ./data

You can also set attribute Recursively using -R option with chattr.

# chattr -R +i data/

After setting the attribute to the directory now try to delete, move or create a file, I am sure you will not allowed to do any one of that. Refer the sample output below.

# rmdir data/        # Deleting the Directory
rmdir: failed to remove `data/': Operation not permitted
# rm -rf data/        # Deletiing the Directory Forcefully
rm: cannot remove `data': Operation not permitted
# mv data/ mydata       # Moving the Directory
mv: cannot move `data/' to `mydata': Operation not permitted
# cd data/
# cat > test.txt       # Creating a File in the directory
bash: test.txt: Permission denied

Filed Under: Linux

Some more articles you might also be interested in …

  1. i3lock: command not found
  2. Getting info with the vsish command (esxi only)
  3. Common Error Messages from Command xfs_repair in Linux
  4. How to Disable Docker Process and docker0 Interface on CentOS/RHEL
  5. Basic Commands to Troubleshoot Performance Issues in Linux
  6. binwalk: command not found
  7. logrotate: command not found
  8. curl Command Examples in Linux
  9. ipcalc: command not found
  10. lslocks: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright