This tutorial was originally published on biglandnetwork.com. It is part of the free Linux for Beginners series, with a 10-minute video for every lesson.
You ask Linux for one file and it answers with a wall of Permission denied. This lesson shows how to find any file by name, type or size, how to hide that error noise, and how to learn what a file really is and how much space it uses. Every command here only reads information, so you can practice safely.
Part of the Linux for Beginners series. This article is the written version of lesson 3 of the Bigland Network video course. All outputs were captured on AlmaLinux 9.8 as a normal user (no root). Your own files, sizes and names will differ, so the examples use
your-userwhere your account name would appear.
1. find: search by name
find always reads the same way: where to start, then what to look for. It visits the start folder and every folder below it.
$ find /etc -name sshd_config /etc/ssh/sshd_config find: ‘/etc/lvm/devices’: Permission denied find: ‘/etc/lvm/archive’: Permission denied find: ‘/etc/lvm/backup’: Permission denied find: ‘/etc/lvm/cache’: Permission denied find: ‘/etc/sssd’: Permission denied find: ‘/etc/pki/rsyslog’: Permission denied find: ‘/etc/grub.d’: Permission denied find: ‘/etc/nftables’: Permission denied find: ‘/etc/audit’: Permission denied find: ‘/etc/ssh/sshd_config.d’: Permission denied find: ‘/etc/firewalld’: Permission denied find: ‘/etc/sudoers.d’: Permission denied The file was found, but a normal user may not open some system folders, and find reports each one it cannot read.
2. Hide the errors with 2>/dev/null
Every command has two output channels: channel 1 is the normal output, channel 2 is for errors. 2> sends channel 2 somewhere else, and /dev/null is the Linux trash bin: anything sent there is thrown away.
$ find /etc -name sshd_config 2>/dev/null /etc/ssh/sshd_config The errors still happen; they are just not shown. The results still reach your screen.
3. Wildcards, -maxdepth and counting
A star * means any text. Put the pattern in single quotes so that find receives the star itself. -maxdepth 1 means this folder only, not its subfolders.
$ find /etc -maxdepth 1 -name '*.conf' | head -n 5 /etc/resolv.conf /etc/kdump.conf /etc/sestatus.conf /etc/yum.conf /etc/request-key.conf Pipe the list into wc -l to count the results (you met head and wc in lesson 2):
$ find /etc -name '*.conf' 2>/dev/null | wc -l 71 4. -iname, -type and -size
| Option | What it does |
|---|---|
-name 'x*' | Exact name, wildcards allowed. Case sensitive. |
-iname 'x*' | The same, but ignores capital letters. |
-type f / -type d | Regular files only / directories only. |
-size +1M | Larger than 1 megabyte (also +100k, +1G). |
-maxdepth 1 | Do not go into subfolders. |
$ find /etc -maxdepth 1 -iname 'HOST*' /etc/host.conf /etc/hosts /etc/hostname $ find . -type d . ./folder ./folder2 ./folder3 ./.ssh $ find /var/log -type f -size +1M 2>/dev/null /var/log/anaconda/journal.log $ find . -name '*.sh' ./example1.sh ./example2.sh ./example3.sh ./sample.sh ./sample2.sh The dot means start here, in the current folder. You can combine options: find /var/log -type f -size +1M lists only big files, never folders. Your own home folder will show different names.
5. which and type: where is a command?
which prints the full path of a program. It only searches the folders listed in your PATH.
$ which ls bash python3 /usr/bin/ls /usr/bin/bash /usr/bin/python3 $ which locate /usr/bin/which: no locate in (/home/your-user/.local/bin:/home/your-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin) $ type cd cd is a shell builtin locate is not installed on this machine. cd is not a program at all: it is part of the shell, so ask type, not which.
6. file and stat: what is this file?
Linux does not trust file name endings. file reads the content and tells you what the file really is:
$ file /etc/hostname /etc /usr/bin/bash /etc/hostname: ASCII text /etc: directory /usr/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ef892035f0f947ac78c4ef86ce9f30687fedc936, for GNU/Linux 3.2.0, stripped stat shows everything Linux knows about one file: size, permissions, owner and dates.
$ stat /etc/hostname File: /etc/hostname Size: 10 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 8863866 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:hostname_etc_t:s0 Access: 2026-11-15 18:30:44.485754096 +0000 Modify: 2026-11-15 18:30:44.484754109 +0000 Change: 2026-11-15 18:30:44.484754109 +0000 Birth: 2026-11-15 18:30:44.484754109 +0000 Access is when the file was last read, Modify when its content changed, and Change when its details, such as the permissions, changed.
7. du and df: disk space
du (disk usage) measures a folder: -s gives one summary line, -h prints human sizes. df (disk free) looks at the whole disk.
$ du -sh /usr/share/doc 23M /usr/share/doc $ du -sh /var/log 2>/dev/null 6.3M /var/log $ df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/almalinux-root 8.0G 5.0G 3.0G 63% / Combine them to find the biggest folders: sort human sizes with sort -h and keep the last lines with tail.
$ du -h --max-depth=1 /usr/share 2>/dev/null | sort -h | tail -n 5 16M /usr/share/man 23M /usr/share/doc 24M /usr/share/microcode_ctl 105M /usr/share/locale 221M /usr/share When a disk is full, run this on the biggest folder, then go one level deeper and repeat. For a longer walkthrough, see How to Find What Is Using Disk Space on Linux.
8. Common mistakes
- Capital letters in the start folder. Folder names are case sensitive, even with
-iname:
$ find /ETC -name hosts find: ‘/ETC’: No such file or directory - No quotes around the star. Without quotes, the shell may replace
*.confwith matching files from your current folder beforefindstarts. Write-name '*.conf'. - Hiding errors when nothing is found. If the screen stays empty, remove
2>/dev/nulland read the errors. - Using
whichfor a builtin.which cdfinds nothing; usetype cd.
9. Practice
- Find every file that ends in
.repounder/etc, without the error noise. - Where is the
python3program? - How much space does
/usr/share/docuse?
Answers:
$ find /etc -name '*.repo' 2>/dev/null /etc/yum.repos.d/almalinux-appstream.repo /etc/yum.repos.d/almalinux-baseos.repo /etc/yum.repos.d/almalinux-crb.repo /etc/yum.repos.d/almalinux-extras.repo /etc/yum.repos.d/almalinux-highavailability.repo /etc/yum.repos.d/almalinux-nfv.repo /etc/yum.repos.d/almalinux-plus.repo /etc/yum.repos.d/almalinux-resilientstorage.repo /etc/yum.repos.d/almalinux-rt.repo /etc/yum.repos.d/almalinux-sap.repo /etc/yum.repos.d/almalinux-saphana.repo /etc/yum.repos.d/docker-ce.repo $ which python3 /usr/bin/python3 $ du -sh /usr/share/doc 23M /usr/share/doc Your list of .repo files depends on the repositories installed on your machine.
10. Cheat sheet
| Command | Use it to |
|---|---|
find /etc -name 'x' | Find by exact name |
find . -iname 'x*' | Find by name, ignoring capitals |
find . -type f / -type d | Files only / folders only |
find /var -size +1M | Find big files |
command 2>/dev/null | Hide error lines |
which python3 / type cd | Locate a program / explain a builtin |
file /etc/hostname | What a file really is |
stat /etc/hostname | Size, owner, permissions, dates |
du -sh folder / df -h / | Folder size / free disk space |
Next, in the series: creating, copying, moving and deleting files and folders with mkdir, touch, cp, mv and rm.
Watch the video lesson on YouTube: https://www.youtube.com/watch?v=q7MxQwRZBG4
Read the original article (always up to date): https://biglandnetwork.com/linux-for-beginners-find-which-file-stat-du-df/
All the lessons: https://biglandnetwork.com/lessons/ · Subscribe on YouTube: https://www.youtube.com/@biglandnetwork
