Stuff I forget again and again:
Rename files according to their timestamp
This one-liner renames all images in a directory according to their file modification date. The resulting file names have 8 digits with leading zeroes. Note that it does not distinguish file types - it works just for jpg as it is printed here.
i=0; for f in $(ls -lrt | cut -c 52-65); do newname=$(printf %08d $i); echo "mv $f $newname.jpg"; mv $f $newname.jpg; let i=i+1; done
Send mail from command line
echo "mail content" | mail -s "subject" mail@domain.tld
(echo "mail content"; cat somefile.txt} | mail -s "subject" mail@domain.tld
All clear?
What was this || and && again?
if exp; then T; else F; fi
is equal to
exp && T || Fother way round doesn't work :-)$ [ X = xxX ] || echo F && echo T
F
T
}}}
All clear?
Set editing mode
For me the "intiutive" editing mode is as emacs behaves:
Filename of a path only
yields: su
Find biggest subdirectories
Find all subdirectories of the current dir and get size of each of this directories (including children):
find . -type d -maxdepth 1 -exec du -h -s {} ;
Mount ISO image
mount -o loop,ro -t iso9660 image.iso /mnt/iso
Rsync using SSH
rsync -rtvz -e 'ssh -l user' src-dir/ user@host:dest-dir/
Note that the src-dir is the "master" => Rsync will not do any two-way syncs but rather push the contents of src-dir to dest-dir. Therefore, take care not to overwrite any data if you try to build a two-way sync as proposed in some newsgroups or articles! (Rather use unison, see below)
Most importat rsync args are:
- a for archive (=rlptgoD)
- D Devices
- g groups
- l symlinks
- n dry run
- o owners
- p permissions
- r recurse
- t times
- v verbose
unison
Nice mirroring tool available at
http://www.cis.upenn.edu/~bcpierce/unison/ It provides either text or graphical interface for full two-way synchronization of directory trees including conflict resolution and remote operation. And this even without server operation, SSH does the job, very nice!
Spyder whole Webpage
Some people like to point and click, but is that nice or what:
Get server fingerprint
If I am asked by ssh whether a server fingerprint is correct - I first need to have the correct fingerprint. Given the situation I can get hold to a console of the machine in question I really trust - here's how to get the fingerprint (linux machine, pretty much standard config I would say):
ssh-keygen -l -f /etc/ssh/ssh_host_key.pub
ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
HTTP/1.1
How to get a page from a webserver if connected by telnet? I always forget this HTTP/1.1 syntax:
foo@bar > telnet somehost 8080
GET /index.html HTTP/1.1
Host: somehost
(or use HEAD, OPTIONS HTTP commands instead)
Cron
Fields: minute(s) hour(s) day(s) month(s) weekday(s) command(s)
The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to be executed. The following table briefly describes each of the fields.
| Field Value | Description |
|---|
| minute 0-59 | The exact minute that the command sequence executes. |
| hour 0-23 | The hour of the day that the command sequence executes. |
| day 1-31 | The day of the month that the command sequence executes. |
| month 1-12 | The month of the year that the command sequence executes. |
| weekday 0-6 | The day of the week that the command sequence executes. Sunday=0, Monday = 1, Tuesday = 2, and so forth. |
| command | The complete command sequence variable that is to be executed. |
The integer fields can contain patterns like */5 (every five minutes) or 0,8,16 to run at hours 0, 8 and 16.
You may want to specify MAILTO=foo@bar.com as first line in the crontab file to have the output of a cron run mailed to this address.
Output redirection
In order to get all output (stdout and stderr) to a logfile (or /dev/null), redirect e.g. stderr to stdout:
foo-command.sh >> foo-command.log 2>&1
Backup
wget
Most useful: continue canceled downloads: