alias s='cd ..'
This was enabled by default in some distro, I think it was Mandrake Linux. I learned to use it and now I can't live without it. 's' is always ready to be immediately pressed, and it can even be spammed. export EDITOR=vim
function highlight() {
egrep --color "$1|\$"
}
function mkcd() {
mkdir $1
cd $1
}
function git-cite() {
git log -1 $1 "--pretty=format:%H (\"%s\")%n" | sed -e 's/\([0-f]\{12\}\)[0-f]*/\1/'
}
alias gd='git diff'
alias gpr='git pull --rebase'
(and a bunch of other similar aliases) function gcmr() {
git checkout origin/merge-requests/$1
}
C-r search history and recall (C-R for another match)
C-o run and recall next (C-O next, C-O next, ...)
C-M-/ undo last edit
M-d delete next word
M-backsp delete prev word
C-y paste text deleted by the two above (combined), Emacs's "yank"
M means Meta key, substitute Alt key on a PC.Not really off-topic, these combos facilitate writing fabulous one-liners.
For downloading a single page from a website for offline storage capabilities. A private, quick, and simple alternative to saving information using archive.org.
# go back to the last directory
cd -
# run last command with sudo
sudo !!
# truncate file
> /tmp/file-to-truncate.txt
# show directory size
du -sh my-dir
# refresh output of command every 2 seconds (needs watch command)
watch ls /tmp
# check how long a command takes
time du -sh mydir
Then I also have a neat function for cd ..: function ..() {
for i in $(seq 1 $1); do cd ..; done
}
# cd ..
..
# cd ../../../../
.. 4
#!/bin/bash
# install in /usr/local/bin/nap
if [ -z $1 ]; then
echo "No time provided. Usage: nap [-cl] [minutes]"
exit 2
fi
if [[ $1 == *c ]]; then
echo Cancelling sleep. PIDs \(if any\): `pgrep -f "nap"`
pkill -f "nap"
exit 0
fi
if [[ $1 == *l ]]; then
ps -Af | grep nap
exit 0
fi
time=$(($1 * 60))
echo Sleeping in $1 minutes...
sleep $time && pmset sleepnow&
I wrote this 10+ years ago, still use it every day.
$ set -o vi
Now you can edit the shell command lines (including the history) using vi / vim commands.By default you will be in append mode.
You can press Esc to go back to command mode.
Then you can edit the current command using vi commands, and also go upward in the history using the k command, to edit any previous history line.
When done editing, hit Enter, and the edited command will be executed by the shell.
You can put the above set command in your .profile so that it always works.
$ vi ’grep -l pattern files'
lets you edit with vi, all the files matching that grep pattern.For example, this is useful for editing all files of a project, which contain a particular variable name, in order to change that name to something else everywhere it is used.
The single quotes in the command should actually be backward single quotes, which I don't have on my mobile keyboard right now.
tar fc . | ( cd destination ; tar fx -)
You can use almost the same recipe to copy between host using ssh:
tar fc . | ssh user@host 'cd destination ; tar fx - )'
Tells me when my build or whatever is done so I can so something else while I wait.
caffeinate -d -i -t (math "((7*60)+30)*60")
to prevent my laptop from sleeing for a specific period of time. I usually run it at the beginning of every day.
MY_STR=$(awk -F'/' '{print $2}' <<< "$FROM")
Where -F could be a comma or other delimiter, printing 1-based field index.
du -s * | sort -nr | head
to find the largest subdirectories. (Although 'duc ls' is faster if I have it installed and up to date on that machine.)
emacs $(git grep | cut -d: -f1 | uniq)
$ ^sometihng^something
win