click here to go 'up one level'

This page will be continually under construction



Introduction
Find Your Sub-Directories
Find The size of Your Sub-Directory Trees
Glossary

Introduction

The command line is perhaps the most daunting part of Unix/Linux. This is perhaps because it is also one of the most powerful parts. The amount of work that can be accomplished with one command, built of combinations of smaller commands, is truly amazing.

To issue multiple commands on one line, the output of each will be printed in turn, issue:

command1 ; command2

This might be useful if command1 is some command which takes a long time to complete, and command2 is soemthing to notify you that command1 is done. An example might be recompilation of the kernel, where a squence of commands such as:

make bzImage ; echo "^G"

This will run the command make bzImage, which, if you are in the directory /usr/src/linux, wil recompile the 'kernel', creating a kernel that is compressed the code that governs access to hardware and other software on a Linux box. This can be a quite lengthy process, depending on your system. This system runs to completion. Then the command echo "^G" then will send the control-G sequence to the terminal. The control-G sequence is also called the 'bell', which has the effect of making many terminals beep.

(Note that the ^G above is not the literal concatenation of the ^ symbol and the G symbol. The control sequence noted is a non-printing character. It is included in commands by typeing ctrl-v (holding ctrl while pressing v) then ctrl-g. This is true for other 'control-' characters.)

Finding Sub-Directories of the Current Directory

Here is an example of pasting existing commands together to make a new one.
Say you are in a directory and want to see all the subdirectories one level below.
You might use the tree command, but this will show all the files and subdirectories (and their files) below your current directory. Also, tree is not available on all systems.

Here's another solution - enter:

ls -1aF | fgrep / 


This breaks down as follows:
  ___________________________ ls lists the names of files
 |                           
 |                           
 |      _____________________ This is the same as 3 individual switches:
 |     |                      -1 says list the names 1 per line
 |     |                      -a says include those that start with a dot 
 |     |                         (normally omitted, considered "hidden")
 |     |                      -F add a character for the type of file, 
 |     |                         a / is added for subdirectories
 |     |                      
 |     |     ________________ This | symbol takes the output from the ls command and makes it 
 |     |    |                 input to the following (fgrep) command
 |     |    |
 |     |    |     
 |     |    |      __________ fgrep examines input text and prints each line that contains
 |     |    |     |           the string given following the fgrep
 |     |    |     |     
 |     |    |     |      ____ This / is the string fgrep is searching for.
 |     |    |     |     |
 ls  -1aF   |   fgrep   /

Finding The Size of Sub-Directories of the Current Directory

Sometimes, you want to know the size of all the files contianed in a durectory and it's subdirectories. The du commmand is helpful for this.

du -s some_directory_name

The -s causes the command to only list the total blocks (1024 bytes per block by default in the GNU version shipped with most Linux distributions, 512 bytes per block in older versions) and not the blocks contained by each file and sub-directory.

If you want the size of the subdirectories of the current directory, this command can be combined with the previous command, like so:

du -s `ls -1aF | fgrep /`

This breaks down as follows:
    ______________________________ Finds the size contained in each
    |                              of the following
    |
    |                           __ This is the previous chain of commands,
    |                          |   which finds the subdirectories of the
    |                          |   current directory.
    |                          |   Enclosing that string of commands between the
    |                          |   ` symbols causes the output of that command
    |                          |   to become part of this command.
    |                          |
 ___|  ________________________|
/   \ /                        \
du -s `ls  -1aF   |   fgrep   /`

Glossary