I have this code, which has to find all .txt files and remove them
#!/bin/bash
find /home/user_name -name "*.txt" | xargs rm
Is it correct ? How can I archive folder after that ?
I have this code, which has to find all .txt files and remove them
#!/bin/bash
find /home/user_name -name "*.txt" | xargs rm
Is it correct ? How can I archive folder after that ?
#!/bin/bash
find /home/user_name -type f -name "*.txt" -exec rm {} \;
# for your specific use case, you could also do
# find /home/user_name -type f -name "*.txt" -delete
# as @hek2mgl pointed out.
# You can have a more restricted search by using -type f
# You can archive the folder using the zip command like below
zip -r user_name.zip /home/user_name
Note: Read the manpage of zip
to see the usage of -r
parameter