Unix Shell Commands

Common Unix Commands

Learning basic Unix commands is essential if your using a shell hosting company for your Eggdrop. There are a few rules you should always remember when using the command line interface. Unix is unforgiving, if you delete a file you cannot retrieve it. Unix commands are CASE SENSITIVE. It is recommended your directories and filenames use lower case names for convenience. While there are many Unix commands this tutorial will deal with the most common directives you'll use on a regular basis.
Note: When editing your eggdrop.conf remember to use lowercase filenames for logs files, users files, and such as Eggdrop will create the filename the way you entered it.

Unix Directory Commands
    Navigating Directories
  • cd: The cd commands provides navigation to a desired directory.
    Example:
    cd alone moves up one directory relative to current directory position.
    cd eggdrop (or your directory name) will move to the specified directory.
    cd eggdrop/scripts ( or your directory/sub directory) will move to the specified sub directory within the named main directory.
  • Listing Directories and Files
  • ls: The ls command lists files and folders on your shell.
    Example:
    ls alone lists all the files in current directory.
    ls -l lists all files in the current directory with more information. Known as long.
    ls -a lists all files, including files that are hidden.
  • Copying Files and Directories
  • cp: The cp command is used to copy files to the named directory. Examples:
    cp filename.txt yournewdirectory
    Copies the filename in the current directory to the yournewdirectory directory.
    cp *.txt newdir copies all files ending in .txt into the yournewdirectory directory.
    cp -r /home/yourdirectory/files/* /home/yourdirectory/backup copies all the files, directories, and subdirectories into the the backup directory.
  • Making Directories
  • mkdir creates a new directory.
    Example:
    mkdir yourdirectoryname
  • Move Directories
  • mv moves a file or files to the named directory
    . Examples:
    mv filename.txt newdirectory/ moves the file to the directory newdirectory.
    mv *.ext newdirectory moves all files with the specified file extension to newdirectory.
  • Remove Directories
  • rmdir directoryname removes the directory named. (this command will only remove an empty directory.)
    rm -r directoryname will remove a directory, even if files exist in that directory.
Unix Chmod Command
The chmod command is important. Many scripts and programs require certain file permissions to perform correctly, others are set for security purposes. Chmod is best used from the command line. Most FTP programs have the option to set file permissions via the change attributes option, however mode changes via FTP are server dependant and will vary by provider. It is recommended you use the chmod command via SSH.
File and Directory Permissions
  • There are three levels of file permissions: Read, Write and Execute.
    There are three groups to which you can assign permissions: Owner, User Group and Everyone.
    The command chmod followed by three numbers is used to change file and or folder permissions. The first number is the permission for the Owner, the second for the Group and the third for Everyone.
  • Below are how the levels of permission translate:
  • 0 = --- No permission
  • 1 = --X Execute only
  • 2 = -W- Write only
  • 3 = -WX Write and execute
  • 4 = R-- Read only
  • 5 = R-X Read and execute
  • 6 = RW- Read and write
  • 7 = RWX Read, write and execute
The most common modes you will use:
  • 400 r-------- files (won't let you accidentally erase)
  • 444 r--r--r-- files (lets everyone read)
  • 600 rw------- files (no one else can read or see files)
  • 644 rw-r--r-- files
  • 664 rw-rw-r-- files
  • 666 rw-rw-rw- files
  • 700 rwx------ programs and directories
  • 750 rwxr-x--- programs and directories
  • 755 rwxr-xr-x programs and directories
  • 777 rwxrwxrwx programs and directories
Chmod Usage

chmod numberpermissions filename

  • Examples:
  • chmod 755 public_html (sets mode on the directory public_html)
  • chmod 755 filename.ext (sets the mode on the specified file only)
Unix Compression Decompression Commands

Unix uses the commands below to compress and decompress files or directories.

Decompressing tar or tar.gz archives on your shell:

Use the following commands to decompress each file type.

  • .tar files: tar -xvfz filename.tar
  • .tar.gz files: tar -xvfz filename.tar.gz
Creating tar or tar.gz archives on your shell:

Use the following command to create compressed files on your shell:

  • tar -cvzf filename.tar.gz directory name.
    If you want to create a tarball to backup your eggdrop folder, use would use the following command:
    tar -cvzf images.tar.gz eggdrop
    Archives of individual files can be compressed as well, just replace the directory name in the example with a file name.
Misc Unix Commands

The Unix commands below have a single purpose with no switches. They are listed here for your convenience.

  • clear clears the ssh window of old text
  • exit exits your ssh client
  • kill PID# kills a running process.
    Note: PID# is a numerical value given to each running process on your shell. To locate the pid number use the ps ux command below.
  • ps ux: shows all running processes on the shell with pid numbers.
  • quota: shows your disk space, number of files and more
  • uptime lists the current uptime of your shell
  • vhosts lists the shell providers current lists of vhosts available for that box.
  • pwd: display the current path on your shell. passwd: changes your shell password.
    Usage: type passwd enter old password then new password. Confirm if required.