Tips tagged bash


10

Tip #91   another solution to #67

For a fix of #67 that is a bit nicer

for support spaces in the arguments just fine, just make sure you quote "$i".

$ touch a

$ touch b\ c

$ for i in *; do ls "$i"; done;

Read more »

5

Tip #94   Overwrite a file with zeroes

Overwrites a file with zeroes.
Put in in your .bashrc or .bash_profile in Mac OS X.

Read more »

13

Tip #95   Bash terminal size

Q: If I resize my xterm while another program is running, why doesn't bash notice the change?
http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)

Bash won't get SIGWINCH if another process is in the foreground.
Enable checkwinsize so that bash will check the terminal size when
it regains control.

Put this in your bash config somewhere (e.g. Gentoo has it in /etc/bash/bashrc):

Read more »

5

Tip #96   Find occurrences of a string in a large code base without firing

A slight improvement to #64 -- drops one grep and adds line numbers

Read more »

106

Tip #139  

Selected Bash Keystrokes:
Ctrl-U - Cuts everything to the left
Ctrl-W - Cuts the word to the left
Ctrl-Y - Pastes what's in the buffer
Ctrl-A - Go to beginning of line
Ctrl-E - Go to end of line Read more »

15

Tip #140   Change extension on a group of files using only bash builtins an

To change the extension on a group of files using only bash builtins and mv:

Read more »

3

Tip #145   swap files

# Swap 2 files/dirs that are in the same dir
# Usage: sw f1 f2
function sw {
f1=$1
f2=$2
if [ "x$f2" = "x" ]; then
echo "Usage: sw file1 file2"
echo " swap name of 2 files"
else
d1=$(dirname $f1)
d2=$(dirname $f2)
if [ "$d1" != "." -o "$d2" != "." ]; then
echo "sw: Can swap only files in current directory"
else
if [ -e "$f1" -a -e "$f2" ]; then
mv $f1 .sw.$f1
mv $f2 $f1
mv .sw.$f1 $f2
else
echo "sw: '$f1' and '$f2' must exist"
fi
fi
fi
} Read more »

14

Tip #147   Find and Grep

Find all files with given name (you can use Bash expansion if you'd like), and Grep for a phrase:
Read more »