Last active
January 21, 2025 10:36
-
-
Save AlexRogalskiy/508f55924544cc8d8403bc39ac625419 to your computer and use it in GitHub Desktop.
Alias
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #----------------------------------------------------------------------------------------------------- | |
| # if user is not root, pass all commands via sudo # | |
| if [ $UID -ne 0 ]; then | |
| alias reboot='sudo reboot' | |
| alias update='sudo apt-get upgrade' | |
| fi | |
| #----------------------------------------------------------------------------------------------------- | |
| ### Get os name via uname ### | |
| _myos="$(uname)" | |
| ### add alias as per os using $_myos ### | |
| case $_myos in | |
| Linux) alias foo='/path/to/linux/bin/foo';; | |
| FreeBSD|OpenBSD) alias foo='/path/to/bsd/bin/foo' ;; | |
| SunOS) alias foo='/path/to/sunos/bin/foo' ;; | |
| *) ;; | |
| esac | |
| #----------------------------------------------------------------------------------------------------- | |
| #1: Control ls command output | |
| ## Colorize the ls output ## | |
| alias ls='ls --color=auto' | |
| ## Use a long listing format ## | |
| alias ll='ls -la' | |
| ## Show hidden files ## | |
| alias l.='ls -d .* --color=auto' | |
| #----------------------------------------------------------------------------------------------------- | |
| #2: Control cd command behavior | |
| ## get rid of command not found ## | |
| alias cd..='cd ..' | |
| ## a quick way to get out of current directory ## | |
| alias ..='cd ..' | |
| alias ...='cd ../../../' | |
| alias ....='cd ../../../../' | |
| alias .....='cd ../../../../' | |
| alias .4='cd ../../../../' | |
| alias .5='cd ../../../../..' | |
| #----------------------------------------------------------------------------------------------------- | |
| #3: Control grep command output | |
| ## Colorize the grep command output for ease of use (good for log files)## | |
| alias grep='grep --color=auto' | |
| alias egrep='egrep --color=auto' | |
| alias fgrep='fgrep --color=auto' | |
| #----------------------------------------------------------------------------------------------------- | |
| #4: Start calculator with math support | |
| alias bc='bc -l' | |
| #----------------------------------------------------------------------------------------------------- | |
| #4: Generate sha1 digest | |
| alias sha1='openssl sha1' | |
| #----------------------------------------------------------------------------------------------------- | |
| #5: Create parent directories on demand | |
| alias mkdir='mkdir -pv' | |
| #----------------------------------------------------------------------------------------------------- | |
| #6: Colorize diff output | |
| alias diff='colordiff' | |
| #----------------------------------------------------------------------------------------------------- | |
| #7: Make mount command output pretty and human readable format | |
| alias mount='mount |column -t' | |
| #----------------------------------------------------------------------------------------------------- | |
| #8: Command short cuts to save time | |
| alias h='history' | |
| alias j='jobs -l' | |
| #----------------------------------------------------------------------------------------------------- | |
| #9: Create a new set of commands | |
| alias path='echo -e ${PATH//:/\\n}' | |
| alias now='date +"%T"' | |
| alias nowtime=now | |
| alias nowdate='date +"%d-%m-%Y"' | |
| #----------------------------------------------------------------------------------------------------- | |
| #10: Set vim as default | |
| alias vi=vim | |
| alias svi='sudo vi' | |
| alias vis='vim "+set si"' | |
| alias edit='vim' | |
| #----------------------------------------------------------------------------------------------------- | |
| #11: Control output of networking tool called ping | |
| # Stop after sending count ECHO_REQUEST packets # | |
| alias ping='ping -c 5' | |
| # Do not wait interval 1 second, go fast # | |
| alias fastping='ping -c 100 -s.2' | |
| #----------------------------------------------------------------------------------------------------- | |
| #12: Show open ports | |
| alias ports='netstat -tulanp' | |
| #----------------------------------------------------------------------------------------------------- | |
| #13: Wakeup sleeping servers | |
| ## replace mac with your actual server mac address # | |
| alias wakeupnas01='/usr/bin/wakeonlan 00:11:32:11:15:FC' | |
| alias wakeupnas02='/usr/bin/wakeonlan 00:11:32:11:15:FD' | |
| alias wakeupnas03='/usr/bin/wakeonlan 00:11:32:11:15:FE' | |
| #----------------------------------------------------------------------------------------------------- | |
| #14: Control firewall (iptables) output | |
| ## shortcut for iptables and pass it via sudo# | |
| alias ipt='sudo /sbin/iptables' | |
| # display all rules # | |
| alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers' | |
| alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers' | |
| alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers' | |
| alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers' | |
| alias firewall=iptlist | |
| #----------------------------------------------------------------------------------------------------- | |
| #15: Debug web server / cdn problems with curl | |
| # get web server headers # | |
| alias header='curl -I' | |
| # find out if remote server supports gzip / mod_deflate or not # | |
| alias headerc='curl -I --compress' | |
| #----------------------------------------------------------------------------------------------------- | |
| #16: Add safety nets | |
| # do not delete / or prompt if deleting more than 3 files at a time # | |
| alias rm='rm -I --preserve-root' | |
| # confirmation # | |
| alias mv='mv -i' | |
| alias cp='cp -i' | |
| alias ln='ln -i' | |
| # Parenting changing perms on / # | |
| alias chown='chown --preserve-root' | |
| alias chmod='chmod --preserve-root' | |
| alias chgrp='chgrp --preserve-root' | |
| #----------------------------------------------------------------------------------------------------- | |
| #17: Update Debian Linux server | |
| # distro specific - Debian / Ubuntu and friends # | |
| # install with apt-get | |
| alias apt-get="sudo apt-get" | |
| alias updatey="sudo apt-get --yes" | |
| # update on one command | |
| alias update='sudo apt-get update && sudo apt-get upgrade' | |
| #----------------------------------------------------------------------------------------------------- | |
| #18: Update RHEL / CentOS / Fedora Linux server | |
| ## distrp specifc RHEL/CentOS ## | |
| alias update='yum update' | |
| alias updatey='yum -y update' | |
| #----------------------------------------------------------------------------------------------------- | |
| #19: Tune sudo and su | |
| # become root # | |
| alias root='sudo -i' | |
| alias su='sudo -i' | |
| #----------------------------------------------------------------------------------------------------- | |
| #20: Pass halt/reboot via sudo | |
| # reboot / halt / poweroff | |
| alias reboot='sudo /sbin/reboot' | |
| alias poweroff='sudo /sbin/poweroff' | |
| alias halt='sudo /sbin/halt' | |
| alias shutdown='sudo /sbin/shutdown' | |
| #----------------------------------------------------------------------------------------------------- | |
| #21: Control web servers | |
| # also pass it via sudo so whoever is admin can reload it without calling you # | |
| alias nginxreload='sudo /usr/local/nginx/sbin/nginx -s reload' | |
| alias nginxtest='sudo /usr/local/nginx/sbin/nginx -t' | |
| alias lightyload='sudo /etc/init.d/lighttpd reload' | |
| alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t' | |
| alias httpdreload='sudo /usr/sbin/apachectl -k graceful' | |
| alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS' | |
| #----------------------------------------------------------------------------------------------------- | |
| #22: Alias into our backup stuff | |
| # if cron fails or if you want backup on demand just run these commands # | |
| # again pass it via sudo so whoever is in admin group can start the job # | |
| # Backup scripts # | |
| alias backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type local --taget /raid1/backups' | |
| alias nasbackup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01' | |
| alias s3backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01 --auth /home/scripts/admin/.authdata/amazon.keys' | |
| alias rsnapshothourly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' | |
| alias rsnapshotdaily='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' | |
| alias rsnapshotweekly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' | |
| alias rsnapshotmonthly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' | |
| alias amazonbackup=s3backup | |
| #----------------------------------------------------------------------------------------------------- | |
| #23: Desktop specific – play avi/mp3 files on demand | |
| ## play video files in a current directory ## | |
| # cd ~/Download/movie-name | |
| # playavi or vlc | |
| alias playavi='mplayer *.avi' | |
| alias vlc='vlc *.avi' | |
| # play all music files from the current directory # | |
| alias playwave='for i in *.wav; do mplayer "$i"; done' | |
| alias playogg='for i in *.ogg; do mplayer "$i"; done' | |
| alias playmp3='for i in *.mp3; do mplayer "$i"; done' | |
| # play files from nas devices # | |
| alias nplaywave='for i in /nas/multimedia/wave/*.wav; do mplayer "$i"; done' | |
| alias nplayogg='for i in /nas/multimedia/ogg/*.ogg; do mplayer "$i"; done' | |
| alias nplaymp3='for i in /nas/multimedia/mp3/*.mp3; do mplayer "$i"; done' | |
| # shuffle mp3/ogg etc by default # | |
| alias music='mplayer --shuffle *' | |
| #----------------------------------------------------------------------------------------------------- | |
| #24: Set default interfaces for sys admin related commands | |
| ## All of our servers eth1 is connected to the Internets via vlan / router etc ## | |
| alias dnstop='dnstop -l 5 eth1' | |
| alias vnstat='vnstat -i eth1' | |
| alias iftop='iftop -i eth1' | |
| alias tcpdump='tcpdump -i eth1' | |
| alias ethtool='ethtool eth1' | |
| # work on wlan0 by default # | |
| # Only useful for laptop as all servers are without wireless interface | |
| alias iwconfig='iwconfig wlan0' | |
| #----------------------------------------------------------------------------------------------------- | |
| #25: Get system memory, cpu usage, and gpu memory info quickly | |
| ## pass options to free ## | |
| alias meminfo='free -m -l -t' | |
| ## get top process eating memory | |
| alias psmem='ps auxf | sort -nr -k 4' | |
| alias psmem10='ps auxf | sort -nr -k 4 | head -10' | |
| ## get top process eating cpu ## | |
| alias pscpu='ps auxf | sort -nr -k 3' | |
| alias pscpu10='ps auxf | sort -nr -k 3 | head -10' | |
| ## Get server cpu info ## | |
| alias cpuinfo='lscpu' | |
| ## older system use /proc/cpuinfo ## | |
| ##alias cpuinfo='less /proc/cpuinfo' ## | |
| ## get GPU ram on desktop / laptop## | |
| alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log' | |
| #----------------------------------------------------------------------------------------------------- | |
| #26: Control Home Router | |
| # Reboot my home Linksys WAG160N / WAG54 / WAG320 / WAG120N Router / Gateway from *nix. | |
| alias rebootlinksys="curl -u 'admin:my-super-password' 'http://192.168.1.2/setup.cgi?todo=reboot'" | |
| # Reboot tomato based Asus NT16 wireless bridge | |
| alias reboottomato="ssh [email protected] /sbin/reboot" | |
| #----------------------------------------------------------------------------------------------------- | |
| #27 Resume wget by default | |
| ## this one saved by butt so many times ## | |
| alias wget='wget -c' | |
| #----------------------------------------------------------------------------------------------------- | |
| #28 Use different browser for testing website | |
| ## this one saved by butt so many times ## | |
| alias ff4='/opt/firefox4/firefox' | |
| alias ff13='/opt/firefox13/firefox' | |
| alias chrome='/opt/google/chrome/chrome' | |
| alias opera='/opt/opera/opera' | |
| #default ff | |
| alias ff=ff13 | |
| #my default browser | |
| alias browser=chrome | |
| #----------------------------------------------------------------------------------------------------- | |
| #29: A note about ssh alias | |
| cat ~/.ssh/config | |
| Host server10 | |
| Hostname 1.2.3.4 | |
| IdentityFile ~/backups/.ssh/id_dsa | |
| user foobar | |
| Port 30000 | |
| ForwardX11Trusted yes | |
| TCPKeepAlive yes | |
| $ ssh server10 | |
| #----------------------------------------------------------------------------------------------------- | |
| #30: Miscellaneous | |
| ## set some other defaults ## | |
| alias df='df -H' | |
| alias du='du -ch' | |
| # top is atop, just like vi is vim | |
| alias top='atop' | |
| ## nfsrestart - must be root ## | |
| ## refresh nfs mount / cache etc for Apache ## | |
| alias nfsrestart='sync && sleep 2 && /etc/init.d/httpd stop && umount netapp2:/exports/http && sleep 2 && mount -o rw,sync,rsize=32768,wsize=32768,intr,hard,proto=tcp,fsc natapp2:/exports /http/var/www/html && /etc/init.d/httpd start' | |
| ## Memcached server status ## | |
| alias mcdstats='/usr/bin/memcached-tool 10.10.27.11:11211 stats' | |
| alias mcdshow='/usr/bin/memcached-tool 10.10.27.11:11211 display' | |
| ## quickly flush out memcached server ## | |
| alias flushmcd='echo "flush_all" | nc 10.10.27.11 11211' | |
| ## Remove assets quickly from Akamai / Amazon cdn ## | |
| alias cdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai' | |
| alias amzcdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon' | |
| ## supply list of urls via file or stdin | |
| alias cdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai --stdin' | |
| alias amzcdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon --stdin' | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ls # Показать файлы в текущей директории | |
| ls -la # Показать скрытые файлы и подробную информацию | |
| ls -lh # Читаемый размер файлов | |
| ls -lt # Сортировка по времени изменения | |
| ls -R # Рекурсивный просмотр вложенных директорий | |
| ls /etc # Просмотр содержимого системной директории /etc | |
| ls -lS # Сортировка по размеру файлов | |
| cd /var/log # Переход в системные логи | |
| cd ~/projects # Переход в папку с проектами | |
| cd - # Вернуться в предыдущую директорию | |
| cd .. # Подняться на уровень выше | |
| cd / # Перейти в корневую директорию | |
| cd $(pwd)/new_folder # Переход в новую папку с использованием pwd | |
| pwd # Абсолютный путь к текущему каталогу | |
| realpath . # Альтернативный способ получения полного пути | |
| mkdir new_folder # Создать папку | |
| mkdir -p parent/child # Создать вложенную папку | |
| mkdir -m 777 shared_folder # Создать папку с правами доступа 777 | |
| mkdir -pv a/b/c # Создать цепочку директорий и отобразить процесс | |
| rm file.txt # Удалить файл | |
| rm -r directory # Удалить папку и все её файлы | |
| rm -rf temp_files # Удалить папку без подтверждения | |
| find . -type f -name '*.tmp' -delete # Удалить все временные файлы .tmp | |
| grep 'error' /var/log/syslog # Найти все ошибки в логах | |
| ps aux | grep nginx # Найти процессы nginx | |
| grep -i 'warning' logs.txt # Игнорировать регистр при поиске | |
| grep -v 'info' logs.txt # Исключить строки с "info" | |
| grep -E 'error|fail' logs.txt # Найти строки с "error" или "fail" | |
| awk '{print $1, $3}' access.log # Вывести 1-й и 3-й столбец из access.log | |
| awk '/error/ {print $0}' logfile.log # Вывести строки, содержащие "error" | |
| awk '{sum+=$2} END {print sum}' data.txt # Суммирование второго столбца | |
| sed -i 's/old-text/new-text/g' file.txt # Заменить "old-text" на "new-text" | |
| sed -n '5,10p' file.txt # Вывести строки с 5 по 10 | |
| sed 's/^[ \t]*//g' file.txt # Удалить начальные пробелы и табуляции | |
| ps aux | grep node # Найти процессы, связанные с Node.js | |
| ps -ef # Альтернативный вывод списка процессов | |
| ps aux --sort=-%mem # Сортировка по потреблению памяти | |
| top # Стандартный мониторинг | |
| htop # Улучшенный вариант с цветной графикой (если установлен) | |
| htop -u user # Показать процессы только определенного пользователя | |
| kill -9 1234 # Принудительное завершение процесса с PID 1234 | |
| killall python # Завершить все процессы python | |
| pkill -f 'script.py' # Завершить процесс по имени файла | |
| netstat -tulnp # Список всех прослушиваемых портов | |
| ss -tulnp # Современная альтернатива netstat | |
| ss -s # Краткая статистика сетевых подключений | |
| curl -I https://example.com # Получить заголовки HTTP-ответа | |
| curl -X POST -d "data=value" https://api.example.com # Отправка POST-запроса | |
| wget -O page.html https://example.com # Сохранить страницу в файл | |
| wget -c https://example.com/file.iso # Догрузить файл, если прервалось скачивание | |
| tmux new -s my_session # Создать новую сессию | |
| tmux ls # Просмотреть список сессий | |
| tmux attach -t my_session # Подключиться к сессии | |
| ctrl+b d # Отключиться от сессии, оставив её работающей |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #----------------------------------------------------------------------------------------------------- | |
| #!/bin/bash | |
| _DEBUG="on" | |
| function DEBUG() | |
| { | |
| [ "$_DEBUG" == "on" ] && $@ | |
| } | |
| DEBUG echo 'Reading files' | |
| for i in * | |
| do | |
| grep 'something' $i > /dev/null | |
| [ $? -eq 0 ] && echo "Found in $i file" | |
| done | |
| DEBUG set -x | |
| a=2 | |
| b=3 | |
| c=$(( $a + $b )) | |
| DEBUG set +x | |
| echo "$a + $b = $c" | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- | |
| #----------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment