Getting Help

man ls

Printing working directory

To see the exact path of the directory that we're in:

pwd

Listing hidden files (using switches)

This shows us all of the hidden files as well as the normal files:

ls -lA

Creating and destroying directories

Make a directory:

mkdir Example

Delete a directory:

rm -r SomeDir

Copying and moving files

mkdir SomeDir

cd SomeDir

touch someFile

Now, if we wanted to create an exact copy of "someFile" we'd use this command:

cp someFile newFile

Now what if we wanted to move "newFile" somewhere else?

mv newFile ../newFile

Let's go back into our "SomeDir" directory to bring newFile back over:

cd SomeDir

mv ../newFile newFile

ls

If we now run "mv" without providing a new destination, we can simply _rename _the file:

mv newFile newerFile

Viewing files -- typing in terminal -- copying files into one

cat someFile.txt

You can use cat to create a short text document in terminal:

cat > someFile

You'll see a blinking cursor on the next line for you type some text in. Go ahead and type:

Those who understand binary and those who don't

then hit return

then type:^C

The ^C interrupts the command and is done with Ctrl+C.

We can combine (or "concatenate") these two files with:

cat someTextFile someMoreTextFile > combinedFile

Now if we view that file with:

cat combined

Viewing large files

Using the "less" command, you're able to scroll up and down with your keyboard to view the entire document. When you're ready to finish viewing, just type "q"

less longText.txt

You can also just view the first few lines of the file by using:

head -3 longText.txt

The "head -3" command tells the computer that we want to view the first 3 lines of the longText.txt file. You can change 3 to any number you want, depending on how much you want to view. If you leave it out, it will default to the first 10 lines.

Tailing files

We can view the last few lines of a file just as easily with:

tail -3 longText.txt

"Tail" also has a really useful parameter that it's worth mentioning: -f. When we move along to actually running programs, you'll often want to _watch the log _of what's happening behind the scenes in your programming. To do this, you can use the "-f" parameter with "tail" like this:

tail -f log.txt

OSX, the operating system on the Mac, uses a number of log files. You can peek at what your computer is doing by running

tail -f /private/var/log/system.log

results matching ""

    No results matching ""