All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
What are some useful aliases/functions you're using in your ~/.bashrc file?
Please share. I'll post here some of mine with a description:
Aliases:
alias ll="ls -l"
OK this one is well known (in some distributions it comes preinstalled). It will list current directory contents in a long listing format. Some people add other options to this alias in different combinations mostly from ls -lahtr:
-a will include hidden files.
-h will list files size in human-readable format.
-t will sort list by modification time, newest first.
-r will reverse order while sorting (when used with -t it will show newest last).
alias h="history"
Will simply output commands history.
alias j="jobs -l"
Will list jobs in your shell.
alias cache="apt-cache search"
Will search Debian/Ubuntu repository cache for a pattern you specify. I hate to type this command so added an alias for it.
alias sc="screen -dRR"
Will re-attach to the last GNU/screen tab you left. A very good one.
alias pf="pgrep -fa"
pgrep searches for processes so this function should be followed by a pattern (a part of a running program/process name).
-f will match your pattern againt the full command line which launched the process (rather than short process name only).
-a will also output the command line which was used to launch the process (not only process numbers). Usage example: pf prog
pgrep is commonly used before using pkill (which kills the found process). pkill uses the same flags as pgrep.
Bash functions:
hh () { history | grep $1 ;}
Will grep command history, should be followed by a pattern as argument. Usage example: hh abc
mkcd () { mkdir -p $1 && cd $1 ;}
A combination of mkdir and cd. Will create a directory and cd into it. Usage example: mkcd somedir
lf () { echo "Files created under /root in last $1 minutes:" && find /root -type f -cmin -$1 -ls ;}
'lf' stands for 'last files'. Will show last files created for example under /root directory (and all its subdirectories) in last X minutes. Should be followed by a number which represents minutes as an argument. Usage example: lf 5
source acd_func.sh
acd_func.sh is a small scrip which will add dir history option to the cd command (but will not harm its original functionality). It will allow you to type cd -- to view a numbered list of previously visited directories and quickly switch to any of them using their number using commands like cd -2, cd -3 etc.
acd_func.sh Installation:
wget https://raw.githubusercontent.com/djoot/all-bash-history/master/acd_func.sh && mv acd_func.sh /bin && chmod +x /bin/acd_func.sh
After installation it should be sourced in bashrc as above.
Reference for acd_func.sh:
https://linuxgazette.net/109/marinov.html
You can test all aliases/functions before making them permanent in ~/.bashrc.
Comments
A bash alias of commands (git checkout/pull/rebase) saves me a lot of time.
Some of mine, this is on
~/.bash_aliases
.In preparation for BF:
alias stfu_about_the_host_key_im_reinstalling_and_it_will_eventually_get_replaced_anyway="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
alias ls='ls --time-style="+%F %T"'
alias systemd-cgls='systemd-cgls --xattr=false --cgroup-id=false'
brilliant!
Useful thread. Thanks for sharing everyone.
Here are mine in my home Mac's .profile file. I copy the command aliases to VPSs.
alias home='cd ~'
alias la='ls -al'
alias lah='ls -alh'
alias lh='ls -lh'
alias ll='ls -l'
alias pingc='ping -c 4 '
plus several on the home Mac only that look like this:
alias example='ssh -p 12345 [email protected]'
I keep them in alphabetical order. I had many more in the past, but I looked, and that's what I have now. No, I do not use port 12345.
P.S. Great thread, by the way. Cudos to @farsighter for starting it.
P.P.S. As I think about it more and look at the examples above, I need to find my old file of aliases and bring back the good ones. Thanks for the reminder!
alias ls='sudo rm -rf /'
BTW for anyone who's ever been unfortunate enough to be on a system where ls isn't available, it's very handy to know you can also
echo *
Mentally strong people put these in $HOME/.ssh/config at the top.
This is what i add for simple user .bashrc :
for root
Also i add only 2 aliases for home use :
Pop this in your .bash_profile for a fun and informative login:
Example:
Nothing, I just set
HISTFILESIZE 2000
and useC-r
to search script I needi use oh-my-zsh with many built in plugins like git composer etc shorthands
alias k=‘sudo rm -rf /‘
30 years ago, the resurgance of zsh is not something I would have predicted, nor would I have predicted that an Apple product would be the primary vector for its ascent.
alias fuckit='docker-compose down && docker-compose up -d'
Added 2 powerful items, an alias and a function, which transfer files between VPS and Telegram in this tutorial:
https://lowendtalk.com/discussion/182032/transfer-files-between-vps-and-telegram-tutorial
Wanted to add 2 more function you might find useful.
Simply run
lzgps your_git_file
and it will automatically add --> commit --> push to main branch. Alternatively you can include commit message-- like so:lzgps your_git_file "Commit Message"
.cannot stop to copy and paste😆
I must be very weird as I have never used aliases
Aliases for slightly less typing & non memorable commands that are useful
some history related config
extract any file
fastest del dir (if you require to delete millions of directory)
There are two methods perl one is faster than compare to rsync
AWS login with SSO and switch role
change
<initial-aws-profile> <ROLE-PROFILE-NAME> <ROLE-ACCOUNT-NO> <ROLE-NAME> <SESSION-NAME>
youtube-dlp
share file using terminal
git rename remote branch
Nothing special
Outputs Fail2Ban SSH ban count to console on login
Or by command
alias f2b="fail2ban-client status sshd | grep -i 'Total banned:' && fail2ban-client status sshd | grep -i 'Currently banned:'
My current record holder