الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

alias, unalias

Make a short name for a longer command (alias), or remove it (unalias).

المستوى
امتحان RHCSA
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
bash (built-in)
يُسمّى أيضًا
unalias

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

An alias replaces the first word of a command with other text. alias ll='ls -l' means: when you type ll, Bash runs ls -l.

An alias made on the command line lives only in that shell. To keep it, put the alias line in ~/.bashrc (only you) or in a file in /etc/profile.d/ (all users).

Aliases are for interactive work. In scripts, use the full commands or a function.

طريقة الكتابة

alias [-p] [NAME[=VALUE] ...]
unalias [-a] NAME [NAME ...]

الخيارات 2

الأكثر استخدامًا

-p
With alias: print all aliases in a form you can use again.
-a
With unalias: remove all aliases of this shell.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1List all aliases

    alias
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'

    RHEL adds a few aliases for every user.

  2. 2Make a short name

    alias ports='ss -tulpn'
    ports

    Works until you close the shell.

  3. 3Keep the alias after logout

    echo "alias ports='ss -tulpn'" >> ~/.bashrc
    source ~/.bashrc

    source loads it now; new shells read ~/.bashrc by themselves.

  4. 4Make a safer rm, cp and mv

    alias rm='rm -i' cp='cp -i' mv='mv -i'

    -i asks before it removes or overwrites a file. root has these by default on RHEL.

  5. 5Run the real command once, without the alias

    \rm old.log

    A backslash (or command rm) skips the alias.

  6. 6Remove an alias

    unalias ports

    Only for this shell. Delete the line in ~/.bashrc to remove it for good.

  7. 7Show what one alias does

    alias ll
    alias ll='ls -l --color=auto'

    Good when a short name behaves in a strange way.

  8. 8Give all admins the same shortcuts

    cat > /etc/profile.d/ops-aliases.sh <<'EOF'
    alias jctl='journalctl -xe'
    alias fwl='firewall-cmd --list-all'
    EOF

    Every user gets these at the next login. Updates do not touch your file.

  9. 9Shorten a long kubectl or podman command

    alias k='kubectl'
    alias pps='podman ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'

    Typical DevOps shortcuts. Keep them in ~/.bashrc.

  10. 10Check for a dangerous alias in a security review

    alias | grep -E "sudo|ssh|su="

    An alias that changes sudo or ssh can steal passwords. There should be none.

  11. 11Remove all aliases in this shell

    unalias -a

    Useful to test a problem without any aliases.

انتبه

  • Aliases are not used in scripts (non-interactive shells), unless the script turns on shopt -s expand_aliases.
  • Use single quotes '…' so variables are read when the alias runs, not when you define it.
  • An alias can hide a real program with the same name. Check with type NAME.

الملفات

~/.bashrc
Your own aliases (read by every new shell).
/etc/profile.d/*.sh
Aliases and settings for all users.
/etc/bashrc
System-wide settings for every shell (do not edit; use profile.d).

نصائح للحفظ

  • alias = make, unalias = remove, ~/.bashrc = keep.
  • \name runs the real command once.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man alias