Basic Command Line Utilities, Tips, & Commands
Many Mac users avoid the command line altogether, a reasonable amount probably don’t even know it exists. For the curious out there, here are some basic and essential commands and functionalities to know if you want to get started using the Mac OS X Terminal. We’ll cover simple file manipulation, maneuvering in the file system, displaying and killing processes, and more. Remember to remove the brackets or the commands won’t work.
The Command Line Basics
ls -la
list all contents of a directory including hidden filescd [directory]
move to the specified directory, cd /Applications will move to your applications foldermv [file1] [file2]
mv is able to rename files or move them, depending on usagecp [file] [destination]
copies a file to either a new filename or destinationcat [file] | more
display contents of a file screen by screen by ‘piping’ the contents through moretouch [file]
creates a file with the given name, eg: touch test.txt will create a blank text filetop
display a continuously updated list of all running processes, including memory and cpu usage, PID is the process ID which you would use to kill a processps -aux
list all processes running from all users, -ux will list only processes of current userkill -9 [pid]
kill the specified process id (basically force quit for the command line)rm [file]
rm removes the specified file or directory, there is no warning so use with cautionping [ip]
determine network latency by pinging another host
General Command Line Usability Tips
- Use the tab key, the tab key will autocomplete directories and filenames for you
- Enable colored terminal, this makes it easier to browse through large amounts of files
- If a command confuses you, try running it with the –help flag, which will often display basic instructions on the given command
- Remember manual pages exist on many commands as well, access them by typing
man [command]
, eg: man ping - If the output of a command flies by you and is too much to fit on one screen, try piping it through more, like so:
ls -la |more
this will enable you to see the output a screen at a time - You can export the contents of a file, output of a command, and results of a script to a text file using the alligators (improper terminology, excuse my forgetfulness), eg:
ls -la /Applications > applist.txt
- If you’ve ever noticed your CPU load skyrocket inappropriately, a good place to find the errant process is with the
top
command, use top in conjection withkill
to find the process ID and kill the CPU hog - Don’t be afraid to get your hands dirty!
For more info, tips, and tricks, be sure to check out our other command line entries and read Ten OS X Command Line Utilities you might not know about.
[…] Basic Command Line Utilities, Tips and Commands […]
[…] you are absolutely clueless about command line interfaces and are on a Mac using OS X then check this link to learn more. If PC is your platform and you are also in need of some command-line information then check this […]
[…] you are absolutely clueless about command line interfaces and are on a Mac using OS X then check this link to learn more. If PC is your platform and you are also in need of some command-line information then check this […]
[…] Also it is Mac OS X 10.5.3 (Leopard) https://osxdaily.com/2007/02/07/basic-command-line-utilities-tips-commands/ […]
[…] Terminal & tn3270 […]
[…] Basic Command Line Utilities, Tips, & Commands – OS X Daily (tags: unix bash tutorial) […]
Don’t forget open, which opens a file as if it were double clicked in the Finder, or open -a names an application like open -a Mail.app
you could use this to edit dot files that don’t show up in the finder, for instance open -a TextEdit.app .bashrc
open -f is a lot like more, but it can be directed at a mac application: ls -la | open -f TextEdit.app
Also pbcopy puts text on the Mac clipboard, for instance ls -la | pbcopy copies the output of the ls command.
if you don’t want to go through the hassle of reading an entire man page, try the ‘whatis’ command, try it on another command as so: whatis ls
this will report a simple one line explanation of the commands usage. Probably more useful for the advanced users out there…
How does one enable a colored terminal, exactly? And does that mean coloring the prompt and pre-prompt text, or enabling colors for files, e.g. making ls show folders as blue, executables as green, etc.?