متقدم
البحث فيالمعامل
طريقة البحث
  • ابحث عن مهمة أو أداة (lvm، selinux، ‎@podman)؛ وصفِّ حسب المستوى والكتاب أو الدورة.
  • مع مربع بحث فارغ، الفلتر وحده يعرض المعامل — مثلًا كل المعامل الصعبة لدورة واحدة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

معمل 13.1The Linux Command Line, الفصل 13

Part 2 practice: your own environment, vi and prompt

المستوى
سهل
30 دقيقة
الأجهزة
any Linux system
الحالة
لم يبدأ

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

الهدف

Set up a comfortable working environment that stays after logout: a personal bin directory in the PATH, aliases and history settings, a coloured prompt with the time, and a few edits in vi.

قبل أن تبدأ

المهام

  1. Make the directory ~/bin and make sure it is in your PATH in every new shell.
  2. Add to ~/.bashrc: the alias ll for ls -l --color=auto, and history settings that ignore repeated commands and keep 5000 lines. Add a comment above each line.
  3. Load the changes into the open shell without logging out.
  4. Show the date in the time zone Europe/Amsterdam for one command only. Your normal TZ must not change.
  5. Copy /etc/services to ~/services.txt. In vi: go to line 20, delete 3 lines, replace every udp with UDP in the whole file, and save.
  6. Make a green prompt that shows the time (hours:minutes), the user, the host and the last part of the directory. Make it stay in new shells.

تحقّق من عملك

bash -lc 'echo $PATH' | tr ':' '\n' | grep bin
bash -ic 'type ll'
bash -ic 'echo $HISTCONTROL $HISTSIZE'
grep -c UDP ~/services.txt
bash -ic 'echo "$PS1"'
  • PATH shows /home/USER/bin.
  • type ll says it is an alias.
  • HISTCONTROL is ignoredups and HISTSIZE is 5000.
  • The prompt contains \A, \u, \h, \W and the colour code 0;32.

تلميحات

اعرض التلميحات
  • PATH changes go in ~/.bash_profile (or ~/.profile); aliases in ~/.bashrc.
  • source ~/.bashrc reloads the file.
  • NAME=value command sets a variable for one command.
  • In vi: 20G, 3dd, :%s/udp/UDP/g, :wq.
  • Colours need \[ and \] around them.

الحل

اعرض الحل
  1. Make the directory and add it to the PATH.
    mkdir -p ~/bin
    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bash_profile
  2. Add the aliases and history settings with comments.
    cat >> ~/.bashrc << 'EOF'
    # my aliases
    alias ll='ls -l --color=auto'
    # history: no repeated lines, keep more
    export HISTCONTROL=ignoredups
    export HISTSIZE=5000
    EOF
  3. Load the file.
    source ~/.bashrc
  4. A temporary variable.
    TZ=Europe/Amsterdam date
    echo "TZ is still: '$TZ'"
  5. Edit in vi (type the keys in vi).
    cp /etc/services ~/services.txt
    vi ~/services.txt
    keys in vi
    20G
    3dd
    :%s/udp/UDP/g
    :wq
  6. Make the prompt and save it.
    echo 'PS1="\[\033[0;32m\]\A \u@\h \W\$\[\033[0m\] "' >> ~/.bashrc
    source ~/.bashrc

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل