Tips tagged bash


4

Tip #201   Store a directory name to come back to

Put the following alias in your profile to store a directory name to use later on:
Read more »

6

Tip #197   Zero files

Zero out files leaving directory and file sets in place - used for archival purposes.
Read more »

10

Tip #196   Manipulate Bash sockets using /dev/tcp

Don't have telnet or netcat handy for making a socket connection? Most Linux distros - not likely Debian - have this functionality built directly into Bash. The following will pull my site's index source on port 80, replace with any URL.

Read more »

10

Tip #195   Bash

These handy one-liners are used to perform the famous Caesar cipher encryption where letters of the alphabet are shifted by differing margins. The same tr command can be used to encrypt and decrypt encoded files/strings.

Rot-13 encryption:
(file)
Read more »

20

Tip #194   Fix the previous command

If, like me, you often make mistakes on the command line, try using the history shortcut '^^' to repeat the last command with changes.

For example:

Read more »

165

Tip #185   CDPATH

This is a little known and very underrated shell variable. CDPATH does for the cd built-in what PATH does for executables. By setting this wisely, you can cut down on the number of key-strokes you enter per day.

For example:
Read more »

18

Tip #181   Remove empty directories

To remove empty directories (even if filenames or dirnames contain spaces or weird characters) from a tree you can do:

Read more »

17

Tip #180   Permanent bash history

Often I find myself using Ctrl-R in Bash to get an old command, only to find that too many days have passed and it's no longer in the .bash_history file.

It is possible to increase the number of lines in the history file, but there can always be a moment when you'll need a long command from many months ago. The solution below uses the PROMPT_COMMAND variable, a command that bash executes before showing each prompt. Here are the two lines to add to your profile:

Read more »

1

Tip #179   Disable bash history

Disable history for a particular account in bash with:

(in home dir)

Read more »

6

Tip #165   Directories and its size

which directories and trees take up all the diskspace?
du -sm $(find /start/dir/* -type d -maxdepth 1 -xdev) | sort -g

If you want more human readable output try:
du -ha /var | sort -n -r | head -n 10

you want to see ALL directories in the tree
find $1 -type d | xargs du -sm | sort -g

To show all directories size including sub directories, type

du -h

To calculate the current directory size you are in (-s stand for summary)

du -sh

To show all the 1 level sub directories size (which you are not interested at sub sub directories.)

du -sh *

To show the size of specific directory

du -sh /home

To show the size of all sub directories of a specific directory

du -sh /home/* Read more »