Recursively remove unnecessary executable-flags
Sometimes files attain executable-flags that they do not need, e.g. when your Windows VM copies them over a Samba share onto your machine.
From inside your Rails project directory call regularly:
geordi remove-executable-flags
Runs chmod -x
on Ruby, HTML, CSS, image, Rake and similar files.
This script is part of our geordi gem on github Show archive.org snapshot .
Related cards:
Shell script to clean up a project directory
Call geordi clean
from a project root to remove unused and unnecessary files inside it.
This script is part of our geordi gem on github. In Geordi > 1.2 you can call geordi clean
.
Removing ANSI color codes from Rails logs
The colors in Rails log files are helpful when watching them but, since they are ANSI color codes like ^[[4;36;1m
, can be annoying when you are reading the logs with a tool that does just prints those control characters (like less
or vim
).
...
Bash Cheat Sheet (standard Emacs mode)
-
Ctrl + R Search commands you entered previously. Press Ctrl + R again to search further back, Ctrl + Shift + R searches forward again.
-
Ctrl + W Deletes from the cursor position to the left.
-
Ctrl + _ _Undo. Yes, this also w...
Bash: How to generate a random number within given boundaries
$RANDOM
on bash returns a random integer between 0 and 32767.
echo $RANDOM
9816
echo $RANDOM
30922
If you want to limit that to a certain maximum, you can just compare against the modulus of that maximum + 1. \
For example, the fo...
Continously run command under bash
Sometimes you want to run a command forever, e.g. to compile a haml to html file on the console. Use this:
$ while(true) do haml index.haml index.html; sleep 1.5; done
How to send a test e-mail from shell
If you want to manually check if e-mail delivery works on a machine by sending an e-mail you can run the following:
mail -s Test someone@example.com < /dev/null
This will send an empty e-mail with "Test" as its subject to `someone@example.com...
List directories ordered by size (with human-readable output)
You know there is the du
command to fetch the disk usage of a directory (“.
” in this example). By default, output is sorted by directory name, not size:
du -h --max-depth=1 .
40K ./a
2.3G ./b
3.1M ./c
500M ./d
2.8G ...
Grep the number of occurences in a file, counting multiple hits per line
Grep prints one line per match. To return the number if matches, use the -c
switch:
grep -c "something" filename
However, if a word appears more than once in a line, it is only counted once.
To count every match, you can use [sed
](http:...
Linux: rename or change extension of multiple files
When you need to bulk rename files you can not call "mv *.foo *.bar
" to change the extension of all .foo
files to bar
(because bash resolves wildcards and replaces them with the list of matched files).
This works on linuxes who use the ...
Find files modified since a given timestamp
If you need to find all files inside a directory that were modified in the last 24 hours you can do this:
find . -mtime 1
You can also refer to another file's timestamp like this:
find . -cnewer other_file
This can be used to check aga...