Jump to content

[INFO] Various Unix/Mac OS X terminal commands


83 posts in this topic

Recommended Posts

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. :P

 

Hi this is my first post in the forum and since you asked im responding to you... im Portuguese and i would be glad to translate this guide to portuguese if you still want to.

 

Im a windows user but now im trying to get lost in the mac world ( tryed to install 10.4.6 on a acer aspire 5050 but it wasnt a good experience since i had problems with the kernel at booting up after the installation so im going for the 10.4.9 now to give it another try.)

 

So this guide is being a precious help in understanding how mac works and, like i said, it would be my pleasure to translate it for you in portuguese if you want. PM me or send me the full guide in PDF to hgserv@gmail.com

 

Best Regards

 

Hugo

Link to comment
Share on other sites

  • 4 weeks later...

Something good for use with Automator e.g. :-Run Shell Script

if [ -d /Volumes/DVD ]then hdiutil unmount /Volumes/DVDfi

What it will do is that 1- Check if directory /Volumes/DVD exist2- Then run the 'hdiutil unmount /Volumes/DVD'3- EndSave it as Application then add it to your startup itemsAnother tip to look for specific files and or directories...find /Users/user -name yourfilename -type f -print

find <location> -name <filename> -type f <file> d <directory> -print <to view>

Another thing you can do isfind location -name filename -type f -exec chmod -v 644 {} \;

find <location> -name <filename -type f <file> -exec <execute> chmod -v <verbose> 644 {} \;

Or you can combine some other functions...

Link to comment
Share on other sites

  • 3 weeks later...
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. :huh:

 

Hi everybody, I'm new in this forum but i find it very interesting ^^

I can translate it in French if you want.I can do it for next week ( let's say for Wednesday because i'm a little busy this w-kend)

Reply me if it 's ok for you.

Bye ^^

Link to comment
Share on other sites

  • 3 weeks later...

I feel super-dumb right now, but i cannot find com.apple.boot.plist. I looked in Library/Preferences/SystemConfiguration, and it wasn't there. I looked in spotlight (over the entire hard drive). I typed sudo find . -name "com.apple.boot.plist" into terminal and after about 10 minutes it finished with no output.

 

I am using 10.4.10 on an emac (G4 1.25GHz). Any ideas?

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

DaxTsurugi

I have something I did not see on your list on the first page

 

$hdiutil burn filename.iso

or

$hdiutil burn -noburnverify filename.iso

This will not do any verify and be much faster

 

I can kick off a burn in the two seconds to type hdiutil burn filename.iso vs. the navigating and clicking around with a gui burning app.

 

I had to research it and others might find it useful

Link to comment
Share on other sites

  • 4 weeks later...

Here are my Terminal Tweaks:

 

Make your "ls" more Colorfull:

- Open a Terminal

- type "vi ~/.bash_profile"

- insert the following lines:

export CLICOLOR=1
 export LSCOLORS=ExFxCxDxBxegedabagacad

- Try changing the Color codes for other Colors :(

 

Make your Vi and Vim Colorfull & More:

- Open a Terminal

- type "vi ~/.vimrc" for Console vi

or type "vi ~/.gvimrc" for Grafical Vim

- add some lines into the file:

set nocompatible
syntax on
set tabstop=4
set backspace=2

- you can find more commands if

you use google with the words "gvimrc" or "vimrc"

 

Add your own "Commands":

- Open a Terminal

- type "vi ~/.bash_profile"

- instert in example:

alias la="ls -la"

- close your Terminal and open it again

- now you have easy file-list-access via "la"

Link to comment
Share on other sites

Eject!

 

umount /Volumes/SomeVolume

 

Mount!

 

mount /dev/disk0s2 /Volumes/SomeDir

 

though you might have to mkdir /Volumes/SomeDir first.

 

 

Comes in handy with stubborn volumes.

 

Keep in mind if you navigate to /Volumes first (cd /Volumes), you can leave out those parts referencing the directory.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

Hello,

 

the ls command list the content of a directory but I always prefer ls -la

the l option outputs in a list with more info for each files (dates, permissions, etc.. )

the a opion outputs also the hiden files (on Unices the hiden files start with a . )

 

more option with the ls manual page:

man ls

 

Because I prefer ls -la and it's boring to type it everytime I created an alias:

alias 'la=ls -la'

And I added this line to the bashrc file (it's like an autoexec.bat on Dos, it's run each time a shell is started)

On Mac OsX there is a bashrc that is system wide (for all users)

bashrc is located in /etc/

 

So any user just have to type la in any terminal...

 

--

Jmp0

Link to comment
Share on other sites

is there a command to run apps?

 

like for instance system prefs?

 

cause at my school i can run most blocked apps thru right click --> show package contents -->contents -->mac os -->"program's name" (it has a terminal icon)

 

but when i do that with system prefs nothing is active.. all the buttons are greyed out.

Link to comment
Share on other sites

  • 2 weeks later...

i'm surprised i havent seen the wonderful useful command line text search tool GREP

 

$ ls -al | grep string

 

the string is anything you're looking for ... or

 

if your looking for something in your logs that you need

 

& cat /var/log/system.log | grep whatever

& cat /var/log/secure.log | grep failure .... this one shows you only the lines that have the word failure in them ...

 

that's really all i can think of right now :)

Link to comment
Share on other sites

  • 1 month later...

Add a few more:

 

To find our your details of your System like kernel version, CPU architecture etc: uname

hostinfo
Mach kernel version:
 Darwin Kernel Version 9.3.0: Fri May 23 00:49:16 PDT 2008; root:xnu-1228.5.18~1/RELEASE_I386
Kernel configured for up to 2 processors.
2 processors are physically available.
2 processors are logically available.
Processor type: i486 (Intel 80486)
Processors active: 0 1
Primary memory available: 3.00 gigabytes
Default processor set: 69 tasks, 234 threads, 2 processors
Load average: 0.01, Mach factor: 1.98

 

Also uname

uname -a
Darwin HOSTNAME.local 9.3.0 Darwin Kernel Version 9.3.0: Fri May 23 00:49:16 PDT 2008; root:xnu-1228.5.18~1/RELEASE_I386 i386

Link to comment
Share on other sites

  • 2 weeks later...

I just got a little Stupid thing that happens:

 

Repair Permissions of a folder

If you've been naughty and messed with the System/Library/Extensions folder at all, :P , 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.

 

When I DO dis little thing it says this little thing uh, ah, "Operation Not Permitted"

 

-Wt_?? That aint a question though.

Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

I appreciate the time it took to write a guide, thanks. What I Want to know is, can I cut and paste terminal commands? As I research all the changes that others are suggesting for setting up my new system (still shipping), I see I have a few lines of things to write into the terminal. And I know that typing and spaces do matter. I was wondering if I could be setting up (saving) a text file in BBEdit now with the set up lines of code for when I get my system in the mail?

 

It would add to my confidence level if I could cut and paste long or multiple lines of command lines in the terminal. Possible?

 

Thanks

Link to comment
Share on other sites

You can copy and paste in terminal, use the same key combination as in other applications. command-c , command-v

 

One thing I find practical in terminal is "open ." It opens the current directory as a finder window. It's good if you want to drag and drop files into the terminal window (lazy way to get paths right) or open directories in finder that are hidden normally.

Also, "man man" gives you the manual for the manual :-)

Link to comment
Share on other sites

You can copy and paste in terminal, use the same key combination as in other applications. command-c , command-v

 

One thing I find practical in terminal is "open ." It opens the current directory as a finder window. It's good if you want to drag and drop files into the terminal window (lazy way to get paths right) or open directories in finder that are hidden normally.

Also, "man man" gives you the manual for the manual :-)

Thanks. I have messed around with the terminal enough not to be really "afraid" of it, but only just. I have done some MDLS lookups with my Mail and MailSmith indexes and moved that data to my database language. I have looked at Man pages here and there, mostly as an outsider. The only real taste I get on a regular basis of UNIXy flavored Mac is the occasional boot I do into single user mode to run Applejack.

 

Which reminds me, any idea if Applejack would break my hack? Or, if Applejack would properly repair permissions? I read in another thread where repairing permissions had to be done in a specific way with the hack process and standard permission repair programs would not work for this purpose. I do have the recommended program downloaded and in my kit, ready to go. But would Applejack do this as well?

 

Thanks

Link to comment
Share on other sites

  • 11 months later...

What about OS X commands when booting the INSTALL DVD and running terminal. I know its shell or bash commands, but it seems that lot of commands are disabled. "rm" is disabled because im trying to remove dsmos.kext and it wont let me. Is there a way around rmdir if there are files in the dir. Again it wont let me.

Link to comment
Share on other sites

  • 2 weeks later...
Not exactly a command, but saves a lot of work and helps on the guessing is the TAB-completion.

 

Tab ROCKS!!!

If you hit tab and it doesn't fully complete the string it can mean that there are multiple options, hit tab twice to show the options available.

Link to comment
Share on other sites

**DUTCH VERSION OF THIS GUIDE (TRANSLATED BY ME :() IT IS NOT YET TRANSLATED FULLY BUT I'LL EDIT THIS POST SEVERAL TIMES TO MAKE COMPLETE TRANSLATION.** // **NEDERLANDSE VERSIE VAN DEZE HANDLEIDING (VERTAALT DOOR MIJ ;)) HIJ IS NOG NIET COMPLEET VERTAALD, MAAR IK ZAL DEZE POST EEN AANTAL KEER BEWERKEN OM ER EEN VOLLEDIGE VERTALING VAN TE MAKEN.**

 

***BEGIN TERMINAL INFO***

Als eerste, Terminal is Mac OS X's versie van Konsole in Linux of Opdrachtprompt in Windows. Je kan het vinden in /Programma's/Hulpprogramma's, beneden. Om het te openen, dubbel-klik er op.

 

Als het is geopend, en je ziet een rechthoekig blokje in het venster, dan is het klaar om jouw commando's in te voeren.

 

Info over Root

Op UNIX-achtige systemen, zoals Mac OS X en Linux, root is de hoofdgebruiker van de computer, wat toegang heeft tot *alles*. In andere woorden, dit is het Systeem Administrator account, wat je onderhoud laat doen, etc.

 

Login als Root

sudo -s

 

Als je dit intypt, dan zal het vragen om jouw gebruikerswachtwoord, denkend dat jouw gebruikersaccount een Administrator account is. Na dit, kan je commando's invoeren die het nodig vinden om root te zijn.

 

OF:

su, wat voor de root wachtwoord vraagt. Als je dit nog niet hebt, volg dan de instructies hieronder. WAARSCHUWING: het aanzetten van de root-modus kan gevaarlijk zijn!

 

Opnieuw, nadat je dat hebt ingevoerd, zal het vragen om het root wachtwoord.

 

Verander root wachtwoord

Als je het wachtwoord van root niet leuk vind, gebruik:

sudo passwd root

Daarna, typ in je oude root wachtwoord en daarna het nieuwe root wachtwoord, naar jouw keuze. Als je eerder nog geen root wachtwoord had, dan zal het alleen vragen om een nieuw root wachtwoord.

 

WAARSCHUWING: TERMINAL VRAAGT NIET OF JE HET ZEKER WEET ALS JE DINGEN GAAT VERWIJDEREN, HERNOEMEN, ETC. EN KAN GEVAARLIJK ZIJN.

***NOTITIE: sudo CAN GELINKT WORDEN MET ALLE VOLGENDE COMMANDO'S, ALS JE HET ZONDER sudo DOET, DAN ZAL HET JE NIET AANWIJZEN ALS IEMAND DIE ROOT IS, MAAR EEN SUPERGEBRUIKER.***

 

Verander mappen

 

Om rond te bewegen doro verschillende mappen, gebruik cd.

Voorbeeld: cd /programma's

Dat zal je verplaatsen naar de Programma's map.

Intypen van cd zonder argument leidt dat het je zal doorsturen naar de laatst in wezende map.

 

Om naar een map te veranderen die spaties bevat, stop aanhalingstekens rond deze map.

Voorbeeld: cd /Applications/"XChat Aqua"

Dat zal je verplaatsen naar de XChat Aqua map in de Programma's map.

 

Verplaats naar andere volumes/disks/partities

 

Om je naar andere volumes/disks/partities te verplaatsen, gebruik cd opnieuw.

Voorbeeld: cd /volumes/Mac

Dat zal je verplaatsen naar de root map (/) van het volume Mac.

 

Je kan ook naar volumes plaatsen die spaties bevatten, net zoals de laatste hint.

Voorbeeld: cd /volumes/"Mac OS X"

 

Verwijder een bestand van jouw Mac

 

Dit zal een bestand verwijderen die in dezelfde map is waar jij bent:

rm <bestandsnaam>

Voorbeeld: rm iets.txt

 

Je kan ook een pad naar iets typen, zodat je ook bestanden in andere mappen kan verwijderen:

rm /pad/naar/iets

Voorbeeld: rm /Programma's/Candybar.app

Dit zal een applicatie genaamd Candybar verwijderen uit je Programma's map.

 

Dit zal een hele map verwijderen uit je Mac:

rm -d <map>

Voorbeeld: rm -d verwijder_mij

(Zeg maar dat je een map hebt genaamd verwijder_mij in de root van je Mac (/))

 

Notitie: hier kan je ook weer een heel pad naar typen, net zoals eerder.

 

Kopieer een bestand

 

Om een bestand te kopieeren:

cp <bestandsnaam> <naam_van_kopie>

Example: cp iets.txt ietsanders.txt

Dit zal iets.txt dupliceren en veranderen in ietsanders.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. :P

 

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, ;) , 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!

Link to comment
Share on other sites

 Share

×
×
  • Create New...