GNU Linux/Tips

From Wiki
< GNU Linux
Revision as of 11:39, 24 July 2012 by Deoren (talk | contribs) (Added notes about properly configuring a hostname)
Jump to: navigation, search

Distribution Independent

Tip/Tricks/Guides that work for any distribution (or at least should).

Output Redirection

  • Save both standard output and error message: >&
  • Save standard output only: > or 1>
  • Save error messages only: 2>

These can be combined, like so:

 gcc test.c 2> error.msg > /dev/null

This saves error messages but tosses standard output

Background and Foreground processes

Putting a command into the background

Example: yum -y update & Output: [1] 21457

This only works when the user is logged on.

Bringing a command into the foreground

Use fg.

Example: fg %1 or fg 21457

Misc: kill %1 nukes it.


Converting video file to sequence of still images

 ffmpeg -i video_file directory/filename.%04d.png

Piping (transferring) contents from one system to another via ssh

Instead of creating an archive on one system and then moving it, you have the option of piping the content through ssh and handling the contents how you choose on the other end. For these examples I'll use System1 and System2 to represent two different systems you want to transfer content between; rsync is another option.

Using tar/ssh to transfer current files from System1 to System2

# Logged into
cd /home
ssh "cd /home && tar cf - myaccount" | tar xf -

Using tar/bzip2/ssh to backup current files from System1 and place on System2

# Logged into
cd /home
tar cf - my_home_dir | bzip2 -z --best |ssh "cd /mnt/backups && cat > my_home_dir-yymmdd.tar.bz2"

Hostname configuration

Sad to say that I was probably improperly configuring system hostnames for years, but it turns out that it's pretty straightforward. Essentially, you configure the unqualified hostname in /etc/hostname and set the full qualified (FQDN) name in /etc/hosts.

cat /etc/hostname


cat /etc/hosts     localhost    node


Distribution Specific

Enabling/Disabling Services starting at boot

Red Hat & CentOS

  1. Find out the name of the service's script from /etc/init.d/ directory. For example, mysqld or httpd [1]
  2. Enable it via chkconfig
    sudo /sbin/chkconfig --add mysqld
  3. Make sure it has been enabled
    sudo /sbin/chkconfig --list mysqld
  4. Set it to autostart
    sudo /sbin/chkconfig mysqld on
sudo /sbin/chkconfig mysqld off



For example, let's say that we would like to set Apache v2.x to start automatically upon system boot.

  1. Get a list of services [2] via service --status-all
  2. We see that apache2 is the correct service name to reference and not apache or httpd.
  3. We set apache2 to auto-start [3] with
    update-rc.d apache2 defaults
  1. Get a list of services [2] via service --status-all
  2. We see that apache2 is the correct service name to reference and not apache or httpd.
  3. We disable apache2 from starting at boot [3] with
    update-rc.d apache2 disable