Andy Taylor

Andy Taylor

UNIX Command Line Usage Notes

This post is essentially the result of watching Dan Benjamin’s PeepCode screencast, Meet the Command Line and taking bucket-loads of notes.

A few general things to remember about UNIX:

Commands

Change Directory

Directory Listing

Showing the Current Path

pwd shows the current path. It’ll output something like:

/Users/andytlr/dropbox/websites

Copying, Moving and Renaming Files

Showing the Contents of a File

Saving and Appending Output to a File

Removing a File or Directory

Make a Directory

Make a File

Pipes

Pipes let you chain commands together. They’re represented by |.

If the output of one command could be the input to the next you could use a pipe like command1 | command2.

Programs

SSH

SFTP

Tree

A typical output might look like this:

.
├── folder1
│   └── folder2
│       └── folder3
│           └── folder4
└── test1
    ├── test2
    │   ├── test2.md
    │   └── test3
    │       ├── test.md
    │       ├── test3.md
    │       └── test4
    └── test2.md

But if the structure is deep, like in / or ~, it quickly gets out of hand.

More

Nano Text Editor

nano filename.txt

Word Count

cat filename.txt | wc will show you a word count of the file.

Grep

cat filename.txt | grep keyword will output only the lines in a file that contain ‘keyword’. This appears to be case sensitive.

Gzip and TAR

Gzip will only compress one file, not a folder. For that you need TAR (short for Tape Archive).

A TAR file is an archive, but it is not compressed.

Using the previous TAR command with the -z flag, you can Gzip it at the same time.

To expand a TAR file, you need to do it from a new folder. Otherwise it’ll dump the contents in the current folder. (It seems like if you compressed a folder, though, that it will expand that folder, rather than it’s contents. So unless there’s a folder with the same name in the current directory, you’re alright.)

  1. It seemed more complicated, but in the last 5min of Dan’s video, there was a section on Secure Copy (SCP), which is an alternative to SFTP.

Have a comment? @me on Twitter.