Tuning sysctl.conf

Dành cho con giời nào thích phá. Mở terminal, gõ sudo nano /etc/sysctl.conf enter, điền password xong paste cái này vào:

kern.sysv.shmmax=536870912
kern.sysv.shmall=131072
kern.sysv.shmmin=1

kern.sysv.shmmni=12288
kern.sysv.shmseg=12192
kern.sysv.semmns=99541
kern.sysv.semmni=87381
kern.sysv.semmsl=99541

kern.maxproc=2048
kern.maxprocperuid=1024
kern.ipc.somaxconn=8192
kern.ipc.maxsockbuf=4194304
kern.ipc.somaxconn=32768
net.inet.tcp.rfc1323=1
net.inet.tcp.win_scale_factor=3
net.inet.tcp.sockthreshold=16
net.inet.tcp.sendspace=250000
net.inet.tcp.recvspace=250000
net.inet.tcp.mssdflt=1440
net.inet.tcp.msl=10000
net.inet.tcp.always_keepalive=1
net.inet.tcp.keepidle=120000
net.inet.tcp.keepinit=1500
net.inet.tcp.keepintvl=1500
net.inet.tcp.delayed_ack=0
net.inet.tcp.slowstart_flightsize: 4
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.inet.icmp.icmplim=50

net.local.stream.sendspace=163840
net.local.stream.recvspace=163840
net.local.dgram.recvspace=4096
net.inet.tcp.slowstart_flightsize=89
net.inet.tcp.local_slowstart_flightsize=10
net.inet.tcp.mssdflt=1460
net.inet.tcp.delayed_ack=3
net.inet.tcp.delayed_ack=0
net.inet.tcp.delayed_ack=3

xong bấm Ctrl+X, bấm Y, Enter, gõ reboot, enter và cảm nhận nhé.

Database size

use master

declare @PageSize varchar(10)
select @PageSize=v.low/1024.0
from master..spt_values v
where v.number=1 and v.type=’E’

select name as DatabaseName, convert(float,null) as Size
into #tem
From sysdatabases where dbid>4

declare @SQL varchar (8000)
set @SQL=”

while exists (select * from #tem where size is null)
begin
select @SQL=’update #tem set size=(select round(sum(size)*’+@PageSize+’/1024,0) From ‘+quotename(databasename)+’.dbo.sysfiles) where databasename=”’+databasename+””
from #tem
where size is null
exec (@SQL)
end

select * from #tem order by DatabaseName
drop table #tem

Tweaking

Terminal Commands – Leopard Tweaking

The default shell for Leopard users is Bash. Although many GNU/Linux users are familiar with it, not all Mac users take full advantage of its power. Here are some very useful terminal commands and tips for hidden Mac OS X settings.

You’ll find the Terminal in the Utilities folder within the Applications folder. To carry out any of the following commands you will need to copy/paste or type in the line of text then hit enter. For the most part, applications will need restarting before changes take place.

Finder

  • Removes the stripes in list view. Repeat the command with TRUE to reverse.
    defaults write com.apple.finder FXListViewStripes -bool FALSE
  • Enable the hidden menu item within the Finder menu itself.
    defaults write com.apple.finder QuitMenuItem -bool YES
    You’ll have a “Quit Finder” menu item within the Finder menu itself.
  • Resets the “Open With” menu, clearing duplicates.
    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
  • Changes the title of a window to its full path. Repeat with NO to reverse.
    defaults write com.apple.finder _FXShowPosixPathInTitle -bool YESfinder-full-path
  • Sets expanded save dialogs as default (showing column/list view of folders rather than a drop down menu). Replace TRUE with FALSE to reverse.
    defaults write -g NSNavPanelExpandedStateForSaveMode -bool TRUE
    open/save expanded save dialog
  • Shows hidden files in the Finder. Replace TRUE with FALSE to hide hidden files again
    defaults write com.apple.finder AppleShowAllFiles TRUE
    hiddenfiles
  • Relaunch Finder in 4 different ways
    Simple way relaunch via terminal killall Finder
  • return to top

Dock

  • Change to 2D Dock. To change back to 3D, repeat with NO at the end.
    defaults write com.apple.dock no-glass -boolean YES
    2d_dock
  • Allows you to increase the size of the Dock past the maximum allowed by the slider in System Preferences. Don’t go larger than 256. Use the slider in System Preferences to shrink the Dock down again.
    defaults write com.apple.dock tilesize -int 256
  • Allows you to increase the Dock magnification past the maximum allowed by the slider in System Preferences. Don’t go larger than 512. Use the slider in System Preferences to shrink the Dock down again.
    defaults write com.apple.dock largesize -int 512
  • Makes all items in the Dock spring loaded. For example, hold a file over an application and it will open or come to the front so you can drop the file onto a specific window. Repeat with NO to reverse.
    defaults write com.apple.dock enable-spring-load-actions-on-all-items -boolean YES
  • Quckly switch to next wallpaper picture in shuffle mode.
    killall Dock
  • return to top

Spaces

  • Changes the delay when dragging windows off the edge of the screen to other spaces. Default value is 0.75.
    defaults write com.apple.dock workspaces-edge-delay -float 0.5
  • Disables the wrap-around when using Control-Arrow keys to changes Spaces. To enable again, repeat with YES at the end.
    defaults write com.apple.dock workspaces-wrap-arrows -boolean NO
    spaces
  • return to top

Desktop

  • Increase Desktop Icon Size.
    If you want massive icons on you desktop this little hack lets you increase the icons to 512 pixels x 512 pixels. This is massive, may slow down on older machines. I don’t think it goes larger than 512. 

    defaults write com.apple.finder DesktopViewOptions -dict IconSize -integer 512
    killall Finde
  • Changing the Format Of Screen Shots.
    If you use the screen shot function, you may want to change the format of the images, this is not easily done normally. Where jpg is in the code you can change this to the format your want:
    png | bmp | gif etc… You need to log out and back in again, or restart for the changes to take effect.
    defaults write com.apple.screencapture type jpg
  • Drag A Widget Onto The Desktop.
    widgets_desktopThis command enables widgets to be placed onto the desktop. Drag a widget around and press F12 to drag it onto the desktop. Repeat the process again to drag a widget back onto the dashboard.
    This may need you to log off or restart for it to take effect.
    defaults write com.apple.dashboard devmode YES
  • return to top

Screensaver

  • Require a password on waking from sleep, but not when screensaver is active.
    defaults -currentHost write com.apple.screensaver askForPassword -int 0

Time Machine

timemachine

  • Changes Time Machine’s backup interval. Requires an administrator password. Default value is 3600 (seconds).
    sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 7200
  • Enable Time Machine On Unsupported Drives ( includeed NAS)
    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
  • return to top

Spotlight

  • Disables the Spotlight icon. Type “killall Spotlight” for changes to take effect.
    To re-enable it, type 755 instead of 0.
    sudo chmod 0 /System/Library/CoreServices/Spotlight.app
    killall Spotlight
  • return to top

ISO CD/DVD

  • Create and burn a “universal” CD/DVD
    mkisofs -allow-multidot -allow-leading-dots -d -hide-rr-moved \
    -l -joliet-long -R -T -v \
    -V VOLUME_NAME -o output.iso root-cd-dir/
    hdiutil burn -noverifyburn output.iso
  • Create an ISO image from a CD/DVD
    diskutil unmountDisk /dev/disk2s0
    dd if=/dev/disk2s0 of=cdname.iso bs=32m
  • Mount a disk image from the command line
    hdid diskimage.dmg (or .iso)
  • Eject a CD/DVD
    drutil eject
  • return to top

Remote Desktop

  • Starts the Remote Desktop service (useful if you only have SSH access but want to do something using the GUI on your client Mac). For more options, see:http://support.apple.com/kb/HT2370
    sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent
  • return to top

Network

  • Displays network configuration for the primary Ethernet interface (en0).
    ipconfig getpacket en0
  • Getting current IP address on interface
    ipconfig getifaddr en1
  • This command can be used after acquiring mac’s, ip’s and hostname’s or any of the above from a freshly scanned LAN. User must be root, and remember to change your settings on your network managing software manually instead of ‘auto DHCP’. You can also substitute eth0 for wlan0 etc
    ifconfig eth0 down hw ether (newmacaddresshere) && ifconfig eth0 up && ifconfig eth0 (newipaddresshere) netmask 255.255.255.0 up && /bin/hostname (newhostnamehere)
  • Changes (spoofs) MAC address until next reboot
    ifconfig en0 ether 00:00:00:00:00:00
  • Find MAC address
    ifconfig en0 | grep ether | sed s/://g | sed s/ether//
  • Lists internet ports that are open. Use sudo if you want the ports open by all users, and the flags -n and -P will disable name resolution and port names and give you numbers instead.
    lsof -i -n -P
  • Displaying a Active Network Connections on the Mac OS X
    lsof -i | grep -E "(LISTEN|ESTABLISHED)" | awk '{print $1, $8, $9}'
  • Display the order for DNS resolution. Useful for when you’re creating or debugging your Network settings.
    scutil --dns
  • wget replacement in MacOS X
    echo 'alias wget="curl -O"' >> ~/.bash_profile
  • return to top

System commands

  • Reboots the computer
    sudo reboot
  • Disables the unexpectedly quit dialog that normally appears when an application crashes. Replace “none” with “prompt” to enable again.
    defaults write com.apple.CrashReporter DialogType none
  • Enable Rosetta support
    sudo sysctl -w kern.exec.archhandler.powerpc=/usr/libexec/oah/RosettaNonGrata
    To Re-Enable Rosetta
    sudo sysctl -w kern.exec.archhandler.powerpc=/usr/libexec/oah/translate
  • return to top

Applications and processes

  • Open an application
    open /Applications/iTunes.app/
  • List file size in human-readable units
    ls -lh /dir/or/file
  • Force quits an application or kill a process or processes by name (e.g: the Dock). Pretty useful if you can’t get into Activity Monitor.
    sudo killall -9 appname
  • return to top

Files management

  • Change to the last directory you were in
    cd /var
    cd /etc
    cd - # will take you to /var
  • To go to your home folder
    just type "cd ~" or even better "cd"
  • Create an empty file
    touch /some/thing
  • Get the first 20 lines of a file
    head -n 20 /some/thing
  • Get 20 lines from the end of a file
    tail -n 20 /some/thing
  • Output the contents of a file
    cat /some/thing
  • How to list and sort directories by size
    du -kh | sort -nr | more
  • Find large files. If you want to quickly find out what the largest files(more than 100M) are in a directory, try following command.
    find . -type f -size +100000k |xargs -I% du -sh %

    or list the 40 heaviest files in your home directory
    du -xak ~/ 2> /dev/null | sort -nr | head -n 40