Check These Out
Sometimes when copying files from one place to another, the timestamps get lost. Maybe you forgot to add a flag to preserve timestamps in your copy command. You're sure the files are exactly the same in both locations, but the timestamps of the files in the new home are wrong and you need them to match the source.
Using this command, you will get a shell script (/tmp/retime.sh) than you can move to the new location and just execute - it will change the timestamps on all the files and directories to their previous values. Make sure you're in the right directory when you launch it, otherwise all the touch commands will create new zero-length files with those names. Since find's output includes "." it will also change the timestamp of the current directory.
Ideally rsync would be the way to handle this - since it only sends changes by default, there would be relatively little network traffic resulting. But rsync has to read the entire file contents on both sides to be sure no bytes have changed, potentially causing a huge amount of local disk I/O on each side. This could be a problem if your files are large. My approach avoids all the comparison I/O. I've seen comments that rsync with the "--size-only" and "--times" options should do this also, but it didn't seem to do what I wanted in my test. With my approach you can review/edit the output commands before running them, so you can tell exactly what will happen.
The "tee" command both displays the output on the screen for your review, AND saves it to the file /tmp/retime.sh.
Credit: got this idea from Stone's answer at http://serverfault.com/questions/344731/rsync-copying-over-timestamps-only?rq=1, and combined it into one line.
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"
I often need to extract a function from a bash script and this command will do it.
This command will sort the contents of FILENAME by redirecting the output to individual .txt files in which 3rd column will be used for sorting. If FILENAME contents are as follows:
foo foo A foo
bar bar B bar
lorem ipsum A lorem
Then two files called A.txt and B.txt will be created and their contents will be:
A.txt
foo foo A foo
lorem ipsum A lorem
and B.txt will be
bar bar B bar
tail -c 1 "$1" returns the last byte in the file.
Command substitution deletes any trailing newlines, so if the file ended in a newline $(tail -c 1 "$1") is now empty, and the -z test succeeds.
However, $a will also be empty for an empty file, so we add -s "$1" to check that the file has a size greater than zero.
Finally, -f "$1" checks that the file is a regular file -- not a directory or a socket, etc.
rpm, sometimes, is not wildcard friendly. To search files installed from package this could be useful.
change PACKAGENAME to any package do you want to search
A little bit smaller, faster and should handle files with special characters in the name.