Posts Tagged “terminal”
Posted by: fidel in How to, Terminal, mac, tags: .bashrc, .bash_history, /bin/bash, 10.5, bash, cli, color, colors, terminal, terminal alias, terminal color
If you do use Terminal.app more then once a week it makes sense to customize your Terminal to your needs.
Personaly i prefer bash so the next steps are focused on the bash shell.
1. Creating a .bashrc:
- Open Terminal.app
- Open Terminal Preference Dialog
- Navigate to the Startup section
- Make sure you have selected “command (complete path)” under “Shell open with” section. The Full path should be “/bin/bash” in our example
- Close the Preference dialog
- Navigate to your users home folder if you aren’t there already. This is usualy done with: “cd ~”
- Enter: “touch .bashrc” to create a new empty file called .bashrc
Now we have done the first steps. We are sure we do use bash and we have an empty .bashrc ….so no function till now
2. Creating a .bash_profile:
Now we have to create a .bash_profile in our Users home directory too.
- Open Terminal.app (be sure that you are in your users home directory)
- Enter the following to create a bash profile: touch .bash_profile
- Open the new bash profile. Enter: vi .bash_profile
- Fill the new bash profile with the following:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
3. Forcing Terminal.app to load our bashrc at start:
Now we have to make sure Terminal.app uses our new .bashrc while starting.
- Open Terminal.app
- Open Terminal Preference Dialog
- Navigate to the Startup section
- Change “/bin/bash” to “/bin/bash –rcfile /Users/yourusername/.bashrc“

On the next start of Terminal.app it should use our empty .bashrc file. So now lets fill it a bit
4. Define an example alias:
- Open Terminal.app
- Open your .bashrc with a texteditor (ie: vi .bashrc)
- Insert the following example alias to check if our .bashrc works: alias ls=”ls -la”
- Save and close the file
- Restart Terminal.app
After relauching Terminal.app the “ls” command should output the same in terminal then “ls -la” does
5. Tweak the history of your shell:
I love my bash history, but why not tweaking its default behaviour ?
- Open Terminal.app
- Open your .bashrc with a texteditor (ie: vi .bashrc)
- Enter the following lines to your .bashrc:
# history handling
#
# Erase duplicates
export HISTCONTROL=erasedups
# resize history size
export HISTSIZE=5000
# append to bash_history if Terminal.app quits
shopt -s histappend
After restarting your Terminal your history should we teaked as follows.
- The first command deletes duplicate-commands out of your .bash_history file which contains your bash history.
- The second command defined the size of your history
- The third line appends the history to your .bash_history to make sure you have all sessions saved.
Well that was the basic first step. You could now continue adding colors to your .bashrc, configuring how the prompt will look like and many other nice things.
Here my final example .bashrc
# Define how Bash prompt looks like:
#
# User @ Host - working dir
#export PS1=”\u@\h\w$ ”
export PS1=”\u@\h\w: ”
# Cli Colors
export CLICOLOR=1
# use yellow for dir’s
export LSCOLORS=dxfxcxdxbxegedabagacad
# Alias
#
#
alias ls=’ls -la’
# history handling
#
# Erase duplicates
export HISTCONTROL=erasedups
# resize history size
export HISTSIZE=10000
# append to bash_history if Terminal.app quits
shopt -s histappend
6 Comments »
I have to cleanup my mails so here the link to the Apple Command-line backup documentation
Quote:
Backing up your hard drive is like going to the dentist: important, but unpleasant enough that it is easy to put off or forget. Because of that, the best way to keep your data safe is to schedule regular backups. While there are numerous commercial applications that address this need (including Apple’s .mac Backup), they tend to either require the user to be logged in, or be connected to an enterprise data center.
The traditional UNIX alternative is to run a command-line backup tool as part of a ‘cron’ script, but many system administrators are unaware of the variety of options available for unattended backups under Mac OS X.
This article discusses some of the issues faced in making backups, the special considerations of Mac OS X systems, a number of options which allow the creation of viable backups, and a few potential pitfalls of developing a backup system. This article does not cover BSD flags, or systems prior to Mac OS v10.4 Tiger. And for simplicity, this article assumes that you have not turned on ACLs (using Mac OS X Server or fsaclctl) on the filesystem you are wanting to back up. There are some subtleties in how these tools interact with ACLs that are beyond the scope of this article. Please consult the latest documentation for each tool for more details.
Links:
No Comments »
Posted by: fidel in Terminal, mac, tags: built-in voice, cli, developer.apple, osascript, say, speech, system preferences, terminal, text to speech
I really like the say command on my Mac’s. Great fun letting another mac in your building say something while someone else is using it.
I stumbled upon some nice tricks regarding the say command.
Examples:
ie you could play a simple melody like that:
say -v Good oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooooooooooooooooooooo
Where “-v Good” defines the voice. You could use “-v Bad” too, or any other system voice. if you dont define a voice yourself, say will use the default voice defined in System Preferences
Check the apple link at the end of this post for more details on the say command.
You could try something more creative like that:
osascript -e ’say “Dum dum dee dum dum dum dum dee Dum dum dee dum dum dum dum dee dum dee dum dum dum de dum dum dum dee dum dee dum dum dee dummmmmmmmmmmmmmmmm” using “Pipe Organ”‘
Best snippet i found so far:
osascript -e ’say “oh This is a silly song silly song silly song this is the silliest song ive ever ever heard So why keep you listening listening listening while you are supposed to work to work to work to work its because i hate my job hate my job hate my job its because i hate my job more than anything else No its because youve no life youve no life youve no life and you better go get one after forwarding this crap” using “cellos”‘
Great =)
Links:
1 Comment »
Posted by: fidel in Terminal, _english, mac, tags: apple.inc, cli, macosxhints.com, restart, services, start, stop, systemstarter, terminal
I stumbled upon SystemStarter while searching a way how to restart a service in Mac OS X.
Quote from the man page:
The SystemStarter utility may be used to start, stop, and restart the system services which are described in the /Library/StartupItems/ and /System/Library/StartupItems/ paths
Example:
- Restart NetInfo: sudo SystemStarter restart NetInfo
- Restart Printing / CUPS: sudo SystemStarter restart PrintingServices
I guess the missing part now is a full listing of the Services…lets see if i can find the time to collect them later.
Links:
No Comments »
Description:
iSSH is a front-end application to the command line application â œsshâ . It provides a quick and easy way to start an SSH connection to a remote computer. You may be asking, â œWhatâ s the point of running SSH without an interactive command prompt (Terminal)?â Well, running SSH in the background will not supply a prompt, but, it will forward ports. This is the main purpose of iSSH. You can set two options with iSSH; which ports to forward to the remote computer, or, to start an SSH SOCKS proxy. The first could be used to forward a VNC connection over SSH and the latter could be used to bypass your workâ s website filters! Either way, it provides a simple way to start an SSH connection for those who are afraid of the Terminal or just donâ t need it.
Links:
No Comments »
Posted by: fidel in Security, Terminal, mac, tags: 10.5, apple inc., Avoiding Multiple Simultaneous Account Access, Ensuring Data Integrity with Backups, experienced users, Information Assurance with Applications, Information Assurance with Services, Installing Mac OS X, Protecting System Hardware, Securing Accounts, Securing Data and Using Encryption, Securing Global System Settings, Securing System Preferences, Securing System Swap and Hibernation Storage, security, Security Architecture, security guide, terminal
Apple has released a Mac OS X Leopard Security Guide with about 250 pages. The targetgroup are experienced Mac OS Users so if you have never worked with Terminal / ClI it might be not your thing.
Overview:
Chapter 1, â œIntroduction to Mac OS X Security Architecture,â explains the infrastructure of Mac OS X. It also discusses the layers of security in Mac OS X.
Chapter 2, â œInstalling Mac OS X,â describes how to securely install Mac OS X. The chapter also discusses how to securely install software updates and explains permissions and how to repair them.
Chapter 3, â œProtecting System Hardware,â explains how to physically protect your hardware from attacks. This chapter also tells you how to secure settings that affect users of the computer.
Chapter 4, â œSecuring Global System Settings,â describes how to secure global system settings such as firmware and Mac OS X startup. There is also information on setting up system logs to monitor system activity.
Chapter 5, â œSecuring Accounts,â describes the types of user accounts and how to securely configure an account. This includes securing the system administrator account, using Open Directory, and using strong authentication.
Chapter 6, â œSecuring System Preferences,â describes recommended settings to secure Mac OS X system preferences.
Chapter 7, â œSecuring Data and Using Encryption,â describes how to encrypt data and how to use Secure Erase to verify that old data is completely removed.
Chapter 8, â œSecuring System Swap and Hibernation Storage,â describes how to secure your system swap and hibernation space of sensitive information.
Chapter 9, â œAvoiding Multiple Simultaneous Account Access,â describes how to avoid fast user switching and local account access to the computer.
Chapter 10, â œEnsuring Data Integrity with Backups,â describes the Time Machine architecture and how to securely backup and restore your computer and data.
Chapter 11, â œInformation Assurance with Applications,â describes how to protect your data while using Apple applications.
Chapter 12, â œInformation Assurance with Services,â describes how to secure your computer services. It also describes how to protect the computer by securely configuring services.
Links:
No Comments »
Posted by: fidel in Terminal, mac, tags: 10.4, 10.5, acl, gui, ls, macupdate.com, permissions, sandbox, terminal, wiki
About Sandbox:
What does Sandbox have to offer you?
- An organized, full-featured GUI for editing Mac OS X’s access control lists.
- A software update system so you never have to come back to this page to check for updates (but you’re welcome to anyway).
- A simple, easy-to-use panel for enabling and disabling ACL functionality
Version 2.1 is not 10.5 compatible so you have to use the latest beta on Leopard.
Well that’s it basically … Sandbox looks great if you are forced to work with ACL’s in Mac OS X but still prefer a real graphical user interface (GUI).
Oh one last thing…. if you are new to this topic and you want to see ACL’s in Terminal.app use ls -le insteed of the usual ls -l
Links:
No Comments »
Besides netstat which is not that helpful if you need to know the appname you can use lsof
As root enter the following in Terminal:
lsof -i
An example output could look like this:
COMMANDÂ Â PIDÂ USERÂ Â FDÂ Â TYPEÂ Â Â DEVICE SIZE/OFF NODE NAME
firefox-b 488 fidel  85u IPv4 0×6dcaa68     0t0 TCP 192.168.x.y:RandomPort->www.youtube.com:http (ESTABLISHED)
Cog      494 fidel   4u IPv4 0×688066c     0t0 TCP 192.168.x.y:RandomPort->apache2-grog.miata.dreamhost.com:http (CLOSE_WAIT)
No Comments »
for sure its quite easy to get the Mac OS X Version string using the “About this Mac”-dialog. but what if you need to get the same result from command-line ?
Lets take a quick look:
- Open terminal.app ( in /Applications/Utilities )
- Enter: /usr/bin/sw_vers
This should end up in a similar output to my one:
MacPro:~ fidel$ /usr/bin/sw_vers
ProductName:Â Â Â Mac OS X
ProductVersion:Â Â Â 10.5.2
BuildVersion:Â Â Â 9C7010
MacPro:~ fidel$
No Comments »
This is a raw copy from macosxhints.com:
Assume you want to do some work on a remote Mac via 10.5’s Screen Sharing, but you forgot to enable Screen Sharing before you left the remote Mac. You’re now a good distance away, and apparently stuck. Fortunately, because the screen sharing system uses launchd to monitor its state, enabling and disabling is as simple as adding a file in the remote Mac’s /Libary/Preferences folder. (Note that you’ll need to be able to login to the remote Mac via ssh to run these commands on that Mac.)
$ cd /Library/Preferences
$ echo -n enabled > com.apple.ScreenSharing.launchd
To disable screen sharing:
$ cd /Library/Preferences
$ rm com.apple.ScreenSharing.launchd
If you have a Finder window open with the remote Mac selected in the Shared section, you’ll even note the icon for Screen Sharing coming and going as you do this.
No Comments »
|