Despite the ubiquity of graphical interfaces and any convenient manipulators like Magic Mouse and Magic Trackpad, Terminal.app application to It is still quite useful and a little "geek" tool to perform certain operations, which most of us are familiar enough superficially. In fact, in his "taming" no big deal, so for all readers MakRadara I have prepared the team for the terminal, which may be useful.
First, let's say that your application Terminal.app itself, as well as all the useful office tool, located in the Applications> Utilities folder. Immediately after its launch, you will see a line that says the computer name and the current directory, and after the dollar sign ($) - affably blinking cursor, which invites you to enter its first team ...
The list of files and folders - ls
By default, after running the utility in the user's home folder is selected as the working directory. To get a list of files and folders in it, simply run the command of two letters ls
.
There are several variations of this command, which are caused by different keys (actually their a lot more):
-
ls -l
displays detailed information about each item, including permissions, file size, etc. In addition, the first character of each line will determine the type of data: if this is the Latin letter «d», then we have a catalog, and if the hyphen (-), it is usually file. -
ls -a
displays a list of all files and directories in the current directory, including hidden items (names in Mac OS X starting with a dot).
Housekeeping tip: keys can be easily combined with each other, so if you want to view data about all the elements of the directory, including hidden files, then your team should look like So:
ls -la
Moving between Directories - cd
The name of this team comes not from old CDs that Apple has successfully killed their digital iTunes Store, and from two English words «change directory» - just that she deals:
- Write
cd Music
- Terminal and go into the Music folder, of course, if it exists in your current directory. - To access the folder in the above, use the command level
cd ..
(Two points). - And the command cd you are instantly transported to the user's home directory.
The full path to the working directory - pwd
The name of the team, too, comes from the first letters of the phrase «print working directory». No matter what directory you are, the result of this command will be the full path to the current directory.
Create a directory - mkdir
This command creates a directory with the specified name. For instance, mkdir Temp
create in the current folder Temp directory. If you forget which directory you're currently in, use pwd
:
Deleting Files and Directories - rm, rmdir
During this action on files and directories via the terminal it is required to take into account a small but important detail: there is no Recycle Bin, so the data is permanently deleted.
But in general the team rm test1.txt
test1.txt delete the file from the current directory. And if we add, say, the key «i» (rm -i test2.txt
), The user will need to confirm the deletion.
Unfortunately, the directory removal is more difficult, because for this operation there several types of commands:
-
rmdir Test
remove the Test directory only if it is empty and does not contain within itself the subfolders or files. -
rm -r Test2
recursively delete all files and folders located inside Test2, and it removes the very end.
Moving and copying files of - mv and cp
Two teams perform virtually the same actions, and therefore the list of the parameters have the same. If I want to move a file from one directory to another, I need to use the command:
mv ~ / test1.txt ~ / Documents / test1.txt
The first parameter (~ / test1.txt) performs file that we need to move, and the second - the destination directory and the resulting file name.
Once again, the mistress on a note. First, as you may have guessed, is not necessarily move in the right directory to perform actions on files. Enough to know his name, full path, and use them as command parameters.
Second, each time not to write the path to your home directory, it suffices to use a tilde (~). For example, saving
~ / Documents
equivalent to/ Users / user / Documents name
.
To copy files simply replace mv
on cp
:
Other commands
Of course, describe all available commands (and their keys) is not possible, so I will focus on several interesting and useful "copies":
- Run any application in the system with the command
open
Specifying by a space and the path to the application name. For example,open /Applications/Airfoil.app
- With a team
who
You can see a list of users who are logged into the system. Naturally, this is only true if the operation on the computer assumes input multiple users or active SSH. - Team
cat test.txt
It will allow you to bring in a Terminal window contents of the file named test.txt, but you will not be his edit (you need to use a text editor such as nano, vim or emacs), only view. - Cancel the process any command (ping whether the work or shell script) is always possible via the universal keyboard shortcut
Control + C
. - Clear Terminal window from a large number of text simply by running the command
clear
. - To execute some commands may require administrator privileges. The fastest way to do this by adding to the top of the command line
sudo
. In this case, the terminal will ask for a password of your account. - View a list of running processes, use the command
top
True, in this case the data will look less clearly than in the monitoring system. - To display at a specific command, you can use the detailed help
man
Specifying the name separated by a space interests of the team. - I almost forgot to mention a fantastic search utility
grep
, Which can be used to find a text string in a file, say, or a particular process in the process list (for example,ps ax | grep smbd
).
Perhaps this and stop, and if I missed something or have wrong - you are welcome in the comments.