Mistakenly I had backed up to an NTFS drive. After restoring all the permissions were set to 777.

I fixed some of the important files like sudo and su. I can't reinstalll right now as my internet connection is limited, at least for another week.

I remembered that pacman stores the meta data related to files in the mtree file for each package in a gzipped format. I tried to use this utility but it seems like it has issues with the bsdtar mtree format, so I decided to write a bash script of my own, which just chmods the files.

Here's the mtree of acl for reference -

gzip -cd /var/lib/pacman/local/acl-2.2.52-3/mtree

Output -

/set type=file uid=0 gid=0 mode=644
./.BUILDINFO time=1478441026.526890249 size=3111 md5digest=80956213c6346f28d8f1b5a9165b952d sha256digest=5e56cab859054c2ca7759cbe50adbc0b6352f78fad3b051bb9174f3bf17f9c21
./.PKGINFO time=1478441026.513556943 size=434 md5digest=8e7df6a965b196aa5564786f022d068d sha256digest=504c99ff77ddb0d2847d7e8c85f637ad78edd78db3ee91a6b491bee5884ebb22
/set mode=755
./usr time=1478441025.433559189 type=dir
./usr/bin time=1478441026.323557338 type=dir
./usr/bin/chacl time=1478441026.323557338 size=14672 md5digest=69332d6d57c153ad21ecf1c09381363d sha256digest=faafbb9420403fb13d4207e986ee0ba940a97b1feb3fcde453669912afeaa340
./usr/bin/getfacl time=1478441026.313557360 size=23680 md5digest=ef23d3c7676198e08d71530c58f44026 sha256digest=f22b3fd68e46d767e7f255be7427cebde9f7539357b2625fade7fa86fbb60743
./usr/bin/setfacl time=1478441026.320224012 size=36224 md5digest=9f6a5f7ddcb08b787b39bcfda4047828 sha256digest=4ac33e394ec50676af4015498fecc867802de3f14f7a589c7d972fcc2b720b4d
./usr/include time=1478441025.466892453 type=dir
./usr/include/acl time=1478441025.473559107 type=dir
./usr/include/acl/libacl.h time=1478441025.473559107 mode=644 size=2590 md5digest=9cd8a73452e0cf899928b27b20b02d6e sha256digest=21366c9f8ffe4018cc3753a73e0c81f0c54102435031de8f5325675f55a42bf2
./usr/include/sys time=1478441025.460225800 type=dir
./usr/include/sys/acl.h time=1478441025.460225800 mode=644 size=3755 md5digest=8ea51961753fc1da4cae7fd48d2068c0 sha256digest=287dbc9269df3fe9e6b0a1dc6c0aac8e90b925867bf235a554a02414f6fcedfd
/set mode=777
./usr/lib time=1478441025.996891351 mode=755 type=dir
./usr/lib/libacl.so time=1478441025.483559085 type=link link=libacl.so.1
./usr/lib/libacl.so.1 time=1478441025.463559127 type=link link=libacl.so.1.1.0
./usr/lib/libacl.so.1.1.0 time=1478441025.996891351 mode=644 size=35456 md5digest=3e5e200ae58fdf7f4558ef863b11d9a6 sha256digest=f8c7e1c06646c5d46725cbc4d0c7290b35d4d2c4203df2a0ccb42e7635be6ce6
/set mode=755
./usr/share time=1478441025.353559356 type=dir

Trimmed for brevity.

My go is something like this -

  1. read this output line by line
  2. if we encounter a "/set mode=" line, parse the value of mode
  3. parse the filename and keep chmodding.
  4. If the file has an individual mode, use that mode instead of the global one.

So, for the first step (reading line by line) I did -

file = "$1"
while read var
        echo "$var"
    done < "$file"

But that's giving me

=: cannot open `=' (No such file or directory)
:  cannot open `' (No such file or directory)
./test: line 5: : No such file or directory

Any help is greatly appreciated.

  • you've probably also lost ACLs and capabilities that were set on the files. if you haven't cleaned out pacman's download cache (/var/cache/pacman/pkg/) i'd suggest reinstalling from there rather than trying to write your own parser. pacman -Qkk will check the installed files against those mtree files but i don't know an easy way to get it to reapply those settings.
    – quixotic
    Mar 31, 2017 at 6:45
  • @quixotic I wrote a parser. This fixed the files (except /var I suppose) Mar 31, 2017 at 17:02

1 Answer 1


As I want to provide help for this problem I wrote a little Bash-Script to fix file-permissions based on those MTREE's ...

curl https://xgit.ddns.net/ergotamin/ShellScripting/raw/master/fix-permissions \
>fix-permissions && chmod 0775 fix-permissions


fix-permissions --all -- to fix all permissions of whole FS fix-permission "/var/lib/pacman/local/PKGNAME -- to fix only this mtree


Here: CLICK ME you can find a solution coded in C, which is MUCH fast then the Bash-Version...


use-mtree /path/to/*/mtree

SourceCode is available Here ... and here ( needed headers are available at my site ):

/******************************************* * ! Copyright (C)2018 * ! Marcel Bobolz * * $ Copying and distribution of this file, with or without modification, * $ are permitted in any medium without royalty provided the copyright * $ notice and this notice are preserved. This file is offered as-is, * $ without any warranty. * * * @ Code-Information : * * => % MTree-Parser * *******************************************/ #include <xstdarchive.h>

__attribute__((flatten)) __bool_t main(__i32_t ArgC, __charr_t ArgV){ ArgC--; ArgV++; __u64_t BytesRead = ZERO; static __file_t PFile; static __uch_t MTreeBuf[BUF1MB]; foreach(ArgV){ ((PFile = popen(StrForm("%s%s", "gzip -cd ", *ArgV), "r")) == NULL) ? \ (exit(ERROR)) : (BytesRead = fread(MTreeBuf, ONE, BUF1MB - ONE, PFile)); (BytesRead > ZERO) ? (pclose(PFile)) : (exit(ERROR)); MTreeBuf[BytesRead] = ZERO; ArchiveListArchive(((__str_t)MTreeBuf), 'x'); memset(MTreeBuf, ZERO, BUF1MB); PFile = NU(__file_t); } return(SUCCESS); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.