-1

[best practices question]

I'm just getting started with unix - and I find some of the common operations e.g. creating symbolic links ln -s or renaming files mv unintuitive.

I am debating whether to define my own aliases e.g. rename, symlink instead.

Is this a bad idea? why (not)?


Note: I'm not doing sysadmin stuff, and am just using the unix terminal for productivity on my own personal computer.

Clarification: By this I mean defining my own syntax for any unintuitive built in bash command - such that I can understand them better - but it would be exclusive to machines I control (access to my aliases)

  • Welcome, related whats-the-difference-between-rename-and-mv. So, they are different commands, depending the context you would prefer one from another – schrodingerscatcuriosity Feb 18 '21 at 19:31
  • Thanks @schrodigerscatcuriosity. I suppose rename is a bad example as it is a generally recognized command. I am referring to aliases that I personally think are intuitive - but would not be universally available - such as the symlink. Edited the question to reflect this. – Rosabel Marquez Feb 18 '21 at 19:58
  • I think this question is not going to be considered a good question. it's going to be opened for debate. I have a few aliases myself, but not to rename basic commands. You want to learn the basic commands anyway so you can write bash scripts that you share with others. – Alexis Wilke Feb 18 '21 at 19:59

4 Answers4

3

This is definitely an issue of preference. In my opinion, there are more advantages to learning commands outright:

  • Consistency/Reliability - knowing and understanding commands like ln and mv will pay off whenever you are on a new computer. While it will never be hard to go back and find your settings, or duplicate them, or look up what you want, knowing the basic command will always save you a little bit of time. Having access to built in manuals (man mv) will always be a benefit as well. Plus, ln -s is less keystrokes than symlink ;)
  • Learning Cap/Flexibility - if you focus on learning the basic commands, and get comfortable with how they work as commands, it will be easier for you to understand how different flags work, how they chain together, etc. While symlink will be good for making symlinks, if you ever want to make a hard link, or replace an existing file, you will have to use ln anyways. Simply put, your custom aliases are not as flexible as the basic commands.

With those in mind, I would recommend not replacing single commands with aliases. However, there are lots of scenarios where aliased commands make a lot of sense. Some examples:

  • Specific tasks that you perform often - e.g. scp -r /home/user/project/logs user@192.168.1.1~/logs/`date %F`
  • Tasks that string together many commands - e.g. cat /var/logs/websites | grep 502 > /home/user/logs/502

I hope that helps give you some idea about how to maximize the usefulness of aliases! At the end of the day though, it is your decision, and you will learn more about linux/unix through doing than by reading any old stack exchange comment :P Making these aliases and replacing them in a year when you outgrow them is a great way to learn.

  • 1
    In my experience, if the alias gets any more complicated than a single command prefix (like alias ll='ls -l'), you're better off writing a function. Functions make it easier to handle arguments flexibly, and remove any quoting problems. – glenn jackman Feb 18 '21 at 23:13
2

I had a similar problem, when I started.

For me the main problem was remembering the names, and options. If you use them for a while then you will get used to them (with the exception of git).

As for intuition. Commands are not intuitive if you have an incorrect model of what they do.

e.g.

mv does not rename, it moves files to a new directory entry. This could be a new name in the same directory, the same name in a different directory, or a different name in a different directory.

rm dose not delete, it remove directory entries. Files are deleted by a reference counting garbage collector (when no directory entries to the file remain, and file is not open by any process).

Choosing the wrong name for an alias, could make it harder to master, and cause misunderstandings and errors.

1

Simplicity eventually becomes comfortable.

When you spend some time in the terminal (and it is individual), you probably understand how comfortable it is that the most used commands are 2, max 3 letters long. Then you realize that you don't want to bother with typing symlink and you will appreciate the simplicity of typing ln -s. Especially when you talk about , like your question is tagged.

And those names of programs like mv, ls, ln, rm are in fact just shortened words as move, list, link and remove for easier remembering.

It is mnemonics, so when you forget the command for the symlink, you just say you need "link symbolic" and ln -s comes to mind.

In my opinion, aliases become useful if they shorten long commands, not longer short ones.

BlueManCZ
  • 1,753
  • 1
  • 13
  • 31
0

Depends what system you are using. For example, on CentOS 8 you can add global aliases to /etc/profile.d/global_alias.sh that are available each time you SSH in. If the file doesn't exist just create it. You would have to reconnect to have them available in your session, or type them directly on the command line to be active for your current session only. On older versions of CentOS (RHEL) you would put them in the file /root/.bashrc.

Inside the file you can put things like:

alias clear="clear; printf '\033[3J' "
alias logs='cd /var/log/; clear; ll;'
alias edit='nano -w -S -T 4'
alias dirsize='du -h -x --max-depth=1'

I personally would use alias and not create symlinks to give commands different names.

Private_Citizen
  • 104
  • 1
  • 2
  • 8