How to expand shell variables in a text file?

This question has been asked in another thread, and this is the best answer IMO: export LOG_FILE_PATH=/expanded/path/of/the/log/file/../logfile.log cat Text_File.msh | envsubst > Text_File_expanded.msh if on Mac, install gettext first: brew install gettext see: Forcing bash to expand variables in a string loaded from a file

How do I recursively list all directories at a location, breadth-first?

The find command supports -printf option which recognizes a lot of placeholders. One such placeholder is %d which renders the depth of given path, relative to where find started. Therefore you can use following simple one-liner: find -type d -printf ‘%d\t%P\n’ | sort -r -nk1 | cut -f2- It is quite straightforward, and does not … Read more

compare contents of two directories on remote server using unix

You can use rsync with the -n flag to find out if the files are in sync, without actually doing a sync. For example, from server1: rsync -n -avrc /abc/home/sample1/* server2:/abc/home/sample2/ This will print the names of all files (recursive, with the -r flag) that differ between server1:/abc/home/sample1/ and server2:/abc/home/sample2/ rsync used parameters explanation -n, … Read more