Jan 15, '14 07:00:00AM • Contributed by: LexFriedman
The Terminal gurus who know this trick, I guess: Hold down the Option key and click where you'd like the cursor to move, and Terminal rushes the cursor that precise spot.
|
|
|
Move the Terminal cursor position with the mouse
Jan 15, '14 07:00:00AM • Contributed by: LexFriedman
Which Terminal gurus among us hasn't wasted too many minutes to count arrowing around the manipulate the cursor while deep within the confines of the command line?
The Terminal gurus who know this trick, I guess: Hold down the Option key and click where you'd like the cursor to move, and Terminal rushes the cursor that precise spot. Bash Function to open man pages in new terminal window
Dec 30, '13 06:30:00AM • Contributed by: tmoswift When I'm stumbling around the command line, I usually need to keep various man pages open for reference. I always forget I can get a dedicated man window from the Help or Contextual menus. This bash function allows you to open a man page in a new window directly from the command line.
Just put this function in your .bashrc file, and when you use the man command, the information opens in Terminal's Man Page specific window setting style. If you don't want to override the default 'man' command operation, you can change the function name to something else. This function expands on OS X's x-man-page url scheme. And of course, there are plenty of alternate ways to view man pages such as in preview, ManOpen, or Bwana. Smallduck is the true author of this hint; I'm merely spreading the word.
We've run a number of hints about preventing a Mac from sleeping, such as this and this.
I came across another really simple way to do this, using the pmset command. Just run this command in terminal: pmset noidle Terminal will display the following text: Preventing idle sleep (^C to exit)... To allow the Mac to go back to sleep, according to its current Energy Saver settings, just press Control-C.
Have you ever wanted to see what's in a Zip archive without unzipping it? Well, it turns out that there is a Terminal command you can use to do so: zipinfo. Just run zipinfo [filename] to get a list of files in an archive.
There are a number of interesting options to this command. The default behavior is to list the files in a short "ls -l" format, but you can also use the -m or -l options to have medium or long lists. You can use the -1 option to only show file names. And there are other useful options in the man zipinfo page. One other useful item is the amount of space the archive takes up, and the amount of space saved. For example: 12 files, 10587791 bytes uncompressed, 9400060 bytes compressed: 11.2% It's worth noting that this command has been around for a long time, and I was surprised to find that it's not mentioned here.
Find which users take up the most disk space. This can of course be used to indentify any number of users so I picked 10 as an arbitrary number.
If you are already root (unlikely, but possible) you can remove the sudo -s part. Here's the command:
sudo -s du -sm /Users/* | sort -nr | head -n 10 sudo -s or it will give a few Permission denied errors before finally spitting out the results, and they may be incorrect. The directory structure should start with the /Users Directory and then it will recursively perform the operation. This may miss any folders outside of the normal user space, but there shouldn't normally be any user data there.
[crarko adds: I tested this, and it works as described. There are third party utilities that will give the same results with a GUI, but this is pretty handy to have for use on remote machines over an ssh connection. It can take a while to complete, so be patient. Also I noticed in Activity Monitor the du process was using a lot of cpu, so it's best to do this while not running other cpu (or I suppose disk) intensive programs.]
There may be times when you want to consolidate all the files in a directory and its sub-directories (or a folder and its sub-folders) into a single directory or folder. For example, you may have a folder with sub-folders for years, and other sub-folders in each year folder for months, and you may want to move files in the month folders all to the top level.
Doing this manually is a complex and time-consuming process. While you might be able to do this by using a search - for example, if all the files are, say, Excel files, you can search for Excel files in the top folder, then just copy them all to a new folder - if there are lots of different types of files, this wouldn't make things easier. Fortunately, there's a way to do this from a command line. On the BedroomLAN blog, Alexios presents two commands that will do this: cd $ROOT_DIRECTORY find -type f -print0 | xargs -0 -I%%% cp %%% $FLAT_DIRECTORY Replace $ROOT_DIRECTORY with the top level directory containing all the sub-directories and files, and replace $FLAT_DIRECTORY with the directory you wish to contain all the files. Note that this command will overwrite any files with the same name, so if you don't have uniquely named files, it's not ideal. You can also use the ln command instead of the cp command, and this will not overwrite files, but will give error messages if there are duplicate file names. See the blog post for more details on this. H/t to robg for pointing this out.
I have a recurring need to extract full names and email addresses from a plaintext archive of email messages. The archive is created by selecting a bunch of emails in Mail, copying them, pasting into TextEdit, and converting to plain text.
For each message in the file, the first line contains the information I wanted: From: Joe Example <joe@example.com>I wanted one email address per line, suitable for pasting into another location. I am far from an expert with the bash shell, but here's what I came up with—I imagine there are many more efficient ways to do this, as I'm sure experienced perl, sed, awk, etc. users may point out. Note that this is highly dependent on the format created by Apple's Mail app in OS X 10.8. grep 'From:' /path/to/archive.txt | cut -f2 -d\< | cut -f1 -d\> | pbcopy The grep bit pulls out the entire From: line, then the first cut command grabs the email address and the trailing close-bracket, by setting the delimiter to an open bracket. The second cut eliminates the closing bracket, by setting that as the delimiter. The output will be one email address per line, sitting on your clipboard ready for pasting. (To debug, just remove the | pbcopy bit to see the output.) I also wanted to extract the names, and came up with a variant to do just that: grep 'From:' ~/Desktop/testfile.txt | sed -e 's/: /:^/g' | sed -e 's/ \</^\</g' | cut -f2 -d^ | pbcopy This one is messier, as names can contain one or more spaces. After getting the From: line, sed is used (twice) to add a carat delimiter immediately after From:, and immediately before the opening bracket of the email address. I then used cut, with the delimiter changed to the carat, to extract the full name (field two) from the found lines. Again, the results are copied to the clipboard; leave this bit off for debugging. With the names and addresses extracted, it's fairly easy to do other stuff with them. In my case, I'm reading them into a couple of array variables in a bash script, so I can then output a name and email address pair to consecutive locations on my multi-pasteboard. If you want to use the names in an array in a bash script, you'll want to change the array delimiter from a space to a newline: IFS=' ' Without this, your array will get split anywhere there's a space in the name values ... or so I've heard, not that it's ever happened to me!
There are several ways to open a Terminal window to the current directory in the Finder. But wouldn't it be useful if you could do the reverse and open a Finder window to the current Terminal directory? Well, you can, and you can completely control the Finder from the terminal.
I have put the code on github with full instructions on how to set it up. It works by using bash_completion, .bash_profile with some applescript to control the Finder, .inputrc and .bash_aliases. Here are some of the features:
[kirkmc adds: I haven't tested this, but it sounds very useful.]
I wanted to find out how long a certain background process had been running. There's a column for CPU Time in Activity Monitor, but that's not real clock time.
It turns out you can get this information with ps, via the etime keyword. So to get a list of every running process, in decreasing order of run time, just use this command: ps -ax -o etime,command -cTo see the results for a single process, just add a grep at the end for the process' name. For example: $ ps -ax -o etime,command -c | grep AppleVNCServer 03-08:09:16 AppleVNCServerSo on my Mac, the AppleVNCServer has been running for three days, eight hours, nine minutes, and 16 seconds. I have a need to do this pretty regularly, so I turned it into a simple command line app: #!/bin/bash # Display the time a given process has been running # Use the process name when calling the command ps -ax -o etime,command -c | grep $1I saved that to a file named psup, and made it executable with chmod 755 psup. Now I can just type psup SomeProcess to see the uptime for SomeProcess.
If you use top in Terminal, you may occasionally see apps with huge VSIZE values. I know this because Witch, one of our apps, is an example of such—it's VSIZE can exceed 11GB.
In trying to figure out why this was so (short answer seems to be: we can't control it, but it's not a problem), I ran across an interesting command, vmmap. This command will spew out a ton of detail about virtual memory usage. Stringing a couple Unix commands together, though, you can extract just the summary portion of the report. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.78 seconds |
|