2008年12月9日 星期二

Mac OS X 終端機用指令大全



本文出自InsanelyMac.com
Seal 稍微的翻譯了一點點... 這篇應該對初學 Mac OS X 的朋友有些幫助...
剩下的部份應該不難懂... 等Seal 比較有空的時候再想辦法翻完...


***BEGIN TERMINAL INFO***
***什麼是終端機***
First off, Terminal is Mac OS X's version of Konsole from Linux, or Command Prompt from Windoze. It is located in /Applications/Utilities, down at the bottom. To open it, double click it.
終端機可以說是 Linux 版的 Konsole 、Windows 系統裡的命令提示字元,在/應用程式/Utilities 裡的最下面可以找到。點兩下就可以執行它。

When it opens and has a rectangular block sitting there, it is ready for your command(s).
當他執行後,會有個矩形的方塊在畫面上,你就可以開始輸入你的指令啦。

Info about Root 什麼是Root
On UNIX based systems such as Mac OS X or Linux, root is the main user for the computer, which has access to *everything*. In other words, this is the System Administrator account, which lets you do maintenance, etc.
在以Unix為本的系統(Mac OS X 或是 Linux) root 是電腦最主要的使用者,擁有存取所有東西的權利。換句話說,就是電腦的系統管理員帳號戶,供你對系統進行維護或是其他的動作。

Login as Root (以Root 身份登入)
sudo -s

After typing that, it will prompt you for your user password, assuming you're on an administrator account. Once you are accepted, you can do the rest of these commands.
在輸入上面指令後,終端機會要求你輸入你的帳戶密碼來辨識你是使用管理員的身份。再輸入後,你就可以開始使用下面這些指令了。

OR 或者是:
su, which asks for the root password. If you don't have the root user enabled, follow the directions below. NOTE: Enabling the root user can be dangerous.
su 這個指令會直接要求root 的密碼。如果你還沒有啟用root 的帳戶,請依照下面的步驟。附註:啟用Root 帳戶可能會造成危險呦

Again, after typing that, it will ask for the root password.

在輸入上述指令後,終端機會要求你輸入密碼

Change root password 更改root 帳戶的密碼
If you don't like your root password, use:
如果你不喜歡你的root 帳戶的密碼,請使用:
sudo passwd root

Then type in your old root password, then give it a new password. If you had no root password before, it will simply ask you to enter a new password.
接者輸入你舊的root 帳戶密碼,再來輸入新的密碼。如果你的root 帳戶從來沒有設過密碼,終端機會直接向你要新的密碼。

WARNING: TERMINAL WILL *NOT* PROMPT YOU FOR CONFIRMATION OF DELETIONS, RENAMES, ETC. 警告: 終端機 “不會”詢問使用者是否要刪除、更改名稱等等動作,請小心使用。
***NOTE: sudo CAN BE LINKED WITH ALL OF THESE COMMANDS, IF YOU DO NOT WISH TO LOGIN AS ROOT; THIS WILL LET YOU ACT AS THE SUPER USER FOR THE ONE COMMAND.***
***附注:sudo 這個指令可以配合下列所有指令使用,如果你不想使用Root 帳戶登入電腦,這個指令可以讓你行使跟Root 帳戶一樣的權利***

Change directories 更動資料夾

To move around in the various directories, use cd.
Example: cd /applications
That will move you into the applications folder.
Typing cd with no argument will return you to the directory you were in before.

To change to a directory with spaces in the name, surround the directory name in quotes.
Example: cd /Applications/"XChat Aqua"
That will move you into a folder called XChat Aqua in the applications folder.

Move to other volumes/disks/partitions

To move to different volumes/disks/partitions, use cd again.
Example: cd /volumes/Mac
That will move you into the root (/) directory of the volume named Mac.

You can also change to a volume with spaces, much like the last hint.
Example: cd /volumes/"Mac OS X"

Remove a file from your Mac

This will remove a file from the same directory you are in:
rm
Example: rm something.txt

You can specify a path to a file to delete, if it is in a different folder.
rm /path/to/something
Example: rm /Applications/Candybar.app
This will remove the application Candybar from your applications folder:

This will remove a directory/folder on your Mac:
rm -d
Example: rm -d delete_me
(Say you had a folder called delete_me in /, your start disk's main folder)

Note: You can specify a path for this too, like the previous rm commands.

Copy a file

To copy a file, use:
cp
Example: cp something.txt somethingelse.txt
This will make a duplicate of something.txt and name it somethingelse.txt

Move a file
To move a file, use:
mv
Example: something.txt /Applications
This will move something.txt to the Applications folder.

Find a file
To find a file, use:
locate
Example: locate Callisto.kext
This will look for anything related to Callisto.kext on your system.

Find a binary file
To find a binary file, like rm, use:
whereis
Example: whereis rm
This will look for the rm command.

Create a folder
If you want to make a folder:
mkdir
Example: mkdir directory
Will make a folder called directory in the current folder you are in.

Move a folder
If you want to move a folder:
mv folder_name path
Example: mv folder /applications
Will move a folder called "folder" to applications.

NOTE: You can also specify a path if you want to put the folder somewhere specific.
Example: mkdir /Applications/directory

Repair Permissions of a folder
If you've been naughty and messed with the System/Library/Extensions folder at all, , you can repair the owner and permissions of the folder by doing:

chmod -R 755
chown root:wheel

chmod -R 755 /System/Library/Extensions
chown -R root:wheel /System/Library/Extensions

NOTE: This can also be done(to a lesser extent) through Disk Utility in /Applications/Utilities. Open Disk Utility and select your Mac Volume, then click Repair Disk Permissions.

Repair permissions in Terminal without DiskUtility
To repair permissions on your whole system without the need of disk utility, do:

diskutil repairPermissions /

List Files in a directory
If you want to view files in a folder, do:
ls

NOTE: This will show you the files in the current directory you are in. You can also do ls to see what's in a specific folder. Example: ls /applications
That will show you files in the Applications folder.

Text editing
If you want to edit various files in the Terminal:
nano
vi
emacs

Whichever you use is up to you. They all are text editors. NOTE: I have only used nano, so I can't really help people with vi or emacs.

You can also call TextEdit from the Terminal:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit

You can add the path of the file you want to edit to the end of the command line and it will open with TextEdit or just browse for it in TextEdit.

Add your own commands to Terminal!
If you want to add your own commands to terminal, follow these easy steps. In this example, we'll add a command called textedit, which will launch TextEdit with sudo priviliges, giving you a text editor with GUI capabilities that allows you to edit any file.
1. Open Terminal.
2. Type sudo -s, then enter your password.
3. nano /usr/sbin/textedit
4. paste this into the file: sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit
5. press CTRL+O, then enter to save.
6. Type textedit into terminal, and enjoy your new command!

***END TERMINAL INFO***

***BEGIN GENERAL MAC OS X INFO***

Run a Universal program in Rosetta
If you have a program that seems to be acting funny, and it's Universal, just right click(CTRL+Click for one button mice) the program, then choose Get Info, then when it pops up, look for a check box that says "Run in Rosetta". This will make the program run under Rosetta, Mac's PowerPC emulator, which allows for PowerPC apps to run, or Universal apps to run under PowerPC instructions.
N.B.: Not all programs have a "Run in Rosetta" option, so don't freak out if there's no option for it.

NOTE: ALL THE FOLLOWING CAN ALSO BE DONE ON HACKINTOSHES BY PRESSING F8 AT STARTUP WHERE IT WILL GIVE YOU A BOOT COMMANDLINE, WHERE YOU CAN INPUT YOUR OPTIONS THERE, SO THAT YOU CAN HAVE THOSE OPTIONS ON THAT BOOT ONLY.

Boot in verbatim mode to see errors/info about your mac
If you seem to be having weird errors with Mac and can't figure out why, try booting in verbatim mode, which tells you word for word what Mac is doing as it is starting up. In Terminal, navigate to /Library/Preferences/SystemConfiguration. Then sudo nano com.apple.boot.plist . Then below where it reads, "Kernel Flags", where it says , add -v between the two string angle brackets so it looks like this:
-v

After this, press CTRL+O to save the file and reboot. To remove verbatim mode, simply follow the steps again and just remove -v from the string line.

Force a screen resolution on startup
If you want to force Mac OS X to start with a certain screen resolution: you have to add a new key and string line to your com.apple.boot.plist.
Graphics Mode
1024x768x32@60
Where 1024x768 is the resolution you want, x32 is the color depth you want, and if you have VESA 3.0 graphics, @60 the refresh rate you want.

Startup in Safe Mode
If you want to boot up in Safe Mode if something is giving you problems, simply add -x to the kernel flags:
-x
Just follow previous instructions.

NOTE: All of these are to be added on the same line!

----------------------------------------------------------------------------------------------------------------------------------------
More OS X Shell commands can be found at...

http://www.ss64.com/osx/index.html
----------------------------------------------------------------------------------------------------------------------------------------

***END GENERAL MAC OS X INFO***

沒有留言:

張貼留言