Files + permissions cheatsheet.
ls -l output
-rw-r--r-- 1 user group 1024 Jan 15 10:00 file
drwxr-xr-x 2 user group 4096 Jan 15 10:00 dir
Type+perms / links / user / group / size / date / name.
Permissions
r=4 w=2 x=1
owner group other
rwx r-x r--
7 5 4
chmod
chmod 755 file
chmod u+x file
chmod g-w file
chmod o=r file
chmod -R 644 dir/
chmod a+r file # all = u+g+o
chmod u+rwx,g+rx,o-rwx file
chown
chown user file
chown user:group file
chown -R user:group dir/
chown :group file # group only
umask
umask # default file creation mask
umask 022 # files 644, dirs 755
umask 077 # private (600, 700)
In ~/.bashrc for permanent.
Special bits
chmod u+s file # setuid (run as owner)
chmod g+s dir # setgid (new files inherit group)
chmod +t dir # sticky (only owner can delete) /tmp uses this
In octal:
chmod 4755 file # setuid
chmod 2755 dir # setgid
chmod 1777 dir # sticky (like /tmp)
ACL
setfacl -m u:alice:rwx file
setfacl -m g:devs:rx file
setfacl -d -m u:alice:rwx dir # default for new files in dir
setfacl -x u:alice file
getfacl file
Requires acl mounted filesystem (default on ext4).
File attributes (chattr)
chattr +i file # immutable (can't modify or delete)
chattr -i file
chattr +a logfile # append-only
lsattr file
Useful for tamper-proofing.
umask in scripts
(umask 077; touch private)
find
find /path -name "*.txt"
find . -iname "readme*" # case-insensitive
find . -type f # files only
find . -type d
find . -size +10M # > 10MB
find . -size -1k
find . -mtime -7 # modified < 7 days
find . -atime +30 # accessed > 30 days
find . -newer file
find . -empty
find . -user alice
find . -group devs
find . -perm 0644
find . -perm /u+x # any of these perms
find . -name "*.tmp" -delete
find . -name "*.log" -mtime +30 -exec rm {} \;
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
locate
sudo updatedb
locate filename
Faster than find for name lookups.
Symlinks
ln -s /actual/path /link
readlink /link
realpath /link # resolved
Hard links
ln file copy # same inode
stat file copy # check inode
Hard links can’t span filesystems.
File types
- regular file
d directory
l symlink
b block device
c character device
p pipe (FIFO)
s socket
Comparing
diff file1 file2
diff -u file1 file2 # unified
diff -r dir1 dir2
cmp file1 file2 # binary
md5sum file
sha256sum file
Copying
cp -a src dst # archive: -dR --preserve=all
cp -u src dst # only if newer
cp -i src dst # interactive
cp -l src dst # hard link instead of copy
cp -s src dst # symlink instead
rsync -a src/ dst/ # better than cp; resumable
rsync -avz src/ user@host:dst/
rsync -avz --delete src/ dst/ # mirror (deletes extras)
Compression
gzip file # → file.gz
gunzip file.gz
gzip -k file # keep original
gzip -9 file # max compression
xz file # better compression
bzip2 file
zstd file # fast + good
tar czf out.tar.gz dir/
tar cJf out.tar.xz dir/ # xz
tar c --zstd -f out.tar.zst dir/
du / df
du -h file
du -sh dir/ # summary
du -sh */ # each subdir
du -shc */ # with grand total
du -h --max-depth=1 .
df -h # disk free
df -i # inodes
df -hT # type
/proc
ls /proc # processes by PID
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/loadavg
cat /proc/uptime
cat /proc/version
File watchers
inotifywait -m -r dir # watch for changes
inotifywait -e modify,create,delete file
ionice / nice
nice -n 19 cmd # low priority
ionice -c 3 cmd # idle I/O priority
Common mistakes
chmod 777everywhere — security hole.chown -Ron running services without restart.- Removing immutable file fails — chattr -i first.
- find without
-print0+ xargs-0for paths with spaces. - Hard links across filesystems fails silently in scripts.
Read this next
If you want my file management snippets, they’re at rajpoot.dev .
Building something AI-, backend-, or data-heavy and want a second pair of eyes? I do consulting and freelance work — see my projects and ways to reach me at rajpoot.dev .