Five Quick Terminal Tips 10
Terminal
Hey
This is going to be a quick a post about Terminal. It is going to feature five quick Terminal tips that can make your life just a little bit easier. These tips are designed to be small and easier to remember. If you know of any quick one line tips please leave a comment. Terminal, if you don’t know by know, is open by going to Applications > Utilities.
1) View The Current Folder Path
If you are in a really deep folder path and you forget which folder you are in this simple command will display which folder you are in:
pwd
Great for finding which path you are in.
2) Reset The Folder Path
Similar in nature to the previous tip, if you want to reset the path you can type the following.
cd
or
~
3) Cancel A Script / Program
If you make your scripts, or use someone else’s, you may want to cancel the command or program before it takes up to much time, resources or bandwidth. All you need to press is two buttons. All you have to do it press:
Control + C
This will stop any program or script and return you back to the command line.
4) Clear The Screen
If you have a messy output from a program or script and you want to make your screen blank again all you have to is type:
clear
That will clear your screen and return it back to the command line.
5) View The Manual Of Any Command
Probably one of the best tip in anyone arsenal if the manual command. This gives you all of the information about the command. A great tip for finding more information about any command and expanding your knowledge.
man [command]
You can find more about this command here.
If you know of any more quick one line tips please post them below. There must be hundreds out there, I would love the here about them.
P.S Sorry for the lack of posts yesterday, I felt a bit ill and I really couldn’t write.
If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.
Where To Next?
10 Responses to “Five Quick Terminal Tips”
-
1
Firstly, you can easily memorize the “pwd” command by thinking of it as “print working directory”. Same thing applies to the “cd” command: “Change Directory”.
Second: “sudo !!” is really handy. If you wrote out a lengthly command and forgot to add “sudo” to the beginning (or didn’t know you would need it) then “sudo !!” repeats the previous command as sudo.
MacTipper
My Mac-Tipping BlogComment By MacTipper on August 21st, at 10:35 pm
-
2
Neat tip, I haven’t heard of the second one.
Comment By admin on August 21st, at 11:02 pm
-
3
Even better than “clear” is “control + l”. Same effect, less typing ;-)
Comment By Frank on August 22nd, at 7:40 am
-
4
1. Objects dragged from the finder to the terminal window will insert the path to that object. Want to cd to a folder in that flash drive you just plugged in? Type “cd” then a space and drag the folder onto the terminal window and hit return. Virtually any command that accepts a path will work.
2. Want to recall a previous command? Press the up arrow until it shows up, then hit return. If you accidentally go too far, down arrow will take you back the other direction in the queue.
3. The ‘history’ command will show your last bunch of commands. How far back it goes is controllable (man history will show you how).
4. Just recalled a command line, but you’d like to make a slight modification? You can edit the command line. Simply typing will insert at the insertion point. You can use the left and right arrows to move the insertion point. Ctrl-A will take you to the beginning of the line; Ctrl-E will take you to the end. Delete will delete backwards; Delete[x> will delete forward. Ctrl-T will swap (transpose) the character your cursor is on with the one before it. If you know emacs, many commands will work… experiment.
5. Long file name you’d rather not type? Type the first few characters then hit tab. The terminal will try to complete the name. If what you’ve typed is not unique enough two things can happen:
It might complete up to the contention, then you can add a few charcters and hit tab to complete some more
It might not complete any more because you are at the contention, hit tab again and you will see a list of possibilities
6. Want to open that text file using TextEdit without opening a bunch of Finder folders to hunt for your file? Type the following:
open -a textedit yourfile
(where yourfile is the name of the file you want to open.)
Many Mac applications will work. For example:
open -a preview some_photo.jpg
7. Wish you could go to another directory and do some commands and then return to exactly where you were? Instead of cd’ing to the directory use the ‘pushd’ command:
pushd some_directory_path
Then when you want to return, ‘popd’. (I know that’s technically two one-liners, but…)
8. Want to create a file with all of the file names in a directory?
ls -1 some_path > listfile.txt
BTW, that’s a one, not a lowercase ell. You can leave off some_path to list the files in your current directory, but you may see listfile.txt in your file.
9. The ‘~’ character refers to your home directory, so no matter how deeply you’re nested in your directory structure you can do things like this:
ls ~
to list your home directory, or
cd ~/Desktop
to jump to your Desktop folder (directory).
10. Planning on typing the same long, complex unix command a bunch of times? Use ‘alias’ to create a shortcut. For example:
alias nodots='find . -name "\.*" -exec rm -rf {} \;'
Now I can use ‘nodots’ like a built-in unix command to remove all those pesky dot files that got copied over to my mp3 player when I did a Finder copy. BTW, make sure you cd to your mp3 player first!!!
Comment By Joey Blades on August 30th, at 2:26 am
-
5
BTW, you might want to consider adding a preview function. Some of my html didn’t render the way it does in Taco… Had I known, I probably would have fixed it…
PS
Nice idea for a website, I’ll keep poking around.
Comment By Joey Blades on August 30th, at 2:32 am
-
6
Nice comment Joey, thanks for that. I will add a preview function if I can find the right code.
Comment By admin on August 30th, at 11:15 am
-
7
hi their i need help
i ably this stupid command and i want to cancel it but how ?
sudo rm -rf ~/.TrashComment By salma on January 6th, at 5:45 pm
-
8
Thats the delete command “rm”. Once it is run you can’t get your files back. You also added sudo which meant it would blindly delete anything without asking.
Comment By admin on January 6th, at 5:49 pm
-
9
However, you only deleted your Trash.
In the future, if you run a command, then realize that you didn’t want to, you can hit Cmd-. to stop it.
Comment By MacTipper on January 6th, at 6:11 pm
-
10
I use top a lot and then kill (to stop the app)
Comment By potacken on January 14th, at 9:37 am

