10 Linux terminal tricks that few people know about

  • 10 Linux terminal tricks that few people know about

    A close acquaintance with the capabilities of the terminal is one of the signs of a person who is well versed in Linux. Although it is difficult to remember some things, there are quite simple but effective techniques that can improve the quality and speed of work in the terminal. Perhaps every Linux user sooner or later gets his own list of valuable little things. We hope that some of the ten Linux command line tricks we want to share with you will be added to your personal list of useful commands.
    No. 1. Go to the previous directory

    We all use the team

    cd ..

    to go to the parent directory. And to go to the previous directory, you can use the command

    cd -

    This technique is similar to the back button.

    test @ linoxide: ~ / Downloads $ cd -
    / home / eyramm
    test @ linoxide: ~ $ cd -
    / home / eyramm / Downloads
    test @ linoxide: ~ / Downloads $

    Here we were first in the Downloads directory, then moved to the Home directory, and finally returned to the Downloads directory.
    No. 2. Repeat last command

    To repeat the previous command, simply enter


    In this example, we will repeat the previous command with superuser privileges.

    $ apt install vlc
    E: Could not open lock file / var / lib / dpkg / lock - open (13: Permission denied)
    E: Unable to lock the administration directory (/ var / lib / dpkg /), are you root?

    $ sudo !!
    sudo apt install vlc
    vlc is already the newest version (2.2.2-5ubuntu0.16.04.3).

    This technique is very useful precisely in situations similar to those considered when the command entered earlier must be executed with superuser rights.
    No. 3. Repeated execution of a command until its successful completion

    In order to execute a command until it is successfully completed, use the command return code in this construction:

    while! [command]; do sleep 1; done

    For instance:

    $ while! ./run.sh; do sleep 1; done
    cat: run.sh: No such file or directory
    cat: run.sh: No such file or directory

    The command in this example will be repeated until a file is found


    and its contents will not be displayed.
    Number 4. View file transfer progress information

    In order to monitor the progress of the file transfer, use the command


    $ pv access.log | gzip> access.log.gz
    611MB 0:00:11 [58.3MB / s] [=>] 15% ETA 0:00:59

    No. 5. Job scheduling

    You can schedule tasks on Linux using the command


    echo wget https://sample.site/test.mp4 | at 2:00 PM

    To view pending tasks, use the command


    No. 6. Table output

    Calling the command


    , or anything else that displays data on the screen, you may encounter long lists, which require long scrolling to view. What is displayed on the screen can easily be organized in the form of a table using the command

    column -t

    For instance:

    $ cat / etc / passwd | column -t

    Command output organized as a table
    Number 7. Useful keyboard shortcuts



    clears the terminal screen. Keyboard shortcut

    Ctrl + L

    allows you to achieve the same thing faster.

    Keyboard shortcut

    Alt +.

    allows you to navigate through previously entered commands. Keyboard shortcut

    Ctrl + U

    removes from the string everything that is already entered into it. For example, you can try this to clear the password entered on the command line.

    Use the keyboard shortcut for incremental reverse search in command history

    Ctrl + R
    Number 8. Compress, split, and encrypt files

    Transferring large files between computers is not an easy task. You can simplify it by compressing files using the command


    , or, if the files are simply very large, creating a multi-volume archive. If you also need to encrypt the files, use the key


    $ zip -re test.zip AdbeRdr11010_en_US.exe run.sh Smart_Switch_pc_setup.exe
    Enter password:
    Verify password:
    adding: AdbeRdr11010_en_US.exe (deflated 0%)
    adding: run.sh (stored 0%)
    adding: Smart_Switch_pc_setup.exe (deflated 2%)

    No. 9. Laptop Battery Stress Test

    Want to see how long your laptop battery lasts at full CPU load? Try the following command:

    $ cat / dev / urandom> / dev / null

    No. 10. Rename or move files

    If you need to quickly rename or move a lot of files with suffixes, try a command of the following form:

    $ cp /home/sample.txt{,-old}

    $ cp /home/sample.txt /home/sample.txt-old

    The following is an example of renaming files with a specific extension in batch mode:

    $ ls

    $ rename 's / comes_here / goes_there /' * .txt
    $ ls

Log in to reply

Login in your account to Start Chat