Archive

Articles taggués ‘Apple’

Useful Mac bash terminal shortcuts

16/01/2024 Comments off

Open directory in finder

open .

Pbcopy and pbpaste

grep 'searching for' hugeFile.txt | pbcopy
pbpaste | sed 's/ / /g'

mdfind command is the spotlight search from command line

say "Hello there"

The say command invokes the system text-to-speech capabilities.

cd -

Will restore the previous directory you were in. Very handy if you accidentally type cd and flip to home.

And some usefull aliases

alias ..="cd .." alias ...="cd .. ; cd .."
alias ls="ls -G" # list alias la="ls -Ga" # list all, includes dot files alias ll="ls -Gl" # long list, excludes dot files alias lla="ls -Gla" # long list all, includes dot files
alias stfu="osascript -e 'set volume output muted true'" alias pumpit="osascript -e 'set volume 10'"
alias ips="ifconfig -a | perl -nle'/(d .d .d .d )/ && print $1'" alias myip="dig  short myip.opendns.com @resolver1.opendns.com"

Bash Keyboard Shortcuts

Moving the cursor:

  Ctrl   a   Go to the beginning of the line (Home)
  Ctrl   e   Go to the End of the line (End)
  Hold the Option key option and click on the current line = Jump Backwards

  Ctrl   p   Previous command (Up arrow)
  Ctrl   n   Next command (Down arrow)
  Hold the Option key option and click on a previous line = Jump upwards

  Ctrl   f   Forward one character
  Ctrl   b   Backward one character
   Alt   b   Back (left) one word      or use Option Right-Arrow
   Alt   f   Forward (right) one word  or use Option Left-Arrow

  Ctrl   xx  Toggle between the start of line and current cursor position

Editing:

 Ctrl   L   Clear the Screen, similar to the clear command

  Alt   Del Delete the Word before the cursor.
  Alt   d   Delete the Word after the cursor.
 Ctrl   d   Delete character under the cursor
 Ctrl   h   Delete character before the cursor (backspace)

 Ctrl   w   Cut the Word before the cursor to the clipboard.
 Ctrl   k   Cut the Line after the cursor to the clipboard.
 Ctrl   u   Cut/delete the Line before the cursor position.

  Alt   t   Swap current word with previous
 Ctrl   t   Swap the last two characters before the cursor (typo).
 Esc    t   Swap the last two words before the cursor.

 ctrl   y   Paste the last thing to be cut (yank)
  Alt   u   UPPER capitalize every character from the cursor to the end of the current word.
  Alt   l   Lower the case of every character from the cursor to the end of the current word.
  Alt   c   Capitalize the character under the cursor and move to the end of the word.
  Alt   r   Cancel the changes and put back the line as it was in the history (revert).
 ctrl   _   Undo
 
  TAB       Tab completion for file/directory names

For example, to move to a directory ‘sample1’; Type cd sam ; then press TAB and ENTER.
type just enough characters to uniquely identify the directory you wish to open.

Special keys: Tab, Backspace, Enter, Esc

Text Terminals send characters (bytes), not key strokes.
Special keys such as Tab, Backspace, Enter and Esc are encoded as control characters.
Control characters are not printable, they display in the terminal as ^ and are intended to have an effect on applications.

Ctrl I = Tab
Ctrl J = Newline
Ctrl M = Enter
Ctrl [ = Escape

Many terminals will also send control characters for keys in the digit row:

Ctrl 2 → ^@
Ctrl 3 → ^[ Escape
Ctrl 4 → ^
Ctrl 5 → ^]
Ctrl 6 → ^^
Ctrl 7 → ^_ Undo
Ctrl 8 → ^? Backward-delete-char

Ctrl v tells the terminal to not interpret the following character, so Ctrl v Ctrl-I will display a tab character,
similarly Ctrl v ENTER will display the escape sequence for the Enter key: ^M

History:

  Ctrl   r   Recall the last command including the specified character(s)
             searches the command history as you type.
             Equivalent to : vim ~/.bash_history. 
  Ctrl   p   Previous command in history (i.e. walk back through the command history)
  Ctrl   n   Next command in history (i.e. walk forward through the command history)
   Alt   .   Use the last word of the previous command
  Ctrl   s   Go back to the next most recent command.
            (beware to not execute it from a terminal because this will also launch its XOFF).
  Ctrl   o   Execute the command found via Ctrl r or Ctrl s
  Ctrl   g   Escape from history searching mode

Process control:

 Ctrl   C   Interrupt/Kill whatever you are running (SIGINT)
 Ctrl   l   Clear the screen
 Ctrl   s   Stop output to the screen (for long running verbose commands)
 Ctrl   q   Allow output to the screen (if previously stopped using command above)
 Ctrl   D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
 Ctrl   Z   Send the signal SIGTSTP to the current task, which suspends it.
            To return to it later enter fg 'process name' (foreground).

To use the Alt Key Shortcuts in OS X – Open Terminal Preferences | Settings Tab | Keyboard | Tick « Use option as meta key »

Emacs mode vs Vi Mode

All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.

Set Vi Mode in bash:

$ set -o vi

Set Emacs Mode in bash:

$ set -o emacs

Source: @coderwall and ss64.com

Categories: Système Tags: , , ,

How to resize a VirtualBox 4+ hard disk (.vdi), the easy way [quick tip]

13/01/2024 Comments off

Source: WebUpd8.org

VirtualBox 4.0 got a very cool new feature that allows you to easily resize a hard disk in just a few seconds. Previously, you had to install Gparted to do this and the procedure was quite slow.

In VirtualBox 4.0+ (see how to install VirtualBox 4.0.x in Ubuntu), to resize a VirtualBox hard disk image (.VDI) firstly locate the folder where the .vdi you want to resize is located – this should be under ~/VirtualBox VMs or ~/.VirtualBox/HardDisks. Then open a terminal, navigate to that folder (« cd /FOLDER/PATH ») and run the following command to resize the .VDI:

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB
Where YOUR_HARD_DISK.vdi is the VirtualBox hard disk you want to resize and SIZE_IN_MB is the new virtual hard disk size, in megabytes. For example, the following command will resize the VirtualBox hard disk called « natty.vdi » to 12000 megabytes:
VBoxManage modifyhd natty.vdi --resize 12000
That’s it! The process takes just a few seconds and you should now have a resized VirtualBox hard disk.

 

Monitor Network Connections in Mac OS X for Free with Private Eye

11/01/2024 Comments off

Source: OSXdaily

Private Eye is a free real-time network monitor app for Mac OS X that is extremely easy to use. Upon launching the app, you’ll start to see all open network connections by application and process, and you can then filter connections by app, monitor all open connections, or watch only incoming or outgoing transfer.

private-eye-network-connection-monitor-mac

Connections are reported by application, the time of the connection, and arguably the most useful, the IP address that is being connected to by the app, making it easy to see socket and routing data, letting you know exactly what app is communicating with what server or IP address, for both local and broader internet networks. If you have any interest in networking, privacy, security, or you just want to keep an eye on what apps are connecting to the internet and to where, you should download this app, but it’s also an amazingly useful tool for troubleshooting network problems and figuring out what is using the network.

 

Download and install Private Eye by putting it into your /Applications/ folder, then open PrivateEye to get started. The list of open network connections is easy to read, you’ll see a time stamp of the connection, the application name, and where the connection is going to by IP (or coming from, as determined by the arrow pointing left for in, or right for out).

private-eye-connections

Using the left side menu you can quickly break down connections to see them all, only show incoming transfers, outgoing connections, or display connections by specific application only. Apps are easy to identify in this list, as are daemons running in the background (like PubSubAgent), and command line processes belonging to the user are also visible (ssh, for example).

This is a simple yet powerful tool without the complexity or the learning curves related to compiling and using the command line tools lsof, watch, open_ports, or wireshark, and is therefore highly recommended for anyone who is interested in seeing this kind of information, whether it’s out of general curiosity, or to help troubleshoot and diagnose specific network activities.

Fixing Mac OSX File Permissions and ACLs From the Command Line

09/01/2024 Comments off

Recently the hard drive in my mac mini running Mac OSX Leopard (10.5) failed. Luckily I had time machine backing it up to an external USB disk. Now, since I had to replace the drive and rebuild my system anyway I figured, why not upgrade to Snow Leopard? Planning to just pull what I needed off the backup drive manually I went ahead with the upgrade. There aren’t too many files on this machine that I depend on. Just some ssh keys, gpg keys and random documents scattered about here and there. So I upgraded, installed my apps and copied my files from the backup. Everything was going smoothly until I tried to actually write to one of the files I copied from the backup drive. This is when I started getting permission errors.

Here’s what happened when I tried to update my ssh known_hosts file:

airbag:~ keith$ echo foo > .ssh/known_hosts 
-bash: .ssh/known_hosts: Permission denied

Huh? But I own this file…dont I?

airbag:~ keith$ id
uid=501(keith) gid=20(staff) groups=20(staff),402(com.apple.sharepoint.group.1),204(_developer),100(_lpoperator),98(_lpadmin),81(_appserveradm),80(admin),79(_appserverusr),61(localaccounts),12(everyone),401(com.apple.access_screensharing)

airbag:~ keith$ ls -al .ssh/known_hosts 
-rw-r--r--@ 1 keith 502 56140 Mar 25 2009 .ssh/known_hosts
I do own it… And so began much head scratching and man page reading.

Well, as it turns out I forgot to look at the file ACLs…

airbag:~ keith$ ls -le .ssh/known_hosts 
-rw-r--r--@ 1 keith 502 56140 Mar 25 2009 .ssh/known_hosts
 0: group:everyone deny write,delete,append,writeattr,writeextattr,chown

Well no wonder, the ACL is set to deny write,delete,append,writeattr,writeextattr and chown from everyone! Let’s get rid of that.

airbag:~ keith$ sudo chmod -N .ssh/known_hosts 
Password:

That ought to do it. The -N flag says get rid of all the ACL info on the file. You could also update this to be just right for your user or group but I’d rather use only the standard unix permissions.

airbag:~ keith$ ls -le .ssh/known_hosts 
-rw-r--r--@ 1 keith 502 56140 Mar 25 2009 .ssh/known_hosts

Seems to have removed all ACLs from the file. I wonder if we can write to it now…

airbag:~ keith$ echo foo >> .ssh/known_hosts 
airbag:~ keith$

And there you have it, the file is writable once again. Now its time to get some real work done!

Categories: Système Tags: , , , ,

Change & Set the Default crontab Editor

08/01/2024 Comments off


Most hardcore command line users and unix geeks love vi, but I prefer nano. If you want to change your default crontab editor to nano, here’s how to do this:

For a one time edit, launch the terminal and type:

EDITOR=nano crontab -e

If you want to set nano as your default editor in general, you use this command:

export EDITOR=nano

Now when you go to edit crontab, nano will be the default editor than vi. You can test this by typing:

crontab -e

Looking beyond Mac OS X, this should work in Linux as well.

Categories: Système Tags: , , , ,