Tag Archives: Bash

How to delete certain lines of text from a file in Bash using sed

“sed -i 1,+2d file_name” deletes starting from line ‘1’ and the next ‘2’ lines, i.e. deletes the first 3 lines

Tagged , , | Leave a comment

How To Find and Delete Files Not Matching MULTIPLE criteria using bash in AIX

“find . ! -name “*.bz2” ! -name “ESPRD*” | xargs rm”  The above command finds all files in the “current” directory excluding those with “*.bz2” extension and those which start with “ESPRD*” and then deletes them all.

Tagged , | Leave a comment

Bash Script To Find and Delete All Files Except Some When the filesystem reaches a specific size

#!/bin/sh # This script checks if the /siebel filesystem reaches the warning limit of free space# And then delete the old logs except those of last 12 hours warninglimit=1572864    # This number is in KB, it’s equal to 1.5 GB,                        … Continue reading

Tagged , | Leave a comment

"Find All EXCEPT" using bash script

find . \( ! -name “hobba*” \) The above command invokes the “find” command asking it to search in the current directory (“.”) and return all files except those starting with the string “hobba”. Note: Take care of the spaces … Continue reading

Tagged , | Leave a comment

Searching for a string inside multiple files and output the name of the files containing that string

find . -name “*” | grep -i ecomm | xargs ls -las | grep “Aug 27” | awk ‘{print $10}’ | xargs grep -i string_to_search_for | grep -i “\.log” | awk ‘{print $1}’ where: “ecomm” is part of the name … Continue reading

Tagged , | Leave a comment