Unix commands in terminal mac

Displays the contents of a file. Press the up and down arrows to scroll though the file. Deletes a file permanently : there is no way to get it back. Be careful when using this command! A note about using sudo : The computer has a few built-in safety restraints to prevent normal users from doing bad things, like deleting critical files. The super user has no such restraints. Note that the super user is not necessarily bad: you must use sudo to install programs and do anything else that affects how your computer runs.

Lets start by using ls to look around your computer. Try typing ls into the command line and pressing enter. The computer will reply with a list of names. These names are the names of files and folders in the directory you are currently in. Whenever you open up a new command line, you start in your home directory, which is the directory that generally contains all of your files. Well, that's nice. But what if we want to go someplace else? That's what cd is for. Try entering this command:.

Remember, to press enter once you have finished typing. The computer will not reply, but you are now sitting in your Documents directory. You can test this by running ls again: the list of names will be different. So where do we go from here? How do we know which of these names are folders that we can go into and which are files that we can't? For that, we need more information from the ls command. Let's give it the -F flag to tell us about files and folders. You will notice that this time, some of the names that the computer returns to you will have a slash after them.

These names are folders: the rest are files. You can always cd into a folder by running cd with the folder name as an argument, as long as you can see that folder with ls -F. When you're done looking in folders, it's time to go back up. But how?

OS X's BSD/unix command-line

Luckily, every folder contains a hidden link back up. To see these hidden links, we will use the -a flag for ls to see all. There are at least two hidden links in every folder. In fact, you can give the ls command multiple flags, like so:. If you run this command, you will notice that the.

How to use Terminal on Mac: Basic commands and functions

To go back up a folder, you can always run:. Remember that if you ever get lost in the computer, you can run pwd to see where you are. Computer programmers are lazy. Because they are lazy, they invented some techniques to do more with less work. Here are some of those techniques:. Whenever you need to type out a location in an argument for example, in the cd command , you don't have to type out the whole thing: the first few letters will do. Once you've typed three or four letters, press the tab key, and the command line will fill in the rest for you!

The shell environment

For example, if you are in your home directory, and you type cd Desk and then press the tab key, the command line will automatically complete the command to read cd Desktop! You can also use this if you find yourself mistyping folder names: tab autocompletion will always fill it in correctly. The command line has a few shortcuts built in. For example, to see your previously typed command, just press the up button.

You can do this to submit the same command multiple times, or to edit a command that you didn't type in quite right. Remember, when you use the command line, the computer will cheerfully do anything it can for you. If you ask it to do something bad, it will try to do so. Some people take advantage of this fact by telling novice command line users to run commands that do nasty things to your computer. Here are a few to watch out for. Never run any of these commands! They can and will destroy your computer! The command to remove a file is rm. You can also use rm to remove multiple files at a time.

This command tells the computer to start at the top of the file structure, and delete every single file on the computer without stopping. After this command has run, your computer be empty. If you turn it off, it will not be able to turn back on until you reinstall an operating system on it. Here is an example of setting an environment variable called FOO and displaying its value:.

As you see, by convention we put variables in upper case. Regardless of which shell you use, whenever you type a command in the shell, you will cause a Unix program to execute. This command sequence illustrates two important concepts: piping and options. Notice the vertical bar between them? That's the pipe character.

The pipe takes the output of the first command and directs it as input to the second command. The second thing to notice is the options given to each command. In Unix, options are traditionally prefixed with a single dash character, -. These command-line options change the behavior of the command. In English this command might be read:. List the number of lines in the current directory and then send them to the word count program to count the number of lines. Often these command-line options override defaults that are set in the environment. If you want to change the way the command behaves on a permanent basis, you can set the environment variable automatically when you log in.

Many commands allow you to combine options in a single string—for example, ls -la —but others do not. Learning and using command-line options is a big part of being efficient at the Unix command line. Some commands have so many options that the documentation runs to dozens of pages. Don't let that worry you now. You often need only a few options to perform a given task, and many options are used only when writing programs in the shell language. Once you understand the basics of the command line and the environment, we can begin to dive deeper into the system.

The first place to start is with the manual. One of the nice aspects of Unix is the high quality of the documentation. There is documentation for users, system administrators, and software developers. You access the documentation with the man command. If you aren't sure of what command you're looking for, you can try the -f and -k options. Both options will search a built-in database if it has been configured; it usually has and return all matches. For example, man —k bzer will display the manual pages that start with the string bz :.

There are many commands related to the Unix file system, since it is core to the operating system. We saw one of them earlier: ls , which lists files in a directory:. The ls command may be the most frequently used command of all, and it has many options to adjust its output. One option you will want to know about right away is ls -a list all. These files or directories typically contain configuration information or log files for the Unix system.

The other command you will need right away is the cd command, which you use to change directories.

  1. d-link dns 232 for mac;
  2. 10 Unix commands every Mac and Linux user should know.
  3. gcc fortran mac os x?
  4. logiciel de caisse coiffure mac?

This is akin to the same command in Windows, but with an important difference. In Unix, all drives devices appear as a single drive. Because there are potentially many places to get lost in a growing file system, this commands lets you quickly determine where you are. Note that you can use the cd command with no arguments to quickly return to your home directory. At this point you know how to move around the file system and list the contents of directories. Now we need a way to read the files stored in them. These days most systems come with the less command for this.

The passwd file lists the user accounts on a Unix system, along with their user and group ID numbers, their home directory, and the path to the corresponding command or shell. Running out of disk space is a gradual process that might take years, but can still catch you off guard. There are two commands you can use to check your free space and determine which files are hogging your disk: du disk usage and df disk free. They both take a -h option human readable. To get a sense of how full your disk is, use the df command:. This shows that my home directory is 92 percent full, so I should probably clean it up.

But how do I know where all the space is being used? For this example, I went with an incantation that limits the output to the first 10 lines. Otherwise du will list every directory on the machine, which could easily be too much to grasp. From this listing you can see how much space is consumed by each directory.