Some Simple OS X Command Line Tools for Everyone
by BoxOfSugar in Circuits > Apple
748 Views, 17 Favorites, 0 Comments
Some Simple OS X Command Line Tools for Everyone
Some Simple OS X Command Line Tools For Everyone
These were gathered from around the internet and from my personal knowledge. Many are simple tools that one can read about in the MAN pages, a couple are shell items that you can create on the fly. Enjoy.
This first one is a simple tree structure directory listing. First go to the command line on your mac by opening the terminal app.
at the prompt cd to home if you are not there.
$ cd ~
Next lets edit your .profile which is basically your shell control panel. We are going to create an alias.
$ vi .profile
This will put you into the editor you ‘i’ to start inserting. Most of you will have a blank file, some of you might already have items in here.
In your file put the following.
alias dirtree="ls -R |grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e ’s/-/|/'"
Hit escape, hit wq at the : to write.
Now lets source the .profile to read in the alias.
$ source .profile
Now you can type the command and see the tree output.
$ dirtree
|---------------colorpicker
|-------------js
|---------------shortcode-generator
|-----------------js
|-----------------shortcodes
|-----------images
|-----------includes
|-------------js
|-----------lang
|-----------psd
|—————styles
It gives you an easier to read directory structure.
This next one I use quite frequently, it allows one to copy information to and from your clipboard. These are simple command line tools and you can MAN page them for more information.
<——>
PBCOPY & PBPASTE
$ ls -al | pbcopy
Will copy the directory listing to the clipboard.
$ pbpaste >> filename.txt
Will now paste the directory listing from the clipboard to a filename.txt file.
<—->
DISKUTIL
Most of you know you can access diskt utility form the applications area, but did you know you can perform the same functions from the command line.
$ diskutil
Will show you the full list of options and of course read the MAN pages before you go messing with your disks.
A quick example I found is over at http://www.ernieflores.net
Deleting and merging a partition with diskutil from the command line
Launch the Terminal and type the following into the command line:
$ diskutil list
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *120.0 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Lion 119.2 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
Look for the identifier for the partition you do not want. We are going to use disk0s3.
To remove that partition type.
$ diskutil eraseVolume HFS+ Blank /dev/disk0s3
The partition will be erased.
$ diskutil mergePartitions HFS+ Lion disk0s2 disk0s3
This will merge the two partitions.
<——>
This next two are fun to play with but not much more.
BANNER
This will print a ascii text banner of whatever input one gives it.
$ banner -w 30 joe
#
###
################### ##
################## ###
####
#########
## ##
# #
# ##
## ##
#########
####
####
#########
## # ##
# # #
# # ##
# # ###
# #####
You can also pipe this to the printer.
$ banner -w 20 JERRY > jerry | lp -d "_132_235_132_250" jerry
This will send banner the word jerry at 20 width, put it into a file, then print the file.
You can get a list of printers with
$ lpstat -a
and
$ lp -d “printername” file
prints from the command line.
<——>
SAY
Say will make your computer say some text string. It is great for playing with and having fun with your friends.
$ say hi
Will make your Mac say the word “Hi”.
<——>
The last one is very powerful and allows you to do many things on your Mac from the command line.
SYSTEMSETUP
$ sudo systemsetup
will get you there. Some of the options you can try are
Usage: systemsetup -setrestartfreeze
Set restart on freeze to either or .
Usage: systemsetup -getallowpowerbuttontosleepcomputer
Display whether the power button is able to sleep the computer.
Usage: systemsetup -setallowpowerbuttontosleepcomputer
Enable or disable whether the power button can sleep the computer.
Usage: systemsetup -getremotelogin
Display whether remote login is on or off.
Type -help in systemsetup to see all of your options. Sometimes this is a quick way to set something when you are a heavy command line worker.
<——>
These are just a few of the tools you can use, there are 1000’s more but I wanted to show you a few that I use to get things done.
Enjoy
Joe Murphy
AKA Grehyton