Truncate files to zero length
This will reduce the filesize of foo
and bar
to 0 bytes:
truncate -s0 foo bar
If the files do not exist they will be created.
You can use this to easily truncate your application's log files:
truncate -s0 log/*.log
Related cards:
Customize tokenization of the MySQL FULLTEXT parser
The way MySQL's FULLTEXT tokenizer splits text into word tokens might not always be what you need. E.g. it splits a word at period characters.
Since the tokenizer has near-zero configuration options (minimum word length and stopwords list), you n...
Solve screen error "Cannot open your terminal '/dev/pts/0' - please check"
When using the screen
tool you may be unable to start a screen session but instead encounter an error:
Cannot open your terminal '/dev/pts/0' - please check.
This is because another user (you) initiated the current terminal -- you probably...
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
.
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...
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...
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 ...
How to send HTTP requests using cURL
-
Reading a URL via GET:
curl http://example.com/
-
Defining any HTTP method (like POST or PUT):
curl http://example.com/users/1 -XPUT
-
Sending data with a request:
curl http://example.com/users -d"first_name=Bruce&last_nam...
How to rotate log files explicitly
Usually, the logrotate
service takes care of renaming log files each night or so to avoid logs becoming huge. That will rename your.log
to your.log.1
, the next time to your.log.2.gz
, etc. Here is how to make that happen out of band (you sh...
How to open files from better_errors with RubyMine on Linux
I recently noticed that better_errors
allows you to to open files from within your favorite editor. However it was not so easy to get rubymine://
links to work ...