Linux File Attributes and System Utilities Overview

File Search with find

Exact match:

find /path -type f -name "filename"

Wildcard patterns:

find /path -type f -name "prefix*"
find /path -type f -name "*suffix"
find /path -type f -name "part*match"

Case-insensitive search:

find /path -type f -iname "Filename*"

Search by file size (use suffixes for units):

  • c: bytes
  • k: kilobytes (1024 bytes)
  • M: megabytes (1048576 bytes)
  • G: gigabytes (1073741824 bytes)

Examples:

find /oldboy -type f -size +100k   # larger than 100 KB
find /oldboy -type f -size -100k   # smaller than 100 KB
find /oldboy -type f -size +1M     # larger than 1 MB

Limit recursion depth:

find /oldboy -maxdepth 1 -type f -name "Oldboy*"  # only top-level
find /oldboy -maxdepth 2 -type f -name "Oldboy*"  # up to two levels

Directory Strcuture Visualization with tree

Display full tree:

tree /oldboy

Limit depth or show only directories:

tree -L 2 /        # up to 2 levels deep
tree -d /oldboy    # directories only

File Compression Using tar

Create a compressed archive:

tar zcvf /oldboy/backup.tar.gz /oldboy/services

Extract an archive:

tar xvf /oldboy/backup.tar.gz

List contents without extraction:

tar tf /oldboy/backup.tar.gz

Exclude files during compression:

  • Single exclusion: --exclude="pattern"
  • Multiple exclusions: -X exclude_list.txt

Example using an exclusion file:

cat > /tmp/exclude.txt <<EOF
/oldboy/oldboy.txt
/oldboy/oldboy.avi
/oldboy/oldboy.jpg
/oldboy/oldboy.png
EOF

tar zcvf /tmp/oldboy05.tar.gz /oldboy --exclude-from=/tmp/exclude.txt

Linux File Permissions and Ownership

Permission bits:

  • r = read (4)
  • w = write (2)
  • x = execute (1)
  • - = no permission (0)

Permissions apply to three classes:

  • Owner (user)
  • Group
  • Others

Numeric examples:

  • rwx------ → 700
  • rw--w---x → 621
  • rwx-wx--- → 730
  • 432 → r---wx-w-

User and Group Management

User identification uses numeric UIDs:

id root    # uid=0
id oldboy  # uid=1000

User categories in CentOS 7:

  • Root: UID 0, full system access
  • System users: UID 1–999, used for services, non-login
  • Regular users: UID ≥1000, interactive login enabled

Group identification uses GIDs. A user can belong to multiple groups.

Security best practices for root:

  • Change SSH port in /etc/ssh/sshd_config
  • Disable root remote login via PermitRootLogin no

Inodes and Data Blocks

Each file has an inode storing metadata (permissions, timestamps, etc.). The filename is stored in the parent directory’s data block.

Check inode usage:

df -i
ls -li /path

Data content resides in blocks (default size: 4KB). Block size tuning:

  • Larger blocks (e.g., 16K–64K): efficient for large files (video, imaging)
  • Smaller blocks (e.g., 1K–2K): better space utilization for many small files

File access flow:

  1. Locate filename in directory block
  2. Retrieve inode number
  3. Use inode to find data blocks
  4. Read actual content

File Timestamps

Three time attributes:

  • atime: last access time
  • mtime: last content modification
  • ctime: last metadata change (e.g., chmod)

Inspect with:

stat /oldboy/test.txt

Hard and Soft Links

Hard link: shares the same inode as the original; valid even if source is deleted. Cannot be created for directories.

ln /source/file /link/hardlink

Soft (symbolic) link: a pointer to the source path; breaks if source is removed.

ln -s /source/file /link/symlink

Key differences:

  • Hard links: same inode, same size, survive source deletion
  • Soft links: different inode, file type shows as link, invalid after source removal

Time Handling Commands

Display current time:

date

Custom formats:

date +%F                 # YYYY-MM-DD
date "+%F %T"           # YYYY-MM-DD HH:MM:SS
date "+%y-%m-%d %H:%M:%S"

Automated timestamped backup:

cp /oldboy/app.log /log/app.log.$(date +%F)

Time synchronization:

yum install -y ntpdate
ntpdate ntp1.aliyun.com

Tags: Linux file-system permissions find tar

Posted on Sat, 07 Nov 2026 16:09:17 +0000 by ManicMax