mac-Terminal commands

Source: Internet
Author: User
Tags bit set cpu usage

Find a better explanation of the command under the Mac Terminal document, paste the full text here, so as not to lose (the original text here):

Mac Terminal command line "one" Bash terminal settings
1. Environment variable Settings
The first thing to know is what kind of shell you use for Mac OS x, using commands
Echo $SHELL
If the output is: CSH or TCSH, then you are using C Shell.
If the output is: bash,sh,zsh, then your use may be a variant of the Bourne shell.
Before Mac OS X 10.2, the default is C Shell.
The default is Bourne Shell after Mac OS X 10.3.
I'm using Mac OS X 10.6.7--bash.
After opening the shell, the default is in the $home directory
setting of the PATH variable
Type: VI. bash_profile Enter, edit. bash_profile file
Press I to enter insert text edit mode
Find a row that sets the PATH environment variable, and add the full path (for example:/usr/local/mysql/bin) you want added. If you do not find the line that sets the path variable, you can add a line yourself:
Export Path=${path}:/usr/local/mysql/bin
Linux, or UNIX, is
Export path= $PATH:/usr/local/mysql/bin
Or:
Export Path=/usr/local/mysql/bin: $PATH
Press ESC to exit the Insert text editing mode
Type Wq carriage return, save and exit the VI editor
If you do not restart, type source. bash_profile immediately make the file effective
Otherwise, the logout will be effective.
Two, color settings
~/.bash_profile is the profile of the currently logged in user in the bash shell. Bash is the default shell in "terminal".
The Clicolor is used to set whether the color is displayed. The CLI is the abbreviation for command line interface.
Lscolors is used to set the color of various file types when Clicolor is enabled. Each of the two letters in the Lscolors value sets the text color and background color for a file type, respectively. A total of 11 sets of color settings in the lscolors, according to the order, respectively, the following file types are set:
①directory
②symbolic Link
③socket
④pipe
⑤executable
⑥block Special
⑦character Special
⑧executable with setuid bit set
⑨executable with Setgid bit set
10.directory writable to others, with sticky bit
11.directory writable to others, without sticky bit
In Lscolors, the letters represent the following colors:
A black
b Red
C Green
D-Brown
E Blue
F Magenta
G Cyan
H Light Grey
A Black Bold
B Red Bold
C Green Bold
D Brown Bold
E Blue Bold
F Magenta Bold
G Cyan Bold
H Light gray Bold
X system default Color
So, if we want to display the catalogue in red, we can set the lscolors to Bxfxaxdxcxegedabagacad, so you can tell by comparing this table:
Lscolors=bxfxaxdxcxegedabagacad

Backgrounds can be set and transparent in preferences



Note
Manipulate files and directories with spaces in the name
The space is written in the command \ \ Space, such as to enter My documents, the command for CD my\\ Documents

"Two" Mac OSX under the command line

The following command line is Unix,linux,os x common command line, some OSX exclusive

1. Background service Management
Launchdaemons is the service that the user started before logging in (daemon)
Launchagents is the service (daemon) that is started after the user logs on

Plist file directory for services
~/library/launchagents Per-user agents provided by the user.
/library/launchagents Per-user agents provided by the Administrator.
/library/launchdaemons System-wide Daemons provided by the administrator.
/system/library/launchagents Per-user agents provided by Mac OS X.
/system/library/launchdaemons System-wide daemons provided by Mac OS X.

Disabling services
Need to use a tool directive provided by Mac OS Launchctl
The LAUNCHCTL directive sets a disable flag for the service, and when Launchd starts, it checks whether the service is disabled to determine whether the service needs to be enabled.
Locate the Disable flag file/var/db/launchd.db/com.apple.launchd/overrides.plist First,
Check to see if the service you want to disable has been disabled. Some services have been disabled, but not listed in Overrides.plist. At this point, you also need to check if the plist file for this service has a label field marked as disable.

Method of disabling a service 1
After confirming that the service is not disabled, we can disable the service by invoking the following command:
$sudo launchctl unload plist file path
$sudo launchctl unload-w plist file path
For example, if you disable Spotlight, enter
$sudo Launchctl Unload/system/library/launchagents/com.apple.spotlight.plist
$sudo Launchctl unload-w/system/library/launchagents/com.apple.spotlight.plist
When the service is disabled, restarting the Mac OS can take effect.
Method of disabling a service 2
A more effective and violent approach (recommended)
Uninstall the service first
$sudo Launchctl Unload/system/library/launchagents/com.apple.spotlight.plist
Then the plist file mv to a different directory backup. Reboot. Get.

Restore Service:
Method 1:
$sudo launchctl load-wf plist file path
Method 2:
The backup plist file mv back to the original folder.
$sudo launchctl load plist file path

View the status of a service
#launchctl List
(You can also use the graphical tools Lingon, modify the service)

2. Run Routine maintenance scripts
$sudo Periodic script Name enter
The script name should be daily, weekly, or monthly. If you want to run three maintenance scripts at the same time, you can enter:
sudo periodic daily Weekly monthly

3. Display the kext used by the current system
$kextstat

4. View IO Usage
$iostat 1

5. View System usage

CPU Usage
$top-L 2 | awk '/cpu usage/&& NR > 5 {print $, ":", $ $, $4, $ $, $6, $7, $8} '

CPU program Running Process
$ps-arcwwwxo "pid%cpu command" | Egrep "Pid|$1" | Grep-v grep | head-12 | Tail-11

Memory already in use

$top-L 1 | awk '/physmem/{print ' Memory used: ' $8} '

Non-active memory
$top-L 1 | awk '/physmem/{print "Memory Inactive:" $6+$10 "M"} '

Hard Drive information
$DF-G | awk '/\/dev\/disk0/{print $2-$3 "G of" $ "G remaining" "(" $ $ ")"} ";

To view the files used by a program
$sudo fs_usage-w-F filesys software name



6. Disabling the spotlight Index
Close Spotlight Index
$sudo mdutil-i off
Clear Spotlight Index
$sudo MDUTIL-E
When you need the spotlight feature, you can restore it again:
$sudo Mdutil-i on

Disabling the spotlight index on a disk
$ sudo mdutil-i off/volumes/your_hard_drive_name_1
Remove Spotlight index from disk
$ sudo mdutil-e/volumes/your_hard_drive_name_1
To delete an indexed spotlight file
$ CD/
$ sudo rm-fr. spotlight-v100


7.lipo is a tool for working with generic programs (Universal Binaries) in Mac OS x.
Example: Keep x86 code (you can use CLEARMYMAC software or you can delete generic binaries that are not used)

$CD/applications
$ Lipo Stickies.app/contents/macos/stickies-thin I386-output stickies.app/contents/macos/stickies.i386
$ CD stickies.app/contents/macos/
$ RM stickies
$ mv stickies.i386 Stickies





8. Set sleep mode
$pmset-G
Display setup Information
$sudo pmset-a Hibernatemode Modenumber
Modenumber is 0,1,3.
0: In this mode, if the system goes into hibernation, the battery or power will continue to power the memory, but will not write any state to the hard drive. If the power supply is not interrupted or the battery is not in the low state when the system resumes from hibernation, the system can instantly revert to the dormant state due to the uninterrupted power supply of the memory.
1: In this mode, when the system enters hibernation, the memory data will be written back to the memory image file of the hard disk hibernation, and the memory will be powered off like other hardware. When recovering from hibernation, since the memory data has disappeared, it must be from the memory image file to write all the pre-hibernation data into memory, due to the IO bottleneck of the hard disk, the process will be significantly longer, so the user will see a progress bar on the screen, and so on when the write memory operation is completed before the computer reverts to hibernation state
3: This mode is also called safe sleep mode, listen to its name to know that he is very safe it is also called mixed sleep mode, because he is mixed with mode 0 and mode 1 features. When entering hibernation, the memory data will not only be written back to the memory image file as Mode 1, but the system will maintain power to the memory module during the whole sleep process. The result is that the in-memory data exists in two places simultaneously: in-memory and in the image file. If the power supply or the battery is normally powered during hibernation recovery, the system recovers instantaneously like mode 0, with in-memory data. If the power is interrupted when the sleep recovery or the battery is exhausted, as long as the power is plugged in, the same can safely restore the system from hibernation, this time with the hard disk memory image files in the state to restore, the recovery process and Mode 1 is a bit slow.

Specifies the path where the memory image file exists
sudo pmset-a hibernatefile <filepath>

In 0 mode, you can delete the memory image file to save hard disk space

9. Changing the startup mode with NVRAM
To view the current NVRAM settings:
Nvram-p
Display XML format:
Nvram-xp
Start in Safe mode?? sudo nvram boot-args= "-X"?? (If you want to start in verbose mode at the same time, you can use sudo nvram boot-args= "-x-v")?
To return to normal startup mode, execute the following command on the terminal or command line:?? sudo nvram boot-args= ""

To control the volume of the boot tone:
Mute-Use the following command:
sudo nvram systemaudiovolume= "%80"
Set a special volume, such as:
sudo nvram systemaudiovolume=2
It's a big voice.
Set the volume to 0:
sudo nvram systemaudiovolume= ""


10. Other Tricks

Force Eject Disc
$drutil Tray Eject

Close the emergency motion sensor
$sudo pmset-a SMS 0
Re-enable burst motion sensor
sudo pmset-a AMS 1

Manually clear the DNS cache
Dscacheutil-flushcache?
Serial Debugging Equipment
Screen/dev/tty.usbserial 9600

"Three" uses the defaults to adjust the school system

1.Finder Show hidden files
$defaults Write Com.apple.finder Appleshowallfiles-bool YES
The finder needs to be restarted to apply the changes, then enter in the terminal
$killall Finder
and enter
Recover hidden Invisible, enter the following code in the terminal and return
$defaults Write Com.apple.finder Appleshowallfiles-bool NO
The same finder needs to be restarted
$killall Finder

Force Finder to show hidden files and folders
$defaults Write Com.apple.Finder appleshowallfiles True

2. Enable or disable additional logs for Installer.app
$defaults Write Com.apple.installer Debugchoiceattrengine-bool YES
$defaults Delete Com.apple.installer Debugchoiceattrengine

Add a "Recent application" folder to the 3.Dock column to display the 10 most recently launched software methods
$defaults Write Com.apple.dock persistent-others-array-add ' {"Tile-data" = {"List-type" = 1;}; "Tile-type" = "recents-tile"; }‘
Return, enter again
$Killall Dock

4. To turn off the dashboard function
Open Terminal, enter
$defaults Write Com.apple.dashboard Mcx-disabled-bool YES
$killall Dock
To re-open, enter in the terminal
$defaults Write Com.apple.dashboard Mcx-disabled-bool NO
$killall Dock

5. Prohibition of production. Ds_store file
$defaults Write Com.apple.desktopservices dsdontwritenetworkstores True

6. Change the screenshot file default storage location
Open Terminal, enter
$defaults Write Com.apple.screencapture location/path/
/path/is the save path that you want to set, such as storing the file in the picture folder of the user directory, the command is:
$defaults Write Com.apple.screencapture location ~/pictures/
And then enter
$killall Systemuiserver
Storage type
$defaults write com.apple.screencapture type jpg

7. Change how your Mac displays Help
$defaults Write Com.apple.helpviewer Devmode-bool True
Want to restore
$defaults Delete Com.apple.helpviewer DevMode

8. Turn off, turn on spaces dynamic effect when switching
$defaults Write Com.apple.dock workspaces-swoosh-animation-off-bool YES && killall Dock
You want to open
$defaults Write Com.apple.dock workspaces-swoosh-animation-off-bool NO && killall Dock

9. Change the system font size (menu, etc.)
$defaults Write Nsglobaldomain Appledisplayscalefactor 1.25

Here the number of the side, the default value is 1, the larger the size of the font you want to recover, enter in the terminal
$defaults Write Nsglobaldomain Appledisplayscalefactor 1

10. Change the landing background
Enter in the terminal
$defaults Write/library/preferences/com.apple.loginwindow desktoppicture "/library/desktop%20pictures/nature/ Aurora.jpg "
Inside the quotation marks is the picture path

Use of "three" Fink

Almost all of Fink's files are installed in/SW (or where you choose to install them). So, if you want to remove Fink, enter the following command:
sudo rm-rf/sw
Upgrade Fink itself
Fink Selfupdate?fink Selfupdate-rsync?fink Index-f?fink selfupdate
Installation
Fink Install XXX
Unloading
Fink Remove xxx
If you want to also unload the dependent packages, add-R. If you want to uninstall the configuration file, use the
Fink Purge
Similar to the remove–purge inside Ubuntu
Update all installed Packages
Fink Update-all
View Installable Packages
Fink list xxx or fink apropos xxx
also supports positive-ze expressions
Fink List "xxx*"
View descriptions of related packages
Fink Info
If you accidentally delete a file for a package, you want to reinstall the entire package
Fink Reinstall
Show dependencies for a package
Fink Show-deps XXX

mac-Terminal commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.