Table of Contents

Basic commands for working with Linux

This section covers some very basic commands to efficiently work with a Linux system. They should be available on all standard installations. Although many modern Linux variants offer an advanced GUI, it is advisable to be able to control a Linux system from command line.

Working with Files

Networking Tools

HTTP/FTP

rsync

Example

* This is a script to upload a complete directory recursively (local copy of website to web server). The local directory is gallery, this is also the place where the script resides. The remote username is user and should be replaced by an existing one. Also, the server server.xx and the server directory have to be adapted.

The rsync options used here: -a: keep a lot of attributes (owner, permissions etc.); -z: compress; -v: verbose; -r: recurse into subdirectories; –update: only upload changed or added files; –delete: delete remote files no longer available locally; and finally: –delay-updates: makes rsync postpone all changes until the run is finished, which makes a lot of sense when updating live websites.

If you comment out the second myoption= line and uncomment the first one, the –dry-run option lets you simulate what rsync would do without actually harming anything.

#! /bin/sh
#comment out --dry-run to get it working
#myoption=--dry-run # don't put spaces around the =
myoption= #this resets the variable
echo "--> gallery dir"
rsync -razv --update --delete $myoption --delay-updates gallery user@server.xx:/var/www/de.baz.foo/

Piping

The output of one command can be piped into the input of another command. This is done by the pipe operator |. To search kernel messages for some string, use dmesg | grep string.

Additionally, the STDOUT (1) and STDERR (2) streams can also be redirected. To redirect the STDERR output to STDOUT, use: command 2>&1 …. This can be used in combination with piping.