df does a great job for an overview. But what if I want to set a variable in a shell script to the number of bytes available on a disk? Example: But I just want to return 33333333 (bytes available on /), not the whole df output. Answer Portably: The -P option ensures that df will print output in the
Tag: unix
auto-formating tool for django html template files
Is there a *nix tool (or vim plug-in) that would allow me to automatically format django html template files? Hitting the space bar hundreds of time does not sound like a good use of my time but then neither does leaving some weird formatting that is hard to read. Answer Install vim-jinja2-syntax plugin by putting Glench/Vim-Jinja2-Syntax when installing it with
Possible to combine glob sort w/ alternation in zsh?
Looking for a shell-only[1] way to take this list of dirs: And return it sorted numerically, with the subdirs showing up right after their parent: (*|*/bar)(n) is rejected as a bad pattern, while */{,bar}(n) expands to */(n) ~/bar(n) so the subdirs show up at the end. [1] I need this to be able to work on a wide variety of
In Unix, how to display welcome message if user has logged in from a particular IP (or host)?
I want to display one message if user XYZ has logged in from any IP (or host). Answer Check to see if you have environment variables such as SSH_CLIENT and SSH_CONNECTION set. If so, you can access these from scripts (perl, bash, etc…) to dynamically generate a welcome message. Below, is a simple perl script to extract the IP address
Where is the official documentation for chmod?
I would have expected it to be here in the gnu documentation but it is not. So I Googled it and their were many links but I don’t know which one is the most “official”. For example the first hit is for an Ubuntu distribution, and the second is for a Mac OS X distribution. Answer On a typical Linux
Bash – How to print multi line strings (with ‘n’) using printf
i’m trying to print a multi line strings in printf this way I can’t do the following Is there any other way? Answer Quoting the variable should do the trick. In your example, however, you are getting double newlines.
How to make zsh `run-help` to ignore `sudo` and get help about the following command
Is it possible to customize zsh so that when I type, say, sudo ls and then hit Alt-h to see man page of the command ls. The default behavior of run-help is to show me the man page of the command sudo, instead of ls. Answer Yes, you can. Run the following lines or add them to your .zshrc. from
Can not assign function parameters to local array variable in `Zsh`
I just try to assign parameters of function as local array variable, I tried I got But if I remove local keyword It’s work What is a problem here? How can I keep my array to local variable? Additional information I tried this on bash shell, it’s work well either as local or global variable. Answer In order to make
How to make pipe run sequentially
Specs Don’t think this should make a difference but I’ll include it anyway GNU bash, version 3.2.51 Premise So say i have a pipe with multiple parts, how can I prevent part of the pipe running before the previous part is finished. Example In the below examples I will try to display the issue Output With sleep to show that
find and replace a String in vi editor on linux?
i am trying to replace String with new String in Linux vi editor but getting following error. Answer I’d guess the reason you’re getting that error message is because you intend to replace the string on all lines, not just the current one. In order to search all lines, add a % to your command: