GNU Linux/Tips

From WhyAskWhy.org Wiki
< GNU Linux
Revision as of 14:32, 13 July 2012 by Deoren (talk | contribs) (Added some notes on piping content from one system to another)
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.

Audio/Video

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 system2.example.org
cd /home
ssh myaccount@system1.example.org "cd /home && tar cf - myaccount" | tar xf -

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

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

Distribution Specific

Enabling/Disabling Services starting at boot

Red Hat & CentOS

Enable
  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
Disable
sudo /sbin/chkconfig mysqld off


Ubuntu

Enable

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

References