this post was submitted on 11 Jul 2023
22 points (92.3% liked)

Linux

48008 readers
874 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I am currently looking for a way to easily store and run commands, usually syncing files between two deeply nested directories whenever I want.

So far I found these projects:

Other solutions:

  • Bash history using ^+r
  • Bash aliases
  • Bash functions

What do you guys use?

top 24 comments
sorted by: hot top controversial new old
[–] [email protected] 14 points 1 year ago

aliases in .bashrc

[–] [email protected] 7 points 1 year ago

If you use fish you can use abbreviations

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago) (1 children)

I wouldn’t install a program for this if your use case is simple. You will end up relying on it when there are already some built in tools that can get you 99% of the way there.

  1. Bash scripts placed in ~/bin or ~/.local/bin
  • Can have simple or complex scripts setup to do whatever you want
  • Easily called from terminal or automated through cron or systemd
  1. Environment variables set in -/.bashrc
  • Great for storing common paths, strings, etc.
  • Can be easily incorporated into bash scripts
  1. Aliases set in ~/.bashrc
  • Ideal (IMO) for common commands with preferred options
  • for example you could setup your most used rsync command to an alias: alias rsync-cust=“rsync -avuP”

Edit: rephrased to not discount the tools shared. I am sure if you had a specific reason to use them they could be helpful. But I think for many users the above options are more than enough and are supported pretty universally.

[–] [email protected] 2 points 1 year ago (1 children)

I more or less was just looking for a general survey of what other people used.

I agree installing a binary for this small kind of thing might be excessive.

[–] [email protected] 1 points 1 year ago

Yeah, potentially overkill, but all the power to anyone who wants to try them out. Freedom of choice is one of the best parts of Linux.

And sorry for the long response. It’s hard to gauge the proficiency that someone might have with Linux, so I tend to lean towards detailed explanations just in case

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)

Obvious things I don't see mentioned:

  • Bash scripts kept in the home directory or another place that's logical for them specifically.
  • history | grep whatever (or other useful piping), though your older commands are forgotten eventually. You can mess with the values of HISTSIZE and HISTFILESIZE environment variables in your system.
[–] [email protected] 3 points 1 year ago (2 children)

I did not know any of the programs mentioned in the post, but some of them seem really nice. Can someone who thinks aliases are a better solution please explain why they think so and what is their advantage over these projects? Do they have any pitfalls that you are aware of?

I believe that if I use a command sparsely enough, I will forget the created alias name just a few days later than the actual command.

[–] [email protected] 1 points 1 year ago

I think that there are definitely valuable/valid use cases for the software in the OP, but I think that the built in bash tools can get most people most of the way there. And learning the common bash/shell conventions is way more valuable than learning a custom tool that some distros/environments won’t support.

If someone already uses aliases, creates some custom scripts, and sets some useful environment variables (along with effective use of piping and redirection) and still needs something more specialized, then getting a new tool could help.

The downsides are a reliance on another piece of software to use the terminal. So I would only use something like this if I had a really solid and specific use case I couldn’t accomplish with what I already use.

[–] [email protected] 1 points 1 year ago

Bash is a shell but it's also a programming language, so between functions, aliases and scripts you can do anything you want without depending on an external program that might break, not be maintained anymore and you need to install everytime you reinstall, a machine.

I just have to restore my .bashrc and ~/bin...

[–] [email protected] 3 points 1 year ago (1 children)

Fish (or zsh with some addons) will give you tab completion based on previous commands, might be something of interest?

Here's some addon tips if you'd rather run zsh instead of fish:

https://gist.github.com/abhigenie92/a907cdf8a474aa6b569ebe89aeee560d

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Fish shell is great, but the more I've used it, the more incompatibilities I've found:

  • Can't use subshells
  • Can't use bash syntax (it would help if bass would process all commands by default)
  • Can't use bash completions (there's a script to do that, but it makes start very slow)

Other than that, it just works by default (unlike zsh) and it works even better with an easy-to-install Tide

[–] [email protected] 1 points 1 year ago

Yeah, it has its downsides. zsh with some addons is probably better overall. Or if you're at least aware of it's differences from bash and can work with that.

[–] [email protected] 3 points 1 year ago

Fish shell. Out of the box it autocompletes taking into account in which directory you are. It's like bash Ctrl+r but without actually invoking it before. Really ergonomic.

[–] [email protected] 2 points 1 year ago

I like bash scripts + auto key! Custom commands with custom keybinds.

[–] [email protected] 2 points 1 year ago (1 children)

I have a file in my ~ called .alias and it is sourced by any shell I might use (currently just zsh) in it are common aliases like s => sudo and "sudo" => "sudo " (just put this as an alias if you use them a lot, you'll thank me when you're trying to use them with sudo)

[–] [email protected] 1 points 1 year ago

I vi as the command line editor, so fetching history commands is quick:

ESC /searchstring

But if it's something really frequent or may benefit from parameters, I usually throw a perl or bash script in /usr/local/bin.

[–] [email protected] 2 points 1 year ago

An alias file is what I’ve found to be the simplest. Just have to add one line to either .zshrc or .bashrc that links to the file. I store the alias file and some custom scripts that a few aliases call in a git repo so it’s literally just a matter of git pull, add one line to the rc file and then close and reopen the terminal and everything is ready to go.

[–] [email protected] 1 points 1 year ago

I use vi as the command line editor, so fetching history commands is quick:

ESC /searchstring

But if it's something really frequent or may benefit from parameters, I usually throw a perl or bash script in /usr/local/bin.

[–] [email protected] 1 points 1 year ago

McFly for better ”ctrl+c”. It also keeps track of what commands you ran in what directory.

https://github.com/cantino/mcfly

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

.zsh aliases to bash functions.

Thanks for the list though, gonna take a look at a few!

[–] [email protected] 1 points 1 year ago

Try fzf. The default hooks will launch fuzzy finders for

  • C-r: history search
  • Alt-c: change directory
  • C-t: fill in argument for a nested path

All seem pretty good for your use case.

[–] [email protected] 1 points 1 year ago

Fish and its search functionality work great for me.

[–] [email protected] 1 points 1 year ago

I'd say aliases and functions are your friends here.

[–] [email protected] 0 points 1 year ago* (last edited 1 year ago)

I use this method from Luke smith for bookmarking.

https://vid.puffyan.us/watch?v=d_11QaTlf1I

I just have another file for commands.

You can use rofi/dmenu/bemenu. I use kickoff though.

load more comments
view more: next ›