Mac Workshop 2007: Activity Monitor, Console and Terminal

Terminal:

For now, read this piece in the Articles section:
You, the Terminal, and Your Mac

Terminal

And here is my personal list of useful commands:

BASH Commands

cp -R /Users/francine/Pictures/486 /Volumes/Files/Winter05 copy the folder "486" and all the files in it to the folder "Winter05"--this used to strip the resource forks off all the files, but has been "Macified" with Tiger so resource forks are now preserved

CpMac -r /Users/francine/Desktop/test /Users/francine/Desktop/norf copy the folder "test" and files into folder "norf" preserving the resource forks of the files

find / -name somefile.xyz starting at root, search eveywhere for the file name

find -x / -name somefile.xyz search the startup volume only for the named file

find . -type f | wc -l get a count of the number of files in that directory, including its sub-folders

find /Users/francine/Documents | wc -l Return a number of all folders AND files in the folder given

find /Users/francine/Ttest -name *.png -exec cp '{}' /Users/francine/Desktop/screens/ \; finds all files with the extension ".png" in the folder Ttest and its sub-folders and copies them to the folder "screens"

find . -name .DS_Store -exec rm '{}' \; finds all files in the current directory and its sub-directories named ".DS_Store" and removes them

open /Users/francine/Library/Logs/CrashReporter/Disk\ Copy.crash.log open file in default application

open /Users/Library/Preferences/.GlobalPreferences.plist open the hidden file in default app

open -a Preview ~/Pictures/revelator.psd open the file in the home pictures folder with the application specified

open -e /Users/francine/Desktop/joshuatree/joshua.htm open the file using TextEdit

clear erase contents of term window so that prompt appears at top of window

top list running processes

dmesg display the startup info

/sw/bin/identify /Users/francine/Desktop/DSCN2204.JPG returns type and size of graphic file

alias jps='/sw/bin/identify' creates a temporary command abbreviation in the shell

jps /Users/francine/Desktop/DSCN2204.JPG running the command using the alias

touch .bash_profile creates a text file for bash shell which (will contain PATH list, among other things)

echo $PATH shows the command path for the shell, to add more, edit .bash_profile or use export command

set PATH=<the desired PATH value> set the PATH value for the shell

export PATH=/some/place/commandfolder/:$PATH write specified path to profile

set PATH=/bin:/sbin:/usr/bin:/usr/sbin:/sw/bin/ my PATH values

history displays a list of previous commands, numbered; to reuse type: !xyz (where xyz is the number you want to reuse)

apropos zgrep returns information about the command

defaults write com.apple.Safari IncludeDebugMenu 1 enable the Safari Debug Menu

defaults write com.apple.screencapture location /Users/francine/Desktop/screens changes the default location of screenshots

Files

joinPDF about.pdf Backup.pdf iDiskUtility.pdf makes one pdf file from two or more files, give name of new file, names of ones to join, thus must have a minimum of three file options

man -t last | pstopdf -i -o last.pdf Makes a pdf file of the man page for the "last" command

grep -i -L DOCTYPE $file 2> /dev/null `find . -name \*\.html` search current directory for htmll files that do NOT contain the string "DOCTYPE"

grep -i nctimes $file 2> /dev/null `find . -name \*\.html` find an html file in the current directory that contains "nctimes"

grep 'One For' * list the files in the current directory that contains the string "One For"

cat /path/to/some/textbased/file.doc shows the plain text version of any text based file, with the formatting showing as ASCII

tar -cvf jpg.tar jpegs create a tar file from the folder "jpegs"--must be in the directory containing the folder

tar --dereference -cvf ./jepgs.tar ./jpegs creates a tar file containing the original files of the aliases in a folder (files now have zero size???)

tar -tf jpg.tar view the content of the archive "jpg.tar"

tar -xvf jpg.tar extract a folder with original name from the archive

GetFileInfo /Users/francine/Desktop/test/pigskul.psd Returns the following information about the file:
type: "8BPS"
creator: "8BIM"
attributes: avbstclInmed
created: 02/05/2040 22:28:16
modified: 11/26/1998 14:06:29

file /Users/francine/Desktop/test/pigskul Returns information about the file type, even for files without extensions:
/Users/francine/Desktop/test/pigskul: Adobe Photoshop Image

SetFile -a V /Users/francine/Desktop/visi set the visibility/invisible attribute for an item

SetFile -a v /Users/francine/Desktop/visi makes visible: see attribute list by using SetFile, hit return. Upper case is on or true, lower case is off
A Alias file
B Bundle
C Custom icon*
D Desktop*
E Hidden extension*
I Inited*
M Shared (can run multiple times)
N No INIT resources
L Locked
S System (name locked)
T Stationary
V Invisible*
Note: Items marked with an asterisk (*) are allowed with folders

fstat / identifies all open files

df -k Shows the disks with their partition number and the amount of data stored in that partition
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/disk1s10 30022360 18096104 11670256 61% /
devfs 105 105 0 100% /dev
fdesc 1 1 0 100% /dev
<volfs> 512 512 0 100% /.vol
/dev/disk0s5 60046560 33818280 26228280 56% /Volumes/OXey
/dev/disk1s9 30023280 14040792 15982488 47% /Volumes/Files
automount -nsl [302] 0 0 0 100% /Network
automount -fstab [317] 0 0 0 100% /automount/Servers
automount -static [317] 0 0 0 100% /automount/static
/dev/disk2s9 62909676 34342400 28567276 55% /Volumes/PantherBU
/dev/disk2s10 62914560 36896880 26017680 59% /Volumes/OXibup
/dev/disk2s11 57666856 32463308 25203548 56% /Volumes/FilesBU
/dev/disk2s12 15645600 3873112 11772488 25% /Volumes/TMac

df -H Show the above information in G, M and K
Filesystem Size Used Avail Capacity Mounted on
/dev/disk1s10 31G 19G 11G 62% /
devfs 108K 108K 0B 100% /dev
fdesc 1.0K 1.0K 0B 100% /dev
<volfs> 524K 524K 0B 100% /.vol
/dev/disk0s5 61G 35G 26G 57% /Volumes/OXey
/dev/disk1s9 31G 15G 16G 49% /Volumes/Files
automount -nsl [303] 0B 0B 0B 100% /Network
automount -fstab [309] 0B 0B 0B 100% /automount/Servers
automount -static [309] 0B 0B 0B 100% /automount/static
/dev/disk2s9 64G 41G 24G 63% /Volumes/PantherBU
/dev/disk2s10 64G 38G 27G 59% /Volumes/OXibup
/dev/disk2s11 59G 33G 26G 56% /Volumes/FilesBU
/dev/disk2s12 16G 7.0G 9.0G 44% /Volumes/TMac

Directories

cd /Downloads/installers/updaters change your directory location

ls -al /Volumes/PMiPod/iPod_Control/Music/F00 a location of the iPod’s actual music files

ls -ald ~/Desktop/test show the info of the directory "test"
drwxr-xr-x 16 francine francine 544 7 Apr 13:45 /Users/francine/Desktop/test

cd ~/Desktop
chmod u+t test move to Desktop, then change the "sticky bit" of the directory "test" in that location so that only the owner of the file/directory can remove files
ls -ald ~/Desktop/test show the info of the directory "test"
drwxr-xr-x 16 francine francine 544 7 Apr 13:45 /Users/francine/Desktop/test

sudo Activities: super user do

sudo -s Change to root, give admin password, prompt changes to: ~ root#

sudo !! Repeat the previous command as sudo

sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder have the Finder run as root; must first quit Finder in Activity monitor (more graceful than a kill command)

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit run the application TextEdit as root

sudo /usr/libexec/locate.updatedb manually update the locate database
locate maine use the locate command to find a file containing the specified string in its name or path

sudo periodic daily run the series of cron tasks specified, using the /etc/periodic directory
sudo periodic weekly
sudo periodic monthly
sudo periodic daily weekly monthly run all of them in one fell swoop

sudo find -x / -mindepth 18 find all files with a path of 18 steps, in other words, locate lengthy nested folder systems, eg, /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CommonPanels.framework/
Versions/A/Resources/NSLPlugins/NSLUI.bundle/Contents/Resources/English.lproj/windows.nib/objects.xib

sudo du -cxd 1 / | less | sort -n returns a list of items at the root level, sorted by their block size, and ignoring mount points, with a grand total. Adding an "h" option returns the size in kbs, mbs, and gbs, but sort ignores that and just gives a numerical sort, eg 10GBs, 12KBs, 15MBs.

sudo du -cxhd 1 /
8.0K /.Metadata
0B /.OSInstall-temp
4.0K /.Trashes
0B /.vol
7.4M /AppAlias
3.8G /Applications
1.0K /automount
3.4M /bin
0B /Cleanup At Startup
0B /cores
8.0K /Desktop Folder
0B /dev
844M /Developer
50M /Documents
2.3G /Downloads
3.0G /Library
512B /Network
109M /private
2.1M /sbin
668M /sw
1.0G /System
373M /System Folder
0B /Temporary Items
0B /TheFindByContentFolder
8.0K /TheVolumeSettingsFolder
0B /Trash
4.9G /Users
658M /usr
4.0K /Volumes
18G /
18G total

diskutil repairPermissions / Run Repair Permissions from the command line, either Terminal or single user mode

/sbin/fsck -yf Run file system consistency check on an unmounted disk from the command line in single user mode


Return to MacWorkshop Calendar

Return to INDEX