General > General Technical Chat

Linux RM Command Help

(1/5) > >>

nicknails:
I have a machine (linux based) that is running software that creates a lot of backup files (OLD extension) when anything is changed. Right now, there's a file that you load onto a thumb drive, and it copies everything from the machine to the thumb drive (full backup of system). I've modified the code to copy just the backup files (OLD extension) on the machine.

cd $SRC_DIR
find . | grep -E '\.(old0|old1|old2|old3|old4|old5|old6|old7|old8|old9)$' | cpio -vdump --quiet $DATAPATH &> $list

Now that those specific files are backed up, I want to delete them. I'm assuming I can do
find . | grep -E '\.(old0|old1|old2|old3|old4|old5|old6|old7|old8|old9)$' | **RM Command Here**

Can I just to "rm -r"?

I don't think I need the cd $SRC_DIR since it should already be in that directory.

Also, can I just to old* or something to that effect instead of listing them all out?

mag_therm:
It might be necessary to use the following to avoid a query at each file:
yes| rm ...
or rm -f....

I use the following for silent backup of only the files that have changed since last bak:
yes| cp -uvr  /run/media/Me/Mypaths/* /run/media/Me/SeaGate2TB_A/My_bak path/

nctnico:
IIRC find (or a similar command) can be used to delete the files without needing to use rm .

Cerebus:
If that's your complete pattern for files then "rm .old?" would junk them.

eti:
Try this:


--- Code: ---for f in {0..9}; do rm *.old$f; done
--- End code ---

What this is saying, is this: "For every iteration from 0-9..." (that's the part in braces {0..9}) "... remove any file ending with .old0, old1, old2... etc, up to .old9, and when finished, exit"

The part
--- Code: ---for f in {0..9}
--- End code ---
is specifying what the variable "f", subsequently referenced as "$f", will be on the next pass, and the range {0..9} constrains it to that range.

Non-destructive test:

Make a test directory "mkdir test_del" or w/e and enter it, and then do this:


--- Code: ---for f in {0..9}; do touch TEST_FILE.old$f; done
--- End code ---
which generates empty test files with the same extensions as you're working with (Screenshot attached)

Now, staying in this test directory, you may run my command and ensure it works as expected, without risking data loss to the ACTUAL files.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod