- newname=$(ls *.log 2> /dev/null | sed 's/log/bad/' | sort -n ) --> this will list the files ending with .log and send errors to /dev/null. Then substitute the filename from log to bad and sort the files and store the filenames in the CRON_LOG variable. the actual file names will be untouched.
- sed options include: i-> edit files in place. Also, n-> silent output if not using edit file in place.
- Another way of doing the same as 1 is : perl -p -i -e 's///g' *. You can also create a backup using perl -p -i.bak -e 's///g' *. This replaces within the existing file.
- echo ls *|tr [:lower] [:upper] --> translates lower filenames to upper
- ls *.log|tr -d log ---> Deletes log from the filename
- ls file{2,3}*log ---> Only lists files: file2.log and file3.log
- ls *.log|cut -d "." -f1 --> prints out all the file names without the ".log"
- find /home/ -type f -name "*.log"
- newname=$(ls *.bad|cut -d '.' -f1,2,3) and then for z in $newname; do echo $z".log";done ---> the first command truncates .bad from filename abc.2323.gz.bad. The second one traverses through all the newnames and appends .log to them. So, the new filename is now abc.2323.gz.log
Sunday, March 18, 2012
Some interesting Unix commands - PART I
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment