Skip to content

Instantly share code, notes, and snippets.

@CarloCattano
Last active November 30, 2022 10:42
Show Gist options
  • Save CarloCattano/074fd597af3699136b747d3acbb4e069 to your computer and use it in GitHub Desktop.
Save CarloCattano/074fd597af3699136b747d3acbb4e069 to your computer and use it in GitHub Desktop.

find folder recursively

find YOUR_STARTING_DIRECTORY -type d -name "*nameOfFolder*" -print 

locate pip package location

pip show package-name 

repeat command every -n seconds

watch -n 2 commandNameHere

Replace string in file

sed -i 's/old-text/new-text/g' input.txt 

For each

# Print every file name 

for f in *; do echo "Processing $f file.."; done  #can process only certain files as well with *.extension .e.g.-> for f in *.txt

#multple lines for several tasks is more readable
#E.g -> Iterate the files and if a .txt is found, remove it :

    for f in *;do 
      if [ "${f: -4}" == ".txt" ]
      then echo "removing txt file $f" && rm $f
      fi
    done

search for text in files recursively

grep -r keyword * 

remove every .* file recursively

find . -name "*.extension" -type f -delete 

find biggest folders

du -ahx / | sort -rh | head -20

files +100M

find / -xdev -type f -size +100M -exec ls -lha {} \; | sort -nk 5

compress entire folder with zstd

tar --zstd -cf directory.tar.zst directory/

remove zsh history duplicates

cat -n .zsh_history | sort -t ';' -uk2 | sort -nk1 | cut -f2- > .zhistory
@CarloCattano
Copy link
Author

CarloCattano commented May 18, 2022

Terminal Management with tmux

  • Persistent session management (creates session named main and/or attach to it if already running)
tmux new-session -n main
# attach to main session
tmux attach -t main
  • Shortcuts
    Ctrl + B -> arrow left right -> resize current view
    Ctrl + B -> % -> divide view horizontally
    Ctrl + B -> " -> divide vertically
    Ctrl + B -> ; -> go to next window

@CarloCattano
Copy link
Author

CarloCattano commented Nov 22, 2022

set -g default-terminal "screen-256color"

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# Resize the current pane using Alt + direction
bind -n M-k resize-pane -U 3
bind -n M-j resize-pane -D 3
bind -n M-h resize-pane -L 3
bind -n M-l resize-pane -R 3

# reload config file (change file location to your the tmux.conf you want to use)
bind r source-file ~/.config/tmux/tmux.conf

# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'egel/tmux-gruvbox'
set -g @tmux-gruvbox 'dark'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'xamut/tmux-network-bandwidth'

set-option -g status-right "#{network_bandwidth}"

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.config/tmux/plugins/tpm/tpm'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment