لینوکس و شبکه

لینوکس و شبکه
طبقه بندی موضوعی
آخرین مطالب
  • ۹۹/۱۱/۱۳
    java

۱ مطلب با کلمه‌ی کلیدی «shel scripting» ثبت شده است

۲۴
خرداد

اگر بخواهیم تنها عبارات سه حرفی را به نمایش بگذاریم از دستور زیر استفاده میکنیم

grep -x '.\{3,10\}'
  • -x match pattern to whole line
  • . any symbol
  • {3,10} quantify from 3 to 10 times previous symbol (in the case any ones)

ایجاد یک فایل بک آپ از همان فایل با پسوند backup در همان مسیر فایل موجود

cp /etc/postfix/main.cf{,.backup}

با گذاشتن این خط در ابتدای یک اسکریپت موجب می‌شود که حالت دیباگ برنامه نوشته شده فراهم آید. یعنی تمام خروجی های کد را در ترمینال نشان می‌دهد:

set -x

IF

Comparisons:

-eq equal to
-ne not equal to
-lt less than
-le less than or equal to
-gt greater than
-ge greater than or equal to


File Operations:

-s file exists and is not empty
-f file exists and is not a directory
-d directory exists
-x file is executable
-w file is writable
-r

file is readable

 


نمونه خاص از تطبیق در شل URL

[[ $a == z* ]]   # True if $a starts with a "z" (wildcard matching).
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching).

 

در تمامی فایل‌های موجود در یک فولدرکلمه IRAN را در کاراکتر شماره شش inject می‌کند:

for file in * ;
do
     mv ./"$file" "${file:0:6}IRAN${file:6}";
     done

یعنی abcdef.ext  تبدیل می‌شود به abcdefIRAN.ext
 


 

حذف کاراکتر دَش یا همان «خط تیره» از تمامی فایل ‌های موجود در یک فولدر: 

 for file in ./*;
     do
         mv "$file" "${file/-/}";
     done

 

  • behrooz mohamadi nsasab