9 time-saving activities for your command line

9 time saving activities for your command line.jpgsignaturedf985ce021ae65b90c39b79e837bbdef

How do you write good code? To be effective. If you want to create something brilliant, you need to eliminate the time dumps that delay you. With just a few tricks, you can speed up your work and focus on what matters.

Index

    1. Create an alias

    Each shell comes with a file called ~/.bashrc neo ~/.bash_profile. The one you use will depend on your system. This role is explained in detail.

    Now think of commands that you can use extensively. It's hard to print them every time, and you can ruin things if you tend to make typos. That's what it's for aliases: They replace your original command with shortcuts.

    alias $preferredAlias="$commandToAlias"

    For example, I have a Dropbox folder that I need to access frequently. Since I do not like to type too many characters, I have this alias in them ~/.bash_profile:

    alias topbox="cd ~/Dropbox/top-eft/"

    Some other useful aliases are:

    alias mv="mv -i"
    alias cp="cp -i"

    The choice -i indicating that you will be prompted before overwriting a file. If you've ever written over something important without knowing it, you know who I'm talking about.

    If you are using a lot of aliases, it might make sense to create a separate file. Just pack all your aliases in a new file called ~/.bash_aliases. Now you need to tell your original configuration file where the alias is live. For that, add the following lines to the top of your section ~/.bash_profile neo ~/.bashrc:

    if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
    fi

    And you're done!

    Once you have edited your bash file, make sure you run the following two appropriate commands:
    source ~/.bash_profile
    source ~/.bashrc

    That way, you want your system to keep up with your changes from now on. If you open a new window, it will automatically find the file.

    2. Pimp your soon

    Your command line quickly becomes the first thing you see when you start working, and probably the last thing you look at before you leave. So it makes sense to tailor it to your preferences.

    I’m a minimalist, so I only include the current directory of the Tidy. So there I am ~/.bash_profile I specified:
    PS1='[W]$ '
    Here, the W refers to the custom directory, and the speed reference variable is PS1.

    Other popular options are:

    • A time stamp will help you find your work back. Add @ in your file.
    • If you are working on a remote server by adding your username and hostname. Add u and / neo h.
    • You could add the shell and the shell version if it suits your job. Add s and / or v to your file.
    • The $ dollar sign usually marks the end of the incentive.

    You can also print your inspiration in colors. This might help when you are generating a lot of output (or mearachd error messages) and want to see where the program started.

    3. Make the most of your history

    Of course you do not want to type the same commands over and over again. Of course the tab is finished - start typing a command, and then hit tab to finish it automatically. But what if you want to get to your past orders? There are a few options:

    • The up and down arrows allow you to scroll through your recent history.
    • If you want to execute your last command again, type !!.
    • If you want to execute the last command starting with foo, type !foo. Take for example, the last time I used my favorite text editor, I opened my configuration file: vim ~/.bash_profile. Next time, I'll just write !vim.
    • If you want to get to the previous command argument, you can use it !$. Suppose I just opened my configuration file with vim, but for now I want to use another text editor. Then nano !$ that's enough.
    • What if you remember the middle part of a long command, but not the initials? You can find the command using ctrl+R and then typing in the letters you know. Once you have found the command, hit enter As usual.
    • If you want to see the last 500-or-so orders you made, just make history. You can change the number of commands stored in the history to, say, a million entries by adding HISTSIZE=1000000 and HISTFILESIZE=1000000 to align your shells. If you want to erase all of your history, type rm ~/.bash_history.

    4. Use your environment efficiently

    You have already encountered a few environmental variables - PS1, HISTSIZE and HISTFILESIZE. In general, these are variables written in LITERATURE that explain the important features of the system.

    You can access the full list of them with the command given. Another example is (of many). SHELLOPTS. It lists all the programs that will be rolled out when you start your final session. Full documentation of the default variables can be found in the GNU documentation.

    READ  The big starting question on my mind for 2022 - TechCrunch

    5. Profit from shell options
    You can customize your shell in a number of ways with shell options. To display all the options, run the following commands in your terminal:
    bash -O
    bash -o

    The choice -O refers to options specific to the bash shell, while -o referring to all other options.

    In the list displayed, you can also see whether the option is turned on or off. You can change the default setting by adding a line to your configuration file. Some useful examples are:
    # Correct spelling
    shopt -q -s cdspell
    # Cd into directory with only its name
    shopt -s autocd
    # Get immediate notification of background job termination
    set -o notify

    The first option listed here makes the shell stronger than typing errors. The second one saves you from typing cd every time you want to change your directory. And if you have a lot of background jobs running, you might want to find out by adding the third option to your environment file.

    6. Find files by name

    Say you are looking for the file foo.txt, but you do not know where you put it. Then from your home directory, type:
    find . -name foo.txt

    Here, the. stands for the custom working directory, and you specify the filename with the -name option. You can also use wildcards. For example, this command will return all files in txt format:
    find . -name *.txt

    7. Search for files by content

    Say you want every event of bar in foo.txt. Then your friend's grep is:
    grep bar foo.txt

    If you want to scan multiple files, you can add them like this:
    grep bar foo.txt foo2.txt foo3.txt

    And if you want to find a bar in all the files of the dirfoo directory, you can use the recycle mode:
    grep -r bar dirfoo

    For more options, you can check out the manual page. Just hit man grep in your territory.

    8. Deal with a lot of results

    Sometimes you want to grep for something, but the result is too long to print on the screen. That's where piping is with the symbol | come in handy.

    For example, the dirfoo directory contains a thousand files that contain a bar. You may want to sift through the product and select the files that interest you. Then you can type:
    grep -r bar dirfoo | less

    This will show the result in a more boring way. You can then highlight the files you want, and close the presentation by typing q. This will leave your command line interface cluttered.

    You can also use it grep in the indirect way. Say you want to run a program fooprog which produces a lot of produce. But you are only interested in the part bar.

    To make this result more understandable, you may want to add all three lines before each bar event, followed by all five lines. You can then type:
    ./fooprog | grep -B3 -A5 -i bar

    Here, -B3 referring to the three lines before the bar, and -A5 for the next five. This way, you can ensure that you only get meaningful information printed in your territory.

    9. Move around in text

    Did you think your finisher was all about keystrokes? Well, here's one: you can make an alt - click article in the middle of a line in your destination. It's a little clunky, but it's going to be enough to give your friends a good idea.
    What saves you a ton of time, though, are keyboard shortcuts. To begin with, I suggest you start accepting the following:

    • Hop to the beginning of line with ctrl+a.
    • Hop to the end line with ctrl+e.
    • Delete everything from the beginning of the line to the cursor ctrl+u.
    • Delete everything from the cursor to the end of the line with ctrl+k.
    • You can accept other shortcuts using the full list of Apple keyboard shortcuts. It works well on Linux command line, too.
      Of course you can't learn all keyboard shortcuts at once. I recommend starting with a couple or two and then moving on to the next couple once you have mastered the first one.
      Bottom line: Get quick, be amazing.
      You've learned how to customize your finishing machine with aliases, the slick, environment variables and shell options. You can now access its history, filter through many files and navigate to the meaningful parts.
      Coding is an ongoing learning process. It's never too late to be effective!

    Related Posts

    Deja una respuesta

    Tu dirección de correo electrónico no será publicada.

    Subir

    We use cookies to ensure that we give the best user experience on our website. If you continue to use this site we will assume that you agree. More information