40 terminal tips and tricks you never thought you needed - tuts+ computer skills tutorial

36
Categories Series Apps !! Computer Skills TERMINAL 40 Terminal Tips and Tricks You Never Thought You Needed by Jordan Merrick 21 Jun 2013 43 Comments " # + % The Terminal is an exceptionally powerful tool, providing a command line interface to the underpinnings of OS X. It’s a topic we’ve covered at length before with our popular series Taming the Terminal. There’s a great deal that Terminal can do, from moving large numbers of files to changing preferences that we didn’t even know exist. To demonstrate just how versatile the Terminal is, I’ve rounded up 40 truly excellent Terminal tips and tricks that can come in very handy. Before We Begin All of the Terminal commands I’ll be showing you are perfectly safe to use and, when it comes to changing preferences, are completely reversible. Saying that, the Terminal is a fickle creature and leaves no margin for error so make sure you’re entering the commands exactly as they are written here. As always, make sure you have a recent backup in case something does happen. Tip: If you’re unfamiliar with Terminal, I would strongly encourage you to read our introductory series on the topic, Taming the Terminal. Terminal isn’t for the faint of heart and we’d rather you be comfortable entering some of these commands. Entering Terminal 62 43 61 &

Upload: harmanjit-singh

Post on 20-Jul-2016

17 views

Category:

Documents


2 download

DESCRIPTION

Terminal tricks

TRANSCRIPT

Categories Series Apps

!! Computer Skills

TERMINAL

40 Terminal Tips and Tricks You NeverThought You Neededby Jordan Merrick 21 Jun 2013 43 Comments

" # + %

The Terminal is an exceptionally powerful tool, providing a command line interface to theunderpinnings of OS X. It’s a topic we’ve covered at length before with our popular seriesTaming the Terminal.

There’s a great deal that Terminal can do, from moving large numbers of files to changingpreferences that we didn’t even know exist. To demonstrate just how versatile the Terminal is,I’ve rounded up 40 truly excellent Terminal tips and tricks that can come in very handy.

Before We Begin

All of the Terminal commands I’ll be showing you are perfectly safe to use and, when it comesto changing preferences, are completely reversible. Saying that, the Terminal is a ficklecreature and leaves no margin for error so make sure you’re entering the commands exactly asthey are written here.

As always, make sure you have a recent backup in case something does happen.

Tip: If you’re unfamiliar with Terminal, I would strongly encourage you to read our introductoryseries on the topic, Taming the Terminal. Terminal isn’t for the faint of heart and we’d rather yoube comfortable entering some of these commands.

Entering Terminal

62 43 61

&

The Terminal window

Terminal is located in the Applications > Utilities folder. Once opened, you can then startentering commands.

Within Terminal, you’ll see something like this:

This is the prompt, where we enter our commands. To correctly identify how to enter acommand, I will be using a dollar sign ($) to signify the prompt, so simply enter the commandthat follows a dollar sign.

Let’s warm up with some basic commands!

Clear the Window

Simply put, this clears the current window. (Within Terminal in OS X, you can still scroll up to

1 MacBook:~ jordan$

1 $ clear

see what was there. This command simply clears the current view).

Navigating to Folders

You can navigate to a folder, such as Utilities, by typing the following command:

If you want to quickly jump back to your home folder, you can simply enter:

With folders that contain spaces, there’s two ways you can do it:

The first method uses the \ back slash to “escape” the space. Since the command line treatsspaces as part of commands, the \ character tells Terminal to ignore the space thatimmediately follows. Alternatively, you can simply wrap the folder’s path in quotation marksand any spaces it contains will be ignored.

Navigate back to your home folder before continuing.

List the Contents of a Directory

You can view the contents of a folder by entering:

1 $ cd /Applications/Utilities

1 $ cd

12

$ cd /Volumes/Macintosh\ HD/$ cd "/Volumes/Macintosh HD/"

1 $ ls

The default output of 'ls'

To view it in a list format, enter:

1 $ ls -l

The output of 'ls' with the '-l' flag

If you want to view all files, including hidden ones:

The above command will display all files, including those hidden ones that start with a period.What if we want to view the folder as a list but also view all the hidden files?

Yep, it’s as simple as combining them together! I think you’re suitably warmed up, so let’s kickit up a notch!

Navigate back to your home folder before continuing.

Ditto

A hidden gem in OS X is Apple’s ditto command. I’ve found this incredibly useful in copyinglarge amounts of data as it can run within a Terminal window that contains more useful

1 $ ls -a

1 $ ls -la

information about its progress than the more traditional Finder copy window.

The above command will copy our “work” folder to a new location. Actually, what happens isthe command copies the contents of our “work” folder to a new “work” folder.

Adding -V, meaning verbose prints a line to the Terminal window for every file that’s beingcopied. It’s extremely useful as you can see exactly what file is being copied at any time.

Ditto is a command I use frequently and have often copied many gigabytes of data betweenhard drives using it because it seems to be so reliable.

Disable Screenshot Drop Shadows

If we ever take a screenshot of a window in OS X, by default it will always show a dropshadow, adding wasted pixels. If you’d prefer to have your screenshots drop shadow-free, youcan use the following command:

You can either restart your Mac to see the changes or, using another command, see theminstantly:

This command stops the graphical front-end to OS X for a split second. Don’t worry, it has torun all the time so as soon as it is stopped, it restarts instantly - but updated with our newoption. Take a screenshot and you’ll now notice that the shadow is no longer included.

To reverse the changes, you can enter the following command:

1 $ ditto -V /old/work/ /new/work/

1 $ defaults write com.apple.screencapture disable-shadow -bool TRUE

1 $ killall SystemUIServer

1 $ defaults write com.apple.screencapture disable-shadow -bool FALSE

1 $ killall SystemUIServer

To see the changes immediately.

Change Screenshot File Format

PNG is probably the best format to use for screenshots, but it can certainly take up a bit ofspace. If you’d prefer to use PDF format, you can use the following:

To revert the changes, enter the following:

Change Screenshot Location

Whilst taking screenshots is great, it can quickly clutter up the Desktop. To change this, wecan use:

Rather then deal with pesky long path names, you can just type the first part of the commandand, after the word “location”, drag a folder you’d like your screenshots to save to. To undothe changes, you can use:

1 $ defaults write com.apple.screencapture type PDF

1 $ killall SystemUIServer

1 $ defaults write com.apple.screencapture type png

1 $ killall SystemUIServer

1 $ defaults write com.apple.screencapture location /drag/location/here

1 $ killall SystemUIServer

1 $ defaults write com.apple.screencapture location ~/Desktop

1 $ killall SystemUIServer

Tip: The squiggle, ~, actually represents your home folder. In the example above, this wouldactually mean /Users/jordan/Desktop. A useful timesaver!

Enable AirDrop on Older Macs

AirDrop is a great feature to send files between Macs quickly and easily without dealing withpesky file sharing apps. Trouble is, it’s only on WiFi and on more recent Macs.

If your Mac doesn’t currently support AirDrop, you can enter the following command to use it,as well as to use it over ethernet:

You’ll need to restart the Finder, the quickest way is to use the killall command which willrestart it:

To revert the changes, enter:

If you'd like more information on enabling AirDrop, we've covered it in more detail in ourprevious tutorial "How to Enable AirDrop on Ethernet Connected and Unsupported Macs".

Show Hidden Files and Folders

To view hidden files and folders in OS X:

Once the Finder restarts, you’ll see a lot of files you never saw before, usually starting with a

1 $ defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool TRUE

1 $ killall Finder

1 $ defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool FALSE

1 $ defaults write com.apple.finder AppleShowAllFiles -bool TRUE

1 $ killall Finder

period (which denotes a hidden file in OS X).

To revert the changes:

We've also covered hidden file visibility in our previous tutorial "Revealing Hidden Files in OSX".

Stress Test Your Mac

If you’re wanting to run some stress tests on your Mac, there’s a simple command we canenter that will instantly utilise 100% of your CPU:

Apple technicians use this frequently when dealing with troublesome Macs that might becrashing under load and it’s a very quick way of stressing a Mac. To cancel the command,press Ctrl-C.

View File System Usage

Sometimes we want to see what our Mac is doing when it comes to reading and writing todisk, especially if we’re trying to identify something that’s preventing us from ejecting a drive.To do this, we use:

By entering sudo, we are requesting to run this as a super user, which requires entering ourMac’s login password. Once done, you’re presented with a constant stream of information asprocesses are accessing your disk.

1 $ defaults write com.apple.finder AppleShowAllFiles -bool FALSE

1 $ killall Finder

1 $ yes

1 $ sudo fs_usage

Some processes you are likely to see are Time Machine (backupd) and Spotlight (mds).

To cancel, you can press Ctrl-C.

View the Contents of Any File

Sometimes we have a file and we just don’t know what format it is. If it’s likely to be a textformat, we can attempt to open it in TextEdit, but it doesn’t always work. We can investigateany file from the Terminal by using:

No matter what the file is, this will open it. On files like MP3s or videos, it’ll likely be gibberish.But if you’re trying to recover a corrupt document, this might help.

Rebuild Spotlight

Spotlight can occasionally not work as well as we’d like. Sometimes, we just need to tellSpotlight to create a new index so it can find files as fast and efficiently as possible. To do this:

The above command will delete Spotlight’s index, forcing it to start a new one. An easier wayof completing the command is to enter the first part of it and, for the location, just drag a harddrive from your desktop to the Terminal window.

Remove Duplicate “Open With…” Entries

A common bug in OS X is seeing duplicate apps within the “Open With…” menu which can getquite full! To fix it:

1 $ cat /path/to/file

1 $ sudo mdutil -E /Volumes/DriveName

1 $ /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user

The above command will work in OS X Leopard and above. Unlike the other commands, I’drecommend restarting your Mac.

Enable Text Selection in Quick Look

Quick Look is great but wouldn’t it be even better if we could select text from within QuickLook without having to open the document? Well with this command, you can:

To revert the changes:

Open Files In Any Application

You can open documents directly from the Terminal very easily, but what about opening themin another application that isn’t the default one for its file type?

Doing the above will open our text file in the app AppName. Simply change the app and file towhatever you need.

Check the Uptime Of Your Mac

It can be days, weeks or even months before we reboot our Mac and it can sometimes be solong that we can’t even remember when we last did. To see how long our Mac has gone

1 $ defaults write com.apple.finder QLEnableTextSelection -bool TRUE

1 $ killall Finder

1 $ defaults write com.apple.finder QLEnableTextSelection -bool FALSE

1 $ killall Finder

1 $ open -a /Applications/AppName.app /path/to/file.txt

without a restart, we can use:

This will display the current time and how long our Mac has been running.

Install OS X Software Updates

Despite Software Updates moving to the App Store in Mountain Lion, we’re able to use thecommand line to install system udates without having to launch it. To see available softwareupdates for your Mac:

After a few minutes, you’ll be given a list of available updates.

If you’d like to install all available updates, enter:

Display A Custom Message At The Login Window

When using a multi-user Mac, it’s often good to have a message display to provide someuseful information, such as “Hey, sticky hands! Others have to use this keyboard, y’know.”

Next time you log out or restart your Mac, your message will appear. To remove the messageentirely:

1 $ uptime

1 $ sudo softwareupdate -l

1 $ sudo softwareupdate -ia

1 $ sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Hey, Sticky Hands!"

1 $ sudo defaults delete /Library/Preferences/com.apple.loginwindow LoginwindowText

Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh

Start a Simple HTTP Server in Any Folder

If you’re needing to quickly test some HTML that you’re working on, start a simple web serverwithin any folder on your Mac. Navigate to the folder to use and enter:

The number at the end is the port to use, open your browser and visit http://localhost:8000 Youcan use the default of port 80 if you wish and remove the port number entirely.

When you’re finished, simply press Ctrl-C.

Run the Same Command Again

You will have seen a few of these commands have required us to enter sudo first, to run themas the root super user. Sometimes, we can enter a long command, only to find out we forgot toput sudo first. Thankfully, we don’t need to re-write the entire command again (or copy andpaste). Instead, we can use a very simple shortcut that stands in place of your previouslywritten command:

If we needed to enter the same command again but with sudo in front, we can just type:

Download a File Without a Browser

If you’d like to download a file without using a browser, we can use the following command:

This will download any URL you enter to the folder you’re currently in. Some browsers try to

1 $ python -m SimpleHTTPServer 8000

1 $ !!

1 $ sudo !!

1 $ curl -O http://appldnld.apple.com/iTunes11/091-6058.20130605.Cw321/iTunes11.0.4.dmg

Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh
Harmanjit Singh

automatically open files when they’re downloaded or add a pesky file extension when youdon’t want them (especially when dealing with text files that have something else besides the.txt extension).

Shutdown Your Mac, With or Without a Delay

To shut down your Mac immediately:

To restart your Mac immediately:

We can even add a time delay (in minutes) if we wish:

Whilst this might not be very useful on your own Mac, if you spend any time remotely logged into Macs via the command line, these can become very useful at restarting remote servers.

Disable Mail’s Reply Animation in Mountain Lion

Mail has a great looking animation whereby if you hit reply to any message, a composewindow animates into view. It’s not for everyone and sometimes just having the windowappear instantly. To turn off the animation:

Quit and relaunch Mail for the changes to take effect. To revert the changes:

1 $ sudo shutdown -h now

1 $ sudo shutdown -r now

1 $ sudo shutdown -r +60

1 $ defaults delete com.apple.mail DisableReplyAnimations -bool TRUE

1 $ defaults delete com.apple.mail DisableReplyAnimations -bool FALSE

Prevent Your Mac From Sleeping

We’ve all left our Mac doing something that will take some time to do, only to come back andfind it went to sleep. We can prevent this from happening by using a simple, and humorouslynamed, command:

Entering the command on its own will keep the Mac awake until you stop it by pressing Ctrl-C.You can add a time parameter with:

The number represents the number of seconds, so our command above will stop the Mac fromgoing to sleep in the next ten minutes.

Create a File Of Any Size

There are occasions when we just need to a file of a particular size for testing. I often find ituseful to copy a 1GB file over a network to get an idea of speeds. Finding a file that is the sizewe want is tricky, but with the command line we can create an empty file of any size that wewant.

You can specify the file size in bytes (b), kilobytes (k), megabytes (m) or gigabytes (g). Theabove example creates a test file of 1GB called test.abc but you can name it whatever youwish and it doesn’t need to have a file extension.

Continually Monitor the Output of a File

This one is for all the budding system administrators out there. If you’d like to keep monitoringa text file and view any changes to it as they’re made, there’s a suitable command that willconstantly monitor your chosen file and display any new lines as they’re added, perfect for

1 $ caffeinate

1 $ caffeinate -u -t 600

1 $ mkfile 1g test.abc

monitoring system log files.

Your Terminal window will constantly watch your specified file (in this case, the system.log andevery time another line is added, it will print it on the screen.

To cancel, press Ctrl-C.

Get Your Network IP Address

Sure, we could open System Preferences, select Network and then view our IP addressinformation, but doing it through the command line is so much cooler!

The term en0 represents the network interface to use. Similar to some programminglanguages, the first network interface starts at zero and then counts up, so if you have twointerfaces (such as ethernet and WiFi) then they would be en0 and en1, respectively.

By default, your Mac will always designate a wired network connection as en0, unless yourMac doesn’t have built-in ethernet. You can substitute en0 with en1 if you’re not using yourwired connection.

Get Your External IP Address

The most common way of finding out your public IP address (the one that we’re provided byour ISP) by visiting a site such as What Is My IP or even typing “what is my IP address” intoGoogle.

We can actually use the Terminal to discover our public IP address using a similar service asabove called IP Echo.

1 $ tail -f /var/log/system.log

1 $ ipconfig getifaddr en0

1 $ curl ipecho.net/plain; echo

As soon as you run the command, you’re presented with your external IP address. Whilst itmight not be as quick to type as visiting one of the aforementioned sites, we can do a lot withthe Terminal output, especially if we’re wanting to include it in some sort of script.

Test Network Connectivity

You’re likely to have heard of the term “ping” at some point. Ping sends very small bits ofinformation over a network to a remote computer, timing how long it takes for a response to bereceived. It’s useful to see if an IP address is working or if a website might be down.

Running the above command will send 10 packets of information and provide detailedinformation about the response time. You can substitute www.apple.com for any other domainname or IP address.

Disable Google Chrome’s Two-Finger SwipeNavigation

For Macs with a built-in multitouch trackpad or used with the Magic Trackpad, Google Chromeoffers its own version of two-finger swiping to go forward and back. Whilst it’s easy to changethis behaviour in Safari, doing so in Google Chrome requires a little Terminal trickery:

Quit and restart Google Chrome to see the changes and you’ll notice you can’t two-fingerswipe anymore. To revert the changes:

Prevent Apps From Saving to iCloud by Default

1 $ ping -c 10 www.apple.com

1 $ defaults write com.google.Chrome.plist AppleEnableSwipeNavigateWithScrolls -bool FALSE

1 $ defaults write com.google.Chrome.plist AppleEnableSwipeNavigateWithScrolls -bool TRUE

iCloud is a great service but if you prefer to use Dropbox, or just save files to your Mac, thenyou’ll no doubt have been frustrated that many iCloud-compatible apps offer iCloud as thedefault Save… destination. Thankfully, we can change this:

Quit and relaunch any app that uses iCloud and now any new documents will default to yourMac in the save dialog rather than iCloud.

To revert the changes:

Make the Icon of Any Hidden App in the DockTranslucent

Hiding apps when you’re not using them is a great way to free up screen space but there’s notreally any way to distinguish between which app is hidden and which isn’t. We can alter theDock so any apps that are hidden will have a translucent icon:

To revert the changes:

Autocomplete Paths

1 $ defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool FALSE

1 $ defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool TRUE

1 $ defaults write com.apple.Dock showhidden -bool TRUE

1 $ killall Dock

1 $ defaults write com.apple.Dock showhidden -bool FALSE

1 $ killall Dock

When entering a long path name such as:

It can be very tedious to enter it all out. What we can do instead is use the Tab key toautocomplete. To use it, simply start entering any command where you’re needing to type apath and once you’ve entered the first or second letter, press Tab. If there’s only one folder thatthe first few characters could autocomplete to, it will do so. If not, you can press Tab twice andit will jump as far as it can, then display all potential files and folders you might want to get to.

To try this, enter the following but instead of pressing Enter, press Tab instead:

You’ll find it then autocompletes to:

You’ll likely hear an alert tone as well. That’s because there’s two folders you might wantaccess to: /Users and /User Information. You can then add the last character to the path andpress Enter.

It works very similar to autocomplete of words in iOS.

Make Your Mac Talk

Mac OS X has some great speech functionality built-in and we can even have it say anythingwe want:

We can even go one better and have it read any text file we like:

1 /Volumes/Macintosh\ HD/Users/admin/Library/Application\ Support/

1 $ cd /Us

1 $ cd /User

1 $ say "This Mac runs OS X, not OS ex"

1 $say -f /path/to/file.txt

Our Mac can then say whatever was in the text file.

Restore a Disk Image to an External Drive

You can mimic the behaviour of Disk Utility and restore a disk image file to an volumeconnected to your Mac:

It will skip verification (you can remove that part if you want to verify it but it can take sometime) and you can restore an image, such as a copy of OS X, directly to a volume or partition.

Turn Off Dashboard

Dashboard was once the future of quick-to-access apps such as a calculator and sticky notes.Despite being quite popular for a few years, it’s quickly faded into obscurity. It’s still aroundand usually opened accidentally.

I use Mission Control extensively and have it positioned on the far left but, honestly, I prefer itgone completely. Thankfully, Dashboard can be permanently silenced:

You’ll find that Dashboard is no longer running, along with any widgets you might have hadinside. Don’t worry, you can bring it back if necessary:

1 $ sudo asr -restore -noverify -source /path/to/diskimage/dmg -target /Volumes/VolumeToRestoreTo

1 $ defaults write com.apple.dashboard mcx-disabled -boolean TRUE

1 $ killall Dock

1 $ defaults write com.apple.dashboard mcx-disabled -boolean FALSE

1 $ killall Dock

View All Active Processes

The app Activity Monitor can give us a detailed view of what our Mac is currently doing. Wecan replicate much of its functionality in Terminal:

Once running, we can easily see all the current processes, listed by processor usage with theprocesses using the most CPU moving to the top of the list.

Additionally, there’s plenty of other information at the top of the window, from how manyprocesses are running, how much RAM is currently in use to the amount of network traffic wehave generated.

Advertisement

See A List of All The Commands You’ve Entered

For our final one, we can enter a command to view all the commands we’ve entered at thecommand line:

All of the previous commands that you’ve run within Terminal are listed here, giving you theability to go back and see what you’ve already done.

1 $ top

1 $ history

Advertisement

Conclusion

The Terminal can help you configure your Mac exactly how you want it and provide access tofeatures that just don't have any graphical interface to change. There are many options that areperfectly safe to use but to avoid overwhelming the user, they're hidden away, only to be foundby power users wanting to make the change.

The command line is a very powerful tool and, just as Uncle Ben said to Peter Parker, "Withgreat power comes great responsibility". Use it wisely!

Difficulty:Intermediate

Length:Short

Categories:

Terminal AirDrop OS X

Translations Available:

Tuts+ tutorials are translated by our community members. If you'd like to translate this post into another language, letus know!

About Jordan Merrick

I'm a technology writer and web designer living in the UK. I write for a number of Apple-related sites,including Sparsebundle. I also create web templates available at ThemeForest and offer bespoke webdesign services at my own site, jordanmerrick.com. You can find me on both App.net and Twitter !

Related Courses

Advertisement

Related Tutorials

Apps

So You Bought a Mac?Jeffrey Way

Quick Tip: How to Write to NTFS Drives in OS X MavericksComputer Skills

How to Take Raspberry Pi Screenshots With VNCComputer Skills

How to Use a Raspberry Pi as a Local Web ServerComputer Skills

Quick Tip: Revealing Hidden Files in OS XComputer Skills

(http://send.getapp.com/SHHr)

Infusionsoft(http://send.getapp.com/SHHr)⋆⋆⋆⋆⋆ # 56,554 $ 30,719CRM tool for Small Businesses

(http://send.getapp.com/SHJf)

RelateIQ(http://send.getapp.com/SHJf)⋆⋆⋆⋆⋆ # 0 $ 3,988

Zoho CRM(http://www.getapp.com/x/zoho-crm-application?

⋆⋆⋆⋆⋆ # 29,540 $ 17,494Web-based CRM application

Jobs

Envato Marketplace Item

43 Comments Mactuts+ Login

Sort by Best Share

Join the discussion…

• Reply •

Basti • a year ago

Very informative. Nice one Jordan! 7

Thomas Lee • a year ago

Favorite

Share ›

Graphic Designerat Dyad Communications in Philadelphia, PA, USA

Web Developer (PHP)at Spiral Scout in Minsk, Belarus

WordPress Developerin Boston, MA, USA

King MEDIACategory: images-and-media

$17.00

• Reply •

Thomas Lee • a year ago

`cd` as a tip/trick? Seriously? 4

• Reply •

Johnny Winter • a year agoMod Thomas Lee

I suppose you could say that things are easy when you know how. When you don'tknow, though, that's when you face obstacles. For the person who is new toterminal, a tip like this could be extremely useful. Not everyone is as knowledgeableas you!

2

• Reply •

Thomas Lee • a year ago Johnny Winter

I understand that people who don't even know what Terminal is would needthat, but calling it a Tip (and certainly a Trick) seems a bit ridiculous. It's anessential.

2

• Reply •

Johnny Winter • a year agoMod Thomas Lee

Sure! We could have called it 40 Essential Tips & Tricks. ;-) 2

• Reply •

twe4ked • a year ago Johnny Winter

Feel like it belongs in an Introduction to Terminal post.

• Reply •

Johnny Winter • a year agoMod twe4ked

How about 'An Introduction to 40 Essential Tips & Tricks' ? ;-) 9

• Reply •

Ben • a year ago

Super useful! I didn't know some of these things were possible! Thanks :-) 3

keystonelemur • 10 months ago

Well, here are a few tips for people that are already mildly comfortable with a command lineand want to take the next step (I'll put a more complete writeup on my blog later atbaweaver.com)

1. Install ZSH, as well as Oh My ZSH. These will save you an immeasurable amount of time.It comes with tab completion, custom theming, plenty of built in aliases, git branch support,and a lot more. It's the single best thing you could possibly do with your terminal.

2. Learn what an alias is, and use them religiously. If you type more than five characters at atime you really need to automate that down, script it, or alias it.

3. Look into TMUX, which will allow you to keep preconfigured terminal sessions for workingon multiple windows such as in a Rails deployment when you need to have a server, aneditor, a git / files window, and whatever you can think of.

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

• Reply •

see more

editor, a git / files window, and whatever you can think of.

4. Learn how to pipe and redirect output of commands, such as 'ls > file.txt' prints all thatoutput to a text file.

5. Lean about the commands sed, awk, grep, and column. Those four commands will getyou a long distance in any type of text file or log watching.

2

• Reply •

dcb • a year ago

Isn't this a forward slash "/" while this is a backslash "\"? 2

• Reply •

Johnny Winter • a year agoMod dcb

Corrected. Thanks for pointing that out. 1

• Reply •

Jordan Merrick • a year ago dcb

That's correct :) We'll get that amended shortly

• Reply •

Iman Mohamadi • a year ago

say command was something I've been looking for many times but couldn't find it, thanksfor the tip.

1

• Reply •

mattack1 • a year ago

You did fs_usage wrong. Also, ~ is a tilde. There were several other problems too. 1

• Reply •

IronMike • a year ago mattack1

How is fs_uage wrong? And where did the author say the tilde was called somethingelse? Or are you just here to complain?

1

• Reply •

the_ed • a year ago IronMike

He left out the "_" . Should be fs_usage, not fs usage 1

• Reply •

Jordan Merrick • a year ago the_ed

The fs_usage command appears to be written correctly but if it isn'tfor you, could you post a screenshot or link? As more than one personis reporting it, we'll check to see if something might be causing theunderscore or other special characters to not be fully displayed.

3

Jordan Merrick • a year ago mattack1

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

• Reply •

Jordan Merrick • a year ago mattack1

That's peculiar, the article is showing fs_usage as written correctly and that noamendments have yet been made. If there are any further problems, please let usknow and we'll look to get any incorrect info fixed straight away.

• Reply •

Taylor Marks • 10 months ago

A lot of this seems to be so common knowledge I'm curious why you bothered... this articlewould have been higher quality by just filtering it out to only have the truly obscure gems.The quicklook highlighting one was nice (although I didn't need to kill finder for it to takeeffect), and I never knew about yes, caffeinate, or mkfile.

• Reply •

SRK • a year ago

I'll just leave this here...

https://github.com/mathiasbyne...

Familiar at all?

• Reply •

Johnny Winter • a year ago

see more

Mod SRK

SRK, should that link be familiar? From your comment I can only conclude that youhave posted it to suggest that the author of this article has, in some way, plagiarisedanother source.

If that is your suggestion, then I take any allegation of plagiarism extremely seriouslyindeed. Every single author that writes for Mactuts+ is contractually bound not toplagiarise content from other sources. All of their contributions should be their owncreation.

Therefore, I have investigated your assertion that this work may have beenplagiarised and I have found the following:

Of the 39 tips that the author has listed, 29 of the tips that appear in this article DONOT appear in your referenced link. In summary, 75% of the tips in this article arenot available from the article that you have referenced, meaning that no plagiarismhas taken place.

That means that there are ten tips that appear both in this article and the article thatyou reference. Of those ten, we have been using one, (remove shadows from screen

9

BrechtDM • 8 days ago

Error spotted (I think): defaults delete com.apple.mail DisableReplyAnimations -bool TRUE

instead of defaults write [and so on]

Share ›

Share ›

Share ›

Share ›

• Reply •

instead of defaults write [and so on]Sorry if already under here or inaccurate. Seems to work better with me.

• Reply •

Isobel • 20 days ago

When i type mkdir into terminal, it says 'permission denied". Why is this happening?Thanks.

• Reply •

raggmopp • 3 days ago Isobel

you may be in a directory where a User cannot write to. Does it work if you invokesudo before the command?

• Reply •

Christina • a month ago

see more

Hi, I have a request, hopefully someone can help...

Every time I start my computer I always have to delete the preferences to my Wacombamboo tablet. Otherwise the pen clicks automatically every few seconds...Right now what I do is have "Bamboo Utility" open on start-up and then I delete manually.

Is there a way to automate this on terminal? So that it starts automatically, runsautomatically and closes on startup?

Here is the Log from the software, plus a screen shot...

Deleting PreferencesRemoving /Users/user/Library/Preferences/com.wacom.pentablet.prefsRemoving /Users/user/Library/Preferences/com.wacom.touch.prefsRemoving /Library/Preferences/Tablet/com.wacom.pentablet.prefsRemoving /Library/Preferences/Tablet/com.wacom.touch.prefsRestarting Driver 247Done.

Thanks!

Nicnacnic • 3 months ago

Jordan,

Question related to terminal. I'm being asked to run the following on a file to change theowner to root:

sudo chown root /Library/(filename.extension)

When I run it, the owner changes to system, not root. I tested this on 2 different machineswith the same result, however a friend of mine tested it and the file ownership changed toroot.

Share ›

Share ›

Share ›

Share ›

• Reply •thoughts?

• Reply •

Cj • 3 months ago

Try entering (without the “>”) :

> emacs

Then hold “esc” and “x” at the same time

Then enter:

> tetris

or

> snake

You’re welcome, two hidden games right there.

• Reply •

alenn • 3 months ago

Superb useful to a new Mac user, thanks for your effort!

• Reply •

jeff • 4 months ago

I spend about 80% of my time in a terminal window, and there were several things in thisarticle I had never heard of. Thank you!

• Reply •

Turd Ferguson • 7 months ago

thank you for the screenshot one, those shadows render like shit sometimes! :)

• Reply •

Bob Berman • 9 months ago

Thanks for posting this, my unix sys admin days are nearly 20 years gone, so this is a nicelittle refresher!

• Reply •

Felipe Volpatto • 9 months ago

"$ python -m SimpleHTTPServer 8000" is amazing!

Nice one, man!

• Reply •

john • 9 months ago

hi everyone my name is bob the burger

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

Share ›

• Reply •

Luke • 11 months ago

I've been trying to figure out how to get terminal to do a simple keystroke in an app, like youcan do in applescript with "tell application "System Events" to keystroke space" for hittingthe spacebar. Is there a way to do this in Terminal?

• Reply •

Matt • a year ago

see more

Be careful using the "yes" command. You'll fill up your hard drive faster than you can blink.To show you the results of "yes," run this command "yes > ~/Desktop/tons_of_ys.txt"

In a few short moments, you've got a file that is several GBs large. If you want to use theyes command to stress your machine, try using this command "yes > /dev/null" This sendsall those tiny little "y's" into what is called a null device. It essentially sends all that outputinto a black hole instead of filling up some random space on your hard drive.

Also, note that using the "yes" command will only peak one of your processors. This wouldrequire quite a few recurrent "yes" commands, especially with hyper-threading being soprevalent - 2 physical cores is 4 theoretical and so on... I'm sure there is some commandline wizardry that allows you to hit all of the cores at once, but that's beyond me. Hope thishelps!

• Reply •

AppleGuy • 6 months ago Matt

Yes > /dev/null/ Use this over what the writer said - If you use that tool without actually knowing whatit does, you can mess some things up. By piping the output to the dev/null folder,you basically tell a *nix based OS to throw out whatever is inside that folder withoutreturn. I always teach techs to do this over a raw yes...

• Reply •

Albert Pak • a year ago

Thank you for this list of useful commands - lots of handy commands

• Reply •

deadlyspoons • a year ago

To "Run the Same Command Again," you can use the UP arrow on your keyboard to see theprevious command you've entered. Keep hitting UP and DOWN arrow to navigate yourcommand history.

Share ›

Share ›

Share ›

Share ›

Share ›

• Reply •

Stanisław Olszak • a year ago

purge is also a useful command - frees inactive memory ;)

• Reply •

BDA • a year ago

having these as apple scripts or automator apps would be really handy

• Reply •

Josh • a year ago

Great Article

• Reply •

Peter • a year ago

The Command + k key combination also clears the current view!

• Reply •

twe4ked • a year ago

Yuuup, never thought I'd need cd.

Subscribe Add Disqus to your site

Share ›

Share ›

Share ›

Share ›

Share ›