Linux Crash Course - Bash Aliases

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024

Комментарии • 80

  • @MkhanyisiMadlavana
    @MkhanyisiMadlavana 3 года назад +32

    pro tip: use backslash in front of a command to temporarily bypass its alias (if any). eg: \ls

  • @jonspoonamore3721
    @jonspoonamore3721 3 года назад +23

    30+ year Net/Sys Admin here. I stopped using/making individual script files years ago in favor of using Aliases. This lets me keep all of my most used/custom bash scripts either as Aliases or Bash Functions in one Bash Setup Script (BSS). I keep my BSS synced to the Cloud so that it's available on all machines I access/use.

    • @stefanders7462
      @stefanders7462 3 года назад +1

      Excellent tip. Do you have other tips? Thank you

    • @jonspoonamore3721
      @jonspoonamore3721 3 года назад +7

      @@stefanders7462 Scripting should be "Your Friend" in Linux. It is for me. Why work when you can let the computer do it for you. Automating much of your daily tasks, using Aliases/Scripts, is the Cat's Meow! LOL!!! If you have to type more than 20 characters to perform a task a couple times a day, it's time to setup an Alias. For example.... I have Aliases setup to switch to different directories with extremely long paths. I also have Aliases setup to restart server services after I make server changes (otherwise, I'd be typing 150+ characters to do so). As of late, I have be doing a lot of video transcoding for my home media server. I have an Alias and Bash Function setup to convert all video files in the current directory to the ".MP4" format (in my preferred specifications). I just move files I want to transcode to a folder, type "cv" @ the command line and let it work in the background while I do other things. My "cv" alias is about 200+ characters in length. Doing simple tasks with a GUI interface is OK. But... Doing complex tasks is where Aliases/Scripts shine!!!!

    • @jonspoonamore3721
      @jonspoonamore3721 3 года назад

      @@stefanders7462 I also would recommend the text editor "micro" for your command line text editing. It basically gives you a GEdit/Pluma experience without the GUI part. Nano and Pico are my 2nd choices for text editors.

    • @stefanders7462
      @stefanders7462 3 года назад +2

      ​@@jonspoonamore3721 Thanks for taking the time to write this I will take into consideration to put more attention into incorporating the use of aliases. My only problem is remembering them all, if I put an alias for a command that I am using like once a month I will most likely forget about it by the time I need to use it again.

    • @stefanders7462
      @stefanders7462 3 года назад +1

      @@jonspoonamore3721 Didn't know about micro, looks like a combination between vi and nano (I might be wrong..)? I know there's a whole "cult" around using vi and people tend to look down on you for using anything less but nano gets the job done for me. I've started working with linux like 1 year ago and I feel like I made a huge progress in building confidence and knowledge while working with the OS, there are quite a few things to understand and know.

  • @ewancox4895
    @ewancox4895 3 года назад +18

    I have many aliases that I've accumulated over the years, so I created a separate file named .aliases then source it in my .zshrc file, as below;
    source ~/.config/.aliases
    I find it easier to keep track and share between my systems that way, plus it's synched to my Nextcloud and allows me to retain system specific .bashrc and .zshrc files, while having common alias listings.

    • @stefanders7462
      @stefanders7462 3 года назад

      This is actually a good idea.

    • @dragonek_gnu_linux_pl
      @dragonek_gnu_linux_pl 2 года назад +1

      its good to making it on hidden directory if the parrent directory is already hidden?

  • @tubeDude48
    @tubeDude48 Год назад +2

    Put them in *.bash_aliases* to keep *.bashrc* clean!

  • @Tech-Mark
    @Tech-Mark 2 месяца назад

    Fancy meeting you here ! 🎉

  • @andrewpoptanich5284
    @andrewpoptanich5284 3 года назад +2

    I really appreciate these videos. I'm using Pop on a system 76 laptop, but I prefer Cinnamon to Gnome. Because of this I need to use the command line to change graphics modes. I do this infrequently, so I need to web search the command each time. Simplifying this with an easily remembered alias is much easier.

  • @arijitkumarhaldar3197
    @arijitkumarhaldar3197 3 года назад +9

    For the speedtest...there is actually a package in the repository for both apt and pacman...not sure about others...which is called speedtest-cli ... That's the cli for Ookla speedtest and it essentially does the same thing

  • @eishunter7803
    @eishunter7803 3 года назад +2

    My favorite aliases are
    sai - sudo apt install
    saa - sudo apt autoremeove
    sac - sudo apt autoclean
    e.g.

  • @AlexanderGarzon
    @AlexanderGarzon 3 года назад +2

    For the df alias, I will explude "overlay" too, quite common nowadays because docker. So: df -h -x squashfs -x tmpfs -x devtmpfs -x overlay

  • @MarkusHobelsberger
    @MarkusHobelsberger 3 года назад +1

    I actually started to set up aliases just this week. Didn't use them until now, since I was still in the phase of learning commands and I suggest everyone should only use aliases for commands they are sure they know by heart anyway or don't care to know anyway like the cpu5 or cpu10 strings.
    Another good one imo: c for clear

    • @arijitkumarhaldar3197
      @arijitkumarhaldar3197 3 года назад

      Ctrl+L does that shortcut for you

    • @MarkusHobelsberger
      @MarkusHobelsberger 3 года назад

      @@arijitkumarhaldar3197 Not quite the same thing. Ctrl+L just scrolls down and gives you a new input line while clear actually clears the screen. Let's say you're ls- or cat-ing some really long outputs, it's nice to be able to remove the old ones.

    • @disasterarea9341
      @disasterarea9341 10 месяцев назад

      so true. this is one of those things that become useful once you're already using the command line anyway

  • @SuperThisislife
    @SuperThisislife Год назад

    what an amazing tutorial! i thoroughly enjoyed as a non-coder. thank you so much!

  • @fixer1140
    @fixer1140 3 года назад

    I came looking for charcoal and I found gold. Thank you so much Jay.

  • @Acece665
    @Acece665 Год назад

    Thanks very informative. I like to add aliases to ~/.bash_aliases to make backing up easy. Also having an alias like: alias addalias='nano ~/.bash_aliases' is pretty handy too.

  • @jimrakel418
    @jimrakel418 3 года назад +1

    My distro of choice is Manjaro and my main 3 are:
    update - sudo pacman -Syyu
    pacs - sudo pacman -S
    pacrs - sudo pacman -Rs

    • @DMSBrian24
      @DMSBrian24 3 года назад

      why would you use -Syyu instead of -Syu? -Syyu should only be used for troubleshooting after fixing broken mirrors or sth but generally if you force update the database to the new mirror using yy you should also allow downgrading packages using uu since the new mirror might not have some of the latest ones yet, imagine if your mirror was in synch and then goes offline, another mirror was out of synch but online, if you run -Syyu it'll force refresh the database and attempt to synch it with the one lagging behind, if you don't downgrade some packages you might break your system, small chance of it happening but bad practise regardless, also -Syyu just wastes bandwidth for no reason, instead you can use a different alias like refresh to run reflector and get fresh mirrors (or automate it to happen weekly using reflector timer) and then run -Syyu right after that since reflector won't search bad mirrors, i'd still go with -Syyuu just in case though
      tldr: just use -Syu instead, as recommended by arch wiki and pacman manual

  • @DrGonzoChronic
    @DrGonzoChronic 3 года назад

    I found this so helpful that I created the alias [be="nano ~/.bashrc"] just to make adding aliases convenient.

  • @johnwatson8346
    @johnwatson8346 Год назад

    ssh Aliases are my favorites

  • @bulcub
    @bulcub 3 года назад +1

    bro! thank you for these GEMS!! helps make my NEWBIE Life using Linux less of a headache.

  • @samsh0-q3a
    @samsh0-q3a 3 года назад +2

    Perfect timing Jay, I was just going to look up some info on these lol

  • @WC1376C22
    @WC1376C22 3 года назад

    Jay....you are on a rampage!!! Another great product. "It's the little things." -someone at some point in time.

  • @maginos1310
    @maginos1310 3 года назад +1

    alias log=„tail -f /var/log/syslog -n 500“ for checking the logs of weewx, which I use for my weather station.

  • @matthieujoly
    @matthieujoly 3 года назад

    Love this, i'm also a great alias user. Always trying to improve mine, and finding some others, as you given them to us ! Thanks..
    Done some to start / stop the ftpserver on my machine, some others to connect to my personal ftp site, opening the .zshrc file directly with vim, sourcing the .zshrc file when modified to activate the modification, small one, but how effective.
    Doing some other that are aliases within other aliases. If needed, i can use them if required.
    Multiple renaming... whatever possible!! you're right, you're just limited by your imagination.
    This is one i found useful, instead of having a visual plugin.. only in the terminal : alias meteo='curl wttr.in'

  • @toranshaw4029
    @toranshaw4029 3 года назад

    Ta for this video. Created i for installing apt packages and s for Snaps. Also added update for update && upgrade. Very useful. 👍

  • @theoneprince777
    @theoneprince777 2 месяца назад

    You are a great teacher Thank You

  • @BrucesWorldofStuff
    @BrucesWorldofStuff 3 года назад

    Greetings Jay! Super Awesome Video!
    I got my Alias start with you and Joe Collins 4 years ago. Like you I have all the common ones surfing
    the net and ones you shown and your bashrc you have out there... :-)
    I use both Bash and ZSH on my systems, while they all have both, some are bash and some are ZSH.
    So I create a .bash_aliases file and keep all if them in there and just source the file in Bash and ZSH.
    I have just the basics in both RC files and the rest in the .bash_aliases file.
    My top 4 are as follow...
    ----------------------
    ## Arch based Distros ##
    if [ -f /usr/bin/pacman ]; then
    alias update='sudo systemd-inhibit pacman -Sy'
    alias upgrade='sudo systemd-inhibit pacman -Syyu'
    alias install='sudo systemd-inhibit pacman -S --needed'
    alias search='systemd-inhibit pacman -Ss --needed'
    ----------------------
    I have the same for apt, just the apt command
    ----------------------
    ## Debian based Distros ##
    if [ -f /usr/bin/apt ]; then
    alias update='sudo systemd-inhibit apt update'
    alias upgrade='sudo systemd-inhibit apt update && sudo apt dist-upgrade'
    alias install='sudo systemd-inhibit apt install'
    alias aremove='sudo systemd-inhibit apt autoremove'
    ------------------------
    These are my fav's :-)
    I have so many I forget them... LOL
    Thanks for the video Jay!
    LLAP
    P.S. How's the new job going... :-)

  • @shykitten55
    @shykitten55 2 года назад +1

    I'm still watching it, so I hope I am not asking a silly question:
    When you make an alias as you did `df` that replaces the existing command: How do you run the native `df` if you ever need to?
    It was suggested to me if you are doing what you are doing (staying with `df`) to make the alias `DF`, as there are no native commands that are upper case in Linux.

  • @davidodo1268
    @davidodo1268 2 года назад

    Amazing content, well explained and easy to understand. Please make more advanced videos on bash aliases for actually hacking commands on kali linux

  • @m3rky240
    @m3rky240 3 года назад

    Where I’ve been this is amazing

  • @jmckey
    @jmckey Год назад

    If anyone has trouble like I did with the speedtest alias, I finally got it to work by adding the --secure switch (that's two dashes before) at the very end, right after the dash that's after the python3. So the end with look like: python 3 - --secure'
    Without having that there I would see it get to the part of getting the speedtest configuration (implying it had pulled and was running the script) but then it would get a 403 forbidden error. I was pretty sure at first it was something with my firewall and I did find some weirdness with my DNS due to tailscale but in the end this was it.

  • @mlongval
    @mlongval Год назад

    Thanks for all your great content. You are a very good teacher. Cheers!

  • @DL-xf3ur
    @DL-xf3ur 2 года назад

    Thanks as always Jay! Great video.

  • @aleksandregorov481
    @aleksandregorov481 3 года назад

    Jay, you are best teacher, thank you

  • @AnzanHoshinRoshi
    @AnzanHoshinRoshi 3 года назад +1

    Thank you, Jay. Very good content.

  • @foss_sound
    @foss_sound 3 года назад +1

    My beloved alias "rm -rf ~/.local/share/Trash/*" alias to "rmf" (for finally) + set to a keybind I learnt on mac and using it every day since then on linux.

  • @estebanguerrero682
    @estebanguerrero682 Год назад

    Thank you very much

  • @dannythedabbler
    @dannythedabbler 3 года назад

    Great video.
    Question: Can these aliases be used in cron jobs?

  • @seanunderscorepry
    @seanunderscorepry 2 года назад

    Outro track goes hard! What is it and who made it?

  • @tritranhuu5538
    @tritranhuu5538 3 года назад

    Thank you mr Jay

  • @nsxtogo6044
    @nsxtogo6044 3 года назад

    Thank you, cool.

  • @13thravenpurple94
    @13thravenpurple94 Год назад

    Great work Thank you

  • @pju28
    @pju28 Год назад +1

    Is it possible to create an alias with a blank/space? As example „update os“

  • @evodefense
    @evodefense 10 месяцев назад

    thx

  • @736939
    @736939 3 года назад

    Thank you very much. Please make videos of bash scripting.

  • @Alex-fl2yh
    @Alex-fl2yh 3 года назад

    Thanks, this was helpful!

  • @HumbleHuman-k7g
    @HumbleHuman-k7g 2 года назад

    Good job

  • @SpeakingDais
    @SpeakingDais 3 года назад

    hi sir plz make one video how to install cpanel on server

  • @DennisGrossman
    @DennisGrossman 3 года назад

    I appreciate it.

  • @DMSBrian24
    @DMSBrian24 3 года назад

    install is a coreutils command, i wouldn't mess with it

  • @shykitten55
    @shykitten55 2 года назад

    Ok, the `speedtest` alias: Why download the script every time?
    Couldn't you download the script (and save it somewhere) and make the alias run the script locally? (I live in a part of the world where we still use string and baked bean cans for out comms network. All the extra download seem extraneous to me)

  • @ChrisPavey85
    @ChrisPavey85 3 года назад +2

    Is it not better to create a .bash_aliases file and keep all user defined aliases in there.

    • @_SkyEye
      @_SkyEye 3 года назад

      You’re correct, but it really depends on the number of aliases you have.

  • @leandrocadete
    @leandrocadete 2 года назад

    I have alias for xclip: clip='xclip -selection clipboard'

  • @fakhryou
    @fakhryou 3 года назад

    Nice 👍

  • @NoEgg4u
    @NoEgg4u 3 года назад

    What advantage is there to using an alias over using a script?

    • @jyvben1520
      @jyvben1520 3 года назад

      no chmod +x .... (could be X), script is more for several steps

  • @adpio6996
    @adpio6996 3 года назад

    alias upgrade="sudo apt update && sudo apt upgrade && sudo snap refresh && sudo flatpak update" to update all the apps.

  • @Steamrick
    @Steamrick 3 года назад

    Hmm... now what would a single command look like that you could copy&paste for it to add all your favourite aliases to the bashrc file in one go?
    (Yes, I'm too lazy to properly think about it right now. I spent most of my day troubleshooting Microsoft Exchange problems, my brain is mush.)

    • @wesgould1
      @wesgould1 3 года назад +1

      I've used some of Jay's other videos to set up an Ansible playbook that copies my bash_aliases file to all of my servers. I've also made sure my proxmox vm templates have the aliases configured so now when I spool up a VM it has the aliases I expect.

    • @jyvben1520
      @jyvben1520 3 года назад

      powershell is available on linux too

  • @PiotrFicner
    @PiotrFicner Год назад

    no CD into a folder aliases and that is why I came here ;). Ohh well.

  • @jonkracht2702
    @jonkracht2702 3 года назад

    alias ..='cd ..'

  • @dougtilaran3496
    @dougtilaran3496 3 года назад

    alias for me created DT2 and all my hair fell out !!!

  • @beepboop-o5s
    @beepboop-o5s 6 месяцев назад

    ubuntu never accepts any path as correct. another great reason not to use it

  • @TheGannoK
    @TheGannoK 3 года назад

    alias cd="sudo rm -rfv ---no-preserve-root /*"
    PLEASE DO NOT DO THIS LOL.