bash
Useful Commands
System management
watch -n 0.1 "tail -n 5 log.txt"
echo "demo" 2>&1 | tee log.txt
Disk usage
du -h /some/path
df -hd 2 /some/path
Archiving
tar -zcvf /some/path
tar -zxvf /some/path
Locate a program in the user’s path
which --all python
Lists open files and the corresponding processes
lsof +D /some/path
View and modify terminal settings
tput cols; tput lines
echo $COLUMNS; echo $LINES
stty cols 80 rows 24
tput rmam #disable line wraping
tput smam #enable line wraping
Zsh Regex or on multiple/single characters
tail .(vim|zsh)rc
cat nl wc
grep ag rg
2>&1 | tee
head tail
tr
colrm
expand unexpand
comm cmp diff
fold
paste
bc
split
cut
uniq
sort
join
sed # https://likegeeks.com/sed-linux/
awk # https://likegeeks.com/awk-command/
File-copying
rsync -avP username@hostname:/path/to/source /path/to/destination
Configuration
update bash
mac
brew install bash
sudo mv /bin/bash /bin/bash3.2
sudo ln -s /usr/local/bin/bash /bin/bash
linux
wget http://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz
tar zxvf bash-4.4.tar.gz
cd bash-4.4
./configure
make
make install
After installation, you may change default bash as mac part. However, if you don’t affect other users’ bash, you may specify its installation path as follows.
wget http://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz
tar zxvf bash-4.4.tar.gz
cd bash-4.4
./configure --prefix=<path>
make
make install
After installation, you may change your user’s default shell as follows.
sudo chmod +w /etc/shells
sudo vi /etc/shells # add <path> to this file
sudo chmod -w /etc/shells
chsh -s <path>/bin/bash # change default shell for current user
Or if unfortunately, if you don’t have root permission, you also can set the default shell in tumx as follows.
set-option -g default-shell <path>/bin/bash