You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Removing files with find, and LVM snapshots

Take an LVM snapshot using a loopback deviceCreate the snapshot
Take a look at the devices in your volume group. First there needs to be sufficient space in the volume group for a snapshot to occur. Check this by typing: vgdisplay and checking for Free PE / Size

Code:

vgdisplay -v

Create a loopback device to use for the snapshot. My volume group is named vg_echo360. I want my snapshot to be 9.9GB in size so I'm creating a loopback device which is 10GB in size.

Now the path /mnt/snapshot_recovery contains the filesystem at a state from when the snapshot was taken.

Remove the snapshot when no longer needed
Be aware that LVM will throw out the snap space if it overflows. Keep an eye on it while changing things with the "lvs" command.

Code:

lvremove /dev/vg_echo360/echo_snapshot1

Do not allow the LVG to allocate data to /dev/loop0 any longer. This sets the PV Status to NOT allocatable.

Code:

pvchange -xn /dev/loop0

Check out the status of /dev/loop0 compared to the other devices.

Code:

vgdisplay -v

Remove the loopback device from the LVG entirely.

Code:

vgreduce vg_echo360 /dev/loop0

See that the device is missing in the following command?

Code:

vgdisplay -v

Now that the device is removed from the LVG you can remove the loopback device from the system entirely.

Code:

losetup -a

/dev/loop0 is the device I want to remove which is using /app/loop.

Code:

losetup -d /dev/loop0
rm /app/loop

FINAL NOTE ON LVM SNAPSHOTS: If you accidentally removed the loopback device before removing it from the LVM that's okay. Just be sure to run the following command on the LVG.

Code:

vgreduce --removemissing vg_echo360

Using find to remove files
Today at work I had to find all raw files a media server archived which were older than 120 days and delete them. They are regular files and have the following two possible extensions: .aac and .h264. So I built a single find command. I first created an LVM snapshot in case I needed to revert changes.

Before running the remove command put the found file names in a temporary file.

Now that all the files are deleted make sure that there aren't any left over.

Code:

du -shc $(cat /tmp/rawfiles) 2> /dev/null

The disk usage should say 0 total used space.

See man find.
OPERATORS section for -o option.
See TESTS subsection in the EXPRESSIONS section of the find man page for the rest of the options.

Another thing to note, when using the -o option is that you have to treat each expression on either side like a completely new find command. It essentially allows you to put two find commands on a single line.