~2 min read • Updated Mar 1, 2026
1. Preventing Deletion of Specific Files or Directories
Users sometimes delete important directories such as public_html. To prevent this, DirectAdmin allows you to intercept deletion attempts using the file_manager_remove_pre.sh hook.
Create the script:
/usr/local/directadmin/scripts/custom/file_manager_remove_pre.sh
Content:
#!/bin/bash
if [[ "${file#${home}}" == /domains/*/public_html ]]; then
echo "You cannot delete your public_html link!"
exit 1
fi
Make it executable:
chmod 700 /usr/local/directadmin/scripts/custom/file_manager_remove_pre.sh
You can block additional paths by adding more if conditions.
---
2. Adding Custom File Types to the EDIT Button
For a file to be editable in FileManager, its extension must be recognized as a text-based MIME type in /etc/mime.types.
Example: enabling the CakePHP .ctp extension:
text/x-php ctp
Any MIME type starting with text/ will be treated as editable.
---
3. Changing Permissions for Uploaded Files
You can automatically adjust permissions for files uploaded via FileManager using all_post.sh.
Create:
/usr/local/directadmin/scripts/custom/all_post.sh
Content:
#!/bin/sh
CHMODVAL=700
ULPATH=/home/${username}${path}
setfile() {
if [ "$1" = "" ]; then
return;
fi
F=`echo $1 | cut -d/ -f4 | awk '{ print substr($1,1,length($1)-6) }'`
chmod ${CHMODVAL} ${ULPATH}${F}
}
if [ "$command" = "/CMD_FILE_MANAGER/" ] || [ "$command" = "/CMD_FILE_MANAGER" ]; then
if [ "$action" = "upload" ]; then
setfile $file1
setfile $file2
setfile $file3
setfile $file4
setfile $file5
setfile $file6
setfile $file7
setfile $file8
fi
fi
exit 0;
Make executable:
chmod 755 /usr/local/directadmin/scripts/custom/all_post.sh---
4. Fixing File Download Issues (Files Displaying as Plain Text)
If downloaded files appear as raw text instead of triggering a download, the issue is usually related to missing or incorrect MIME types.
Checklist:
- Ensure
/etc/mime.typesexists and is readable:
ls -la /etc/mime.types
-rw-r--r-- 1 root root ...
- Verify required MIME types exist:
grep zip /etc/mime.types
application/zip zip
- Ensure DirectAdmin is using the correct MIME Error! Hyperlink reference not valid.
/usr/local/directadmin/directadmin config | grep mime
apachemimetypes=/etc/mime.types
If you modify directadmin.conf, restart DirectAdmin afterward.
---
5. Using Head and Tail Commands in FileManager
You can preview the beginning or end of a file directly from FileManager using GET parameters.
View the first 10 lines:
/CMD_FILE_MANAGER/file.txt?fm_head=10
View the last 5 lines:
/CMD_FILE_MANAGER/file.txt?fm_tail=5
Only one parameter can be used at a time.
Output is always displayed as text/plain.
Written & researched by Dr. Shahin Siami