Vi Commands

To create a shell script:

  1. Use a text editor such as vi. Write required Linux commands and logic in the file.
  2. Save and close the file (exit from vi).
  3. Make the script executable.
  4. You should then of course test the script, and once satisfied with the output, move it to the production environment.
  5. The simplest program in Bash consists of a line that tells the computer a command. Start up your favorite text editor (such as vi):

vi hello.sh

Essential Vi Commands

  • Open a file:

vi filename

  • To go into edit mode:

press ESC and type I

  • To go into command mode:

press ESC

  • To save a file

press ESC and type :w fileName

  • To save a file and quit:

press ESC and type :wq

OR

press ESC and type :x

  • To jump to a line:

press ESC and type :the line number

  • To Search for a string:

Press ESC and type /wordToSearch

  • To quit vi:

Press ESC and type :q

Save the following into a file called hello.sh:

#!/bin/bash
echo "Hello, World!"
echo "Knowledge is power."

Save and close the file. You can run the script as follows:

 ./hello.sh

Sample outputs:

bash: ./hello.sh: Permission denied

Saving and Running Your Script

The command ./hello.sh displayed an error message on the screen. It will not run script since you’ve not set execute permission for your script hello.sh. To execute this program, type the following command:

chmod +x hello.sh
./hello.sh

Sample Outputs:

Hello, World!
Knowledge is power.

Alias

Alias

alias

Create an alias. Aliases allow a string to be substituted for a word. An alias can be used as the first word of any simple command.

Syntax
alias [-p] [name[=value] ...]

unalias [-a] [name...]

Key
-p Print the current values

-a Remove All aliases

When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias
substitution when the alias is expanded.

If no value is given, (or with the -p option) alias will print a list of Aliases along with their current values. For each name in the argument list for which no value is supplied, the name and value of the alias is printed.

Alias returns true unless a name is given for which no alias has been defined.

name can not be `alias’ or `unalias’.

unalias can be used to remove each name from the list of defined aliases.

Alias substitution
The shell maintains a list of aliases which can be set, unset and printed by the alias and unalias commands. After a command line is parsed into simple commands the first word of each command, left-to-right, is checked to see if it has an alias. If so, the first word is replaced by the alias. If the alias contains a history reference, it undergoes History substitution (q.v.) as though the original command were the previous input line. If the alias does not contain a history reference, the argument list is left untouched.

Thus if the alias for ls were ls -l the command ls /usr would become ls -l /usr, the argument list here being undisturbed. If the alias for lookup were grep !^ /etc/passwd‘ then lookup bill would become grep bill /etc/passwd.

Aliases can be used to introduce parser metasyntax. For example, alias print ‘pr !* | lpr’ defines a command (print) which pr‘s its arguments to the line printer.

The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second
time. This means that you can alias ls to ls -F, for instance, and bash does not try to recursively expand the replacement text.

Examples

Create an alias ‘c’ that will clear the screen:
$ alias c=’clear’

Create an alias ‘ls’ that will change the default action of ls:
$ alias ls=’ls –classify’
$ ls
$ unalias ls

More aliases for ls:
$ alias la=’ls -lAXh –color=always’   #Show all, sort by extension
$ alias ls-al=’ls -al’   #fix typo missing space
$ alias l=”ls -l”
$ alias la=”ls -la”

Use alias to fix missing space typos:
$ alias cd..=’cd ..’
$
alias ..=’cd ..’

Display the working directory
$ alias .=’echo $PWD’

Prevent accidental deletions by making rm interactive:
$ alias rm=’rm -i’

Shorten apt-get installation commands:
$ alias canhaz=’sudo apt-get install’

Run firefox and open a specific website:
$ alias fftr=’/Applications/Firefox.app/Contents/MacOS/firefox-bin http://ss64.com’

Produce a custom prompt to display which machine you are on, the current folder, and the number of the current command:

   $ alias cd='cd !*; set currDir = `basename $cwd`; set currDir = `echo
"<${host}:"$currDir
" ! >"`; set prompt = "${currDir} "'
$ cd $cwd

<Mac_One:Work-folder 15 >

Making an alias permanent:

Assuming you have the BASH shell, then use your favorite text editor to edit or create a file called ~/.bash_aliases and add your alias commands.

alias is a bash built-in command.

“There are many reasons why novelists write, but they all have one thing in common – a need to create an alternative world” ~ John Fowles

Related:

Alias man page – Apple.com
env – Display, set, or remove environment variables
echo – Display message on screen
set – Set a shell variable
shift – Shift positional parameters

How to Diskpart Erase or Clean a Drive

How to Diskpart Erase or Clean a Drive

How to Diskpart Erase or Clean a Drive Through the Command Prompt

How to Diskpart Erase or Clean a Drive

source

Critical Instructions:

  • Disclaimer: Seagate Technology, LLC is not responsible for lost user data. Be sure to back up any important data on this drive before proceeding.
  • This article explains the Microsoft Diskpart Erase utility. The command that erases the drive during this process is “Clean”. In this article “Clean” and erase are used interchangeably. Cleaning or erasing a storage device removes all data and partitions from the drive.
  • Please read all steps, instructions, and warnings before attempting the Diskpart Erase/Clean. 
  • Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive. Please make certain that you are erasing the correct disk.
  • Remove all additional drives from the computer excluding the drive you are booting from and the drive you want to Erase/Clean.
  • For more information regarding Microsoft’s Diskpart Utility please select here: http://technet.microsoft.com/en-us/library/bb490893.aspx

Items to note:

  • This article will walk through the steps of using the Microsoft Diskpart Erase utility to Clean the disk of a previous partition and format, including any data on the drive. This command takes only a few minutes to complete.
  • This article covers Diskpart Erasing a 3TB or larger drive that has a Master Boot Record (MBR) Partition table, which is thereby limiting its capacity to 2TB. However, this article also applies to any scenario where a Diskpart Erase of an entire disk is necessary.
  • For more information regarding drives over 2TB and GPT/MBR partition tables please see the following articles.

  1. To determine the disk number assigned to the 3TB+ MBR partitioned drive follow the steps below.

    1. From the Start menu right click on Computer which will provide a drop down menu. (If you are on Windows 8 or 8.1 move your mouse to the bottom left hand corner of the desktop screen and right click. Then select Disk Management).
    2. Choose Manage.
    3. Select Disk Management (listed under Storage).
    4. Look for the drive that is identified as the 3TB drive (2794GB). The properties window shows that the partition table on the drive is MBR . Important: note the Disk number (such as Disk 1).
      Shows disk management with a properties box open. Disk 1 is squared off and there is an arrow pointing to "2048GB Unallocated" and Master Boot Record

  2. Open a Command Prompt window. To open the Command Prompt on a Windows Vista or Windows 7 machine click on Start and type cmd in the search bar. Then right click on cmd.exe and run as administrator. It will prompt you with the message, “Do you want to allow the following program to make changes to this computer,” click yes. A black Command Prompt window will open.
    Shows how to search for CMD from the Start Menu. There is an arrow pointing to the text cmd and the application cmd.exeOn Windows 8 move your mouse to the bottom left hand corner of the desktop screen and right click. Select Command Prompt (Admin) from the pop-up menu.
    Shows the pop up window from Windows 8. The Compand Prompt (Admin) is highlighted. There is an arrow pointing to Command Prompt (Admin)This is the Command Prompt window.
    Shows the command prompt window C:Windowssystem32>_ is the bottom line.
  3. From the command prompt, type diskpart and press Enter.
    Shows the command prompt window shows that I have typed "diskpart"The diskpart prompt will open.
    Shows the command prompt window that DISKPART> is now the selected command
  4. From the diskpart prompt, type list disk and press Enter.
    Shows the command prompt window and that I have typed "list disk"A list of disks will appear in a text format. You will return to the diskpart prompt. Step one verified that Disk 1 is the 3TB drive.Warning: Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive. Please be certain that you are erasing the correct disk. "Shows the command prompt window and displays all detected disks. Disk 1 is squared off. "
  5. From the diskpart prompt you will need to select a disk disk number (for instance, if the 3TB+ drive is Disk 1, you would typeselect disk 1) and press Enter. Warning: Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive. Please be certain that you are erasing the correct disk.
    Shows the command prompt window and that I have typed "select disk 1"A message appears saying that the disk is selected. You will return to the diskpart prompt. Warning: Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive. Please be certain that you are erasing the correct disk.
    "Shows the command prompt window and displays that Disk 1 is now the selected disk "
  6. From the diskpart prompt, type clean and press Enter. The drive’s partition, data, and signature is now removed. You will return to the diskpart prompt. Warning: Once you type clean and hit enter the drive will be erased. No warning will be provided.
    Shows the command prompt window and that I have typed "clean"
  7. The Command Prompt window will display the message “DiskPart succeeded in cleaning the disk“.  Close out of the Command Prompt window by clicking the red X in the upper right hand corner.
    Shows the command prompt window and displays DiskPart succeeded in cleaning the disk. DiskPart succeeded in cleaning the disk is squared off.Now the 3TB+ drive can be re-initialized, partitioned, and formatted.
  8. Reference How to use Add a New Disk/Reformat in Windows using DiscWizard v16 to Initialize the drive in GPT and format the drive for use.

How to Diskpart Erase or Clean a Drive

إغلاق جهازك الماك من Terminal

إغلاق جهازك الماك من Terminal

إغلاق جهازك الماك من Terminal

 

يمكن إيقاف تشغيل ال”ماك” الخاص بك بشكل صحيح لتجنب تكبد مشاكل مثل تعطل بعض الملفات في النظام. كل ما يتطلبه الأمر هو القليل من الصبر والقليل من الروتين الصحيح. يمكنك استخدام القائمة Apple لإيقاف جهاز الكمبيوتر الخاص بك، ووضعها على النوم، أو إعادة تشغيله، ولكن مع الـ “Terminal” يمكنك تحديد المزيد من الخيارات لاغلاق جهازك، بما في ذلك تسجيل خروج كافة المستخدمين ووضع أوقات معينة لإغلاق جهاز نظام التشغيل Mac الخاص بك. وهذه الأوامر هي في متناول يديك، وبالاضافة إلى ذلك حتى إذا كنت تدير الخادم أو ماك عن بعد من خلال SSH. بإمكانك متابعة القراءة لمعرفة المزيد.

 

إيقاف التشغيل Shutting Down

Terminal-shutdown-1

لإيقاف تشغيل جهازك ال”ماك”، يمكنك استخدام او كتابة الأمر التالي للقيام بذلك على

sudo shutdown -h now

 

h- يعطي الأمر لجهازك ويعلمه بالإيقاف التشغيل. بعد تنفيذ الأمر باستخدام كلمة المرور الرئيسية للنظام سيتم إيقاف تشغيل الجهاز، او عن طريق الحصول على صلاحيات الإدارة التي تتيح لك المجال أن تستدعي إيقاف تشغيل الجهاز.

 

إعادة التشغيل Rebooting

 

Terminal-shutdown-2

لإعادة تشغيل الجهاز، بإمكانك استخدام الأمر التالي لإعادة التشغيل:

sudo shutdown -r now

r- ينفذ عملية إعادة التشغيل ضمن أمر إعادة التشغيل. بعد تنفيذ الأمر سيتم إعادة التشغيل مباشرة.

 

وضعية النوم Sleeping

Terminal-shutdown-3

لوضع جهازك في وضع النوم أو وضع توفير الطاقة، بإمكانك استخدام الأمر التالي:

sudo shutdown -s now

Terminal-shutdown-5

عند تفعيل الأمر، سيتم وضع الجهاز في وضع توفير للطاقة. وان كنت تستخدم SSH البروتوكول الخاص بتشفير الاتصال وتأمين الاتصال. يجب عليك التأكد من إتاحة الخيار التالي “Wake for network access” من الخطوات التالية: System Preferences > Energy Saver

لن تتمكن من الدخول على الجهاز عن بعد إلا ان تم تشغيله يدويا بتحريك الفأرة أو الضغط على زر التشغيل أو الضغط على زر لوحة المفاتيح.

 

إستخدام إيقاف مؤقت Using a Timed Shutdown

في الأوامر السابقة تم استخدام “now” بعد كتابة الأمر المرغوب به. بحيث يقوم بإعطاء الأوامر للجهاز بالتنفيذ الفوري. ومع ذلك، بإمكانك ان تعطي الأمر للجهاز بالايقاف او وضعه في وضعية النوم او موفر للطاقة بعد فترة زمنية معينة. بإمكانك استخدام احدى الطرق التالية:

 

في وقت معين

 

بإمكانك إيقاف تشغيل الجهاز،إعادة تشغيل الجهاز، وضع النوم للجهاز، في وقت معين باستبدال “now” باستخدام احد التنسيقات التالية للتواقيت على سبيل المثال: yymmddhhmm . 

بحيث يبدأ ب “yy” أي السنة يتم كتابة العام المرغوب حسب التوقيت المتوفر في الجهاز، و “mm” الشهر اي في اي

شهر تريد، “dd” اليوم، “hh” الساعة بنظام ال24 ساعة، “mm” الدقيقة/الدقائق.

في المثال التالي أرغب في إيقاف تشغيل الجهاز في الساعة

So, if for instance, we wanted the computer to restart at 3:30pm on January 1, 2013, we’d issue the following command:

sudo shutdown -r 1301011530

After executing the command, you’ll be given the date and time of the shutdown in your system’s format, along with the process id (pid).

 

المصدر الرئيسي

إغلاق جهازك الماك من Terminal

إغلاق جهازك الماك الخاص بك من Terminal

إغلاق جهازك الماك الخاص بك من Terminal

Terminal 101 إغلاق جهازك الماك الخاص بك

يمكن إيقاف تشغيل ال”ماك” الخاص بك بشكل صحيح لتجنب تكبد مشاكل مثل تعطل بعض الملفات في النظام. كل ما يتطلبه الأمر هو القليل من الصبر والقليل من الروتين الصحيح. يمكنك استخدام القائمة Apple لإيقاف جهاز الكمبيوتر الخاص بك، ووضعها على النوم، أو إعادة تشغيله، ولكن مع الـ “Terminal”&nbsp;يمكنك تحديد المزيد من الخيارات لاغلاق جهازك، بما في ذلك تسجيل خروج كافة المستخدمين ووضع أوقات معينة لإغلاق جهاز نظام التشغيل Mac الخاص بك. وهذه الأوامر هي في متناول يديك، وبالاضافة إلى ذلك حتى إذا كنت تدير الخادم أو ماك عن بعد من خلال SSH. بإمكانك متابعة القراءة لمعرفة المزيد.</div>

إيقاف التشغيل Shutting Down

لإيقاف تشغيل جهازك ال”ماك”، يمكنك استخدام او كتابة الأمر التالي للقيام بذلك على الفور:

sudo shutdown -h now 

المصدر الرئيسي
Terminal 101 إغلاق جهازك الماك الخاص بك