Help - Search - Members - Calendar
Full Version: [INFO] Various Unix/Mac OS X terminal commands
InsanelyMac Forum > OSx86 Project > Tutorials (The Genius Bar)
Pages: 1, 2
Korrupted
I figured I'd post some useful information, since I didn't see a similar topic anywhere using Search, so here it is.

***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.

When it opens and has a rectangular block sitting there, it is ready for your command(s).

Info about 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.

Login as 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.

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

Change root password
If you don't like your root password, use:
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.

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.***

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 <filename>
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 <folder>
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 <filename> <name_of_copy>
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 <filename> <destination>
Example: something.txt /Applications
This will move something.txt to the Applications folder.

Find a file
To find a file, use:
locate <filename>
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 <binary file>
Example: whereis rm
This will look for the rm command. tongue.gif

Create a folder
If you want to make a folder:
mkdir <name_of_folder>
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, hysterical.gif , you can repair the owner and permissions of the folder by doing:

chmod -R 755 <path>
chown root:wheel <path>

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 <path> 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 <filename>
vi <filename>
emacs <filename>

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, "<key>Kernel Flags</key>", where it says <string></string>, add -v between the two string angle brackets so it looks like this:
<string> -v </string>

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.
<key>Graphics Mode</key>
<string>1024x768x32@60</string>
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:
<string> -x </string>
Just follow previous instructions.

NOTE: All of these are to be added on the same <string> </string> line!

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

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

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

That's it for now. If anyone thinks of anymore, or I think of anymore, I will add them to this guide. Enjoy!

Thanks to: Bofors, for the su info and the TextEdit from Terminal info, and Deetman for the Whereis and Locate commands.

June 20/'06 - Added in external link. Very good resource!
bofors
QUOTE(DaxTsurugi @ Apr 9 2006, 01:52 PM) *
Login as Root
sudo -s


What is the difference between that and just typing:

su
Korrupted
There is no difference, I'll add it to the guide. Thanks. smile.gif
bofors
QUOTE(DaxTsurugi @ Apr 9 2006, 01:52 PM) *
Text editing
If you want to edit various files in the Terminal:
nano <filename>
vi <filename>
emacs <filename>

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.


I like to do text editing in a real application. So I launch TextEdit (or Property List Editor in the Xcode-Developer Tools) as root like this:

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.
Korrupted
Added to the guide. I added thanks to you at the bottom. smile.gif
Hagar
QUOTE(bofors @ Apr 9 2006, 06:07 PM) *
What is the difference between that and just typing:

su



Actually, the difference between sudo -s & su is that:

sudo -s uses the users password (user must be a member of group wheel) whereas:

su uses the root password (which doesnt necessarily exist on all systems, & some consider it a secrity risk)
Korrupted
I didn't know that..thanks for telling us. smile.gif
time66
little ad.

I had both:
<string> -v </string> and
<string> "Graphics Mode"="1280x1024x32@60" </string>

didn't work...

seems u can only ad only one line?
i removed <string> -v </string>

and everything worked.....smile.gif
Korrupted
You do all those commands on one line. smile.gif
sigxcpu
sudo asks for the USER password, if it has administrative rights (e.g. /etc/sudoers file)
su asks for the ROOT password.

that is the difference
Korrupted
Hagar said that in a previous post already, but thanks for your input. smile.gif
Swad
Thanks for the info, DaxT!

It's guides like this that make the Genius Bar rock. :-)
Korrupted
Thanks. :)
Korrupted
Would anybody be willing to translate this info into other languages? That'd be neat if everyone could have this info, not just us English speakers. biggrin.gif
bilditup1
There's no way to move folders? Also, is there any difference between the cp command and the ditto command?
Korrupted
Added how to move a folder. As far as I can tell, there's no difference between 'cp' and 'ditto'.
bilditup1
Aight thanks. I was wondering about moving folders, appreciate it.

-eli b.
Korrupted
Added how to change directories, change to different volumes, as well as how to change into volumes/directories with spaces in the name. I can't believe I forgot those!
Korrupted
Added how to find files and binary files.
vassalle
QUOTE(bofors @ Apr 10 2006, 06:58 AM) *
I like to do text editing in a real application. So I launch TextEdit (or Property List Editor in the Xcode-Developer Tools) as root like this:

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.


thanks for the guide! anyway, is there a way to set an alias for a command or application? for eg, the textedit above, instead of typing sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit, cant i set an alias to maybe textedit?

to illustrate further, say when your playing cs, you can bind certain "command", say show timeleft. it will be something like
bind l timeleft
then everytime i press l, it will show the time left.

hopefully i'm making it clear enough. dont know how to explain it.
Korrupted
Added how to make your own Terminal Commands.
monkeysr
Replacing: <string>-v</string>

with:

<string>"Graphics Mode"="1280x960x32@85"</string>

Killed my OSX installation. It will no longer boot.
Korrupted
Then boot in -s to remove it smile.gif. I also fixed it to what it should really be.
monkeysr
Thanks! smile.gif
Korrupted
QUOTE(monkeysr @ Jun 19 2006, 03:08 AM) *
Thanks! smile.gif


Did the new fix work for you?
youraa
hi i 've been trying to change my resolution acording to your instructions and cannot menage could you pls help, i'm adding messages from my terminal

-bash: bluntman: command not found
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key></string>1280x1024x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key> </string>1280x1024x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string>"Graphics Mode"="1280x1024x32@60"</string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <string>"Graphics Mode"="1280x1024x32@60"</string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key> </string>1024x768x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$

pls help I'm new in these matters smile.gif
youraa
QUOTE
QUOTE
hi i 've been trying to change my resolution acording to your instructions and cannot menage sad.gif could you pls help, i'm adding messages from my terminal

-bash: bluntman: command not found
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key></string>1280x1024x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key> </string>1280x1024x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string>"Graphics Mode"="1280x1024x32@60"</string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <string>"Graphics Mode"="1280x1024x32@60"</string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <key>Graphics Mode</key> </string>1024x768x32@60</string>
-bash: syntax error near unexpected token `<'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$ <string> "Graphics Mode"="1280x1024x32@60" </string>
-bash: syntax error near unexpected token `newline'
zdzislaws-computer:~ zdzislaw$


You have to add that to your com.apple.boot.plist




Thx for the help:)
But must haxe mixed something up my system is not booting anymore sad.gif
I have the grey screen a nd the dashed circle rotating and nothing happens,
i read about similar pronlem of one of the guys but coludn't find the solution:(
In the file it looked like that:

<key>Graphics Mode</key>
<string>"Graphics Mode"="1280x1024x32@60"</string>


I replaced the <string></string> (I think) which was underneath the line <key>Graphics Mode</key> with <string>"Graphics Mode"="1280x1024x32@60"</string>

then I couldn't save sad.gif Now i know that I should use ctrl O)
so i copied the file to the desktop made the changes and overwrote the old file in the preferences folder

ehmm does it mean I need to format sad.gif?
How do i start in yhe -s mode?
thx for the help
panos
Not a good ideal to set a root account. Always use sudo instead. Protects you from Human Error.


I LAEK CHICKEN!
Korrupted
I just list it for people who want it. I never said to use it over sudo. tongue.gif
kuba
Find a file
To find a file, use:
locate <filename>
Example: locate Callisto.kext
This will look for anything related to Callisto.kext on your system.

--------------------------------

Beside the "locate" command there is the "find" command.
"locate" is dependant of the update database, while "find" is not.
The locate program searches a database for all pathnames which match the
specified pattern. The database is recomputed periodically (usually
weekly or daily), and contains the pathnames of all files which are publicly
accessible.
The find command is dependant on parameters about what you want to find (and where and how).

A casual example for the find command:
$find /usr -name somefile.txt

In the above command you have specified your find path to the /usr directory (or partition). You are searching for a "name" to be specific: "somefile.txt".
The find command has many parameters.
Just open a terminal and type "man find".

Cheers, Solaris Bob

Edit: here is a nice goody for the UNIX oriented MacOSX Geeks: http://rmn.ulaval.ca/manuals/oreilly/mac/index.htm

Although it is a copyrighted O'Reilly book, it is been put on the web by a university, so I suppose that part is legally covered... whistle.gif
willgonz
For an editor I like to use Pico. At the terminal type pico and it's there.
Crazor
There is an IMPORTANT difference between cp and ditto: ditto preserves ressource forks, whereas cp DOES NOT when used without the proper flags.
Also, ditto is much more powerful: it can handle archives, strip architectures from universal binaries etc.
Consult "man ditto" for more info.
Manaka
There are some other differences between the cp (and other file related UNIX commands) and Ditto that are Mac OS X version specific.

cp and mv in Mac OS X 10.3 and earlier did not support forked files. You had to use the Ditto command (with the appropriate switch - check the man page, or cpMac which was installed if the user had installed the developer tools.

As of Mac OS X 10.4 the cp and mv commands are resource fork aware and will work just fine without having to use Ditto.
Jdhore
QUOTE(sigxcpu @ May 1 2006, 09:11 PM) *
sudo asks for the USER password, if it has administrative rights (e.g. /etc/sudoers file)
su asks for the ROOT password.

that is the difference


That's not exactly correct...sudo gives you admin (or root) permissions just for the line in which you Sudo'd.
su is to login as root until you close the terminal and you don't su before a command...you:

su
password
command (s)
vassalle
hey Dax,

thanks for responding to my earlier comment regard creating the alias.. i followed your instruction but can't seem to run textedit from the terminal.. i get the following message
CODE
amir-hamzahs-computer:~ vassalle$ textedit
-bash: /usr/sbin/textedit: Permission denied


i've followed your instruction correctly, double triple checked it but still get the same error. do you know what am i doing wrong?

i'm running 10.4.8 with mikfi kernel.
realfolkblues
THanks for this it helps alot! biggrin.gif
Korrupted
I went ahead and made this a sticky so it's easier to find since Terminal is probably -the- most used program in OSX when experimenting with it.
myha
Hi,

can someone please tell me how to use aliases on mac? On linux I had .bashrc into which I added the aliases, how to do it on mac?

Thanks, BR
asap18
Usually you can just right click the file/folder and hit "make alias"
myha
Hi,

I ment aliases from console...

for example:
ll="ls -la"
this is what I use on linux...
Markandeya
I've found this side,it may help to you as well.

http://www.kernelthread.com/mac/osx/tools.html
nimb0z
whats the command to view the cd/dvd drive via terminal? I need to copy some files from there to system folder.
Korrupted
It's cd /Volumes/Name_Of_Your_CD where Name_Of_Your_CD is obviously the name of your cd. For example, if you have Warcraft III, its cd name is The Frozen Throne, and thus you would type cd /Volumes/"The Frozen Throne". If you want to see all the drives Mac currently sees, just go to /Volumes with cd /Volumes, then type ls, which will show you a list.
soup4you2
This is not a terminal command but a little trick. sometimes i like the feel of just the console with no GUI present. You need to have it set so you have to type in your username and password.

In the username field enter:

>console

then press enter.. *poof* full screen terminal.
peterblood
to make an alias, just type
alias ll='ls -l'
MONGO!
Found this browsing around for Terminal info.

It's a fun command that lets you set your preferred screensaver as your desktop:

/system/library/frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/contents/macos/screensaverengine -background
dan98203
Hi everyone, I would like to know if there is a way to enable the administrator account through the terminal since it is not active on the Imac? i don't have any passwords for the users who are currently on the imac so I can't login to any accounts.
SunLizard
Greetings,

I'm *trying* to get OSX86 (10.4.8 patched w/SSE2 & SSE3) installed on my homebulit system. I've got some Linux/Unix experience (in other words, I can hurt myself in a shell) but am not familiar with the capabilities of the Single User mode when booting. [ie what I can and can't do in single user mode]

The Question: Can I mount the drives to the /Volumes/ folder the same way at command line shell the same way as *nix? (eg 'mount /dev/disk0 /Volumes/DVDrom')

Background: I can get OSX installed but it has issues on first boot with my PCIe card (specifically addressed in the Video Forum.) I think Callisto kexts will set me free, but I can't get the bloody files of the CD I burned them to as the only drive recognized in Single User ( '-s' at the boot options screen.) Sidenote: I can't get the safe mode '-x' to boot properly either as once its starts to bring up GUI (QE/CI) the machine halts. So I *think* I'm stuck with Single User mode until I get the Callisto drivers installed.

Thanks in advance.
S_L
triofour
hy!


i only can start with pressing x while startup! what does it do? i found just descriptions like "force mac os startup"? and: is there any flag for that i could ad to the bootlistfile?!

thanks
triofour
Gooly
Will be usefull, if you can include few usefull kernel parameters. wink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.