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:


Change Directory

Directory Listing

Showing the Current Path

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


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 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.





A typical output might look like this:

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

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


Nano Text Editor

nano filename.txt

Word Count

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


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.