zcat/gzcat works in linux, not on osx. general linux/osx compatibility
You are right. It’s annoying behavior. $ zcat foo.txt.gz zcat: can’t stat: foo.txt.gz (foo.txt.gz.Z): No such file or directory Try this: $ zcat < foo.txt.gz asdfadsf
You are right. It’s annoying behavior. $ zcat foo.txt.gz zcat: can’t stat: foo.txt.gz (foo.txt.gz.Z): No such file or directory Try this: $ zcat < foo.txt.gz asdfadsf
One way would be with sed: mv ‘file’ $(echo ‘file’ | sed -e ‘s/[^A-Za-z0-9._-]/_/g’) Replace file with your filename, of course. This will replace anything that isn’t a letter, number, period, underscore, or dash with an underscore. You can add or remove characters to keep as you like, and/or change the replacement character to anything … Read more
which will search your path for the arguments you supply, it’s found on just about any BSD or SysV UNIX moriarty:~ dave$ which bash true false /bin/bash /usr/bin/true /usr/bin/false
To check for the CVE-2014-6271 vulnerability env x='() { :;}; echo vulnerable’ bash -c “echo this is a test” it should NOT echo back the word vulnerable. To check for the CVE-2014-7169 vulnerability (warning: if yours fails it will make or overwrite a file called /tmp/echo that you can delete after, and need to delete … Read more
Update: 2 more things that have popped up in the comments and in follow-up questions: Using auditd this way will dramatically increase your log volume, especially if the system is heavily in use via commandline. Adjust your log retention policy. Auditd logs on the host where they are created are just as secure as other … Read more
Use a ~/.bash_completion file. From the Bash Completion FAQ: Q. How can I insert my own local completions without having to reinsert them every time you issue a new release? A. Put them in ~/.bash_completion, which is parsed at the end of the main completion script. See also the next question. Q. I author/maintain package … Read more
With Unix you can pipe the output of one program into another. So to filter tail, you can use grep: tail -f path | grep your-search-filter
A trick I use sometimes is to use base64 to encode the commands, and pipe it to bash on the other site: MYCOMMAND=$(base64 -w0 script.sh) ssh user@remotehost “echo $MYCOMMAND | base64 -d | sudo bash” This will encode the script, with any commas, backslashes, quotes and variables inside a safe string, and send it to … Read more
If you read the man page for bash you’ll find the following at the top of the OPTIONS section: All of the single-character shell options documented in the description of the set builtin command can be used as options when the shell is invoked. In addition, bash interprets the following options when it is invoked… … Read more
I generally put something similar to the following at the beginning of every script (especially if it’ll run as a daemon): #!/bin/bash exec 3>&1 4>&2 trap ‘exec 2>&4 1>&3’ 0 1 2 3 exec 1>log.out 2>&1 # Everything below will go to the file ‘log.out’: Explanation: exec 3>&1 4>&2 Saves file descriptors so they can … Read more