Trick and Shorcuts For Cli
Trick and Shorcuts For Cli
1. Tab Completion:
• Use the Tab key to autocomplete commands, file names, and directories. It
saves time and reduces errors.
• For example, if you type ‘ec’ and hit ‘tab’ it will complete the command as ‘echo’
2. Command History:
• Utilize the up and down arrow keys to cycle through previously used
commands. History displays a list of recent commands and executes a specific
command by its number.
3. Understanding Commands:
• Use [command] --help to access command manuals and understand their
usage, options, and syntax.
• ls –help will give you all the flags that you can use for the list command.
6. Navigation Shortcuts:
• cd ~ navigates to the home directory, and cd - switches to the previous
directory.
8. File Permissions:
• Understand the chmod command to change file permissions (+x, -r, etc.) and
chown to change ownership.
To check the distribution, look into the os-release. Or simply put ‘cat etc/os-release’
this will show the type of distribution the terminal is using and accordingly use the
commands.
14. xargs.
• xargs is a powerful command used in Linux to build and execute command lines
from standard input. It's particularly useful when you want to convert input
from other commands into arguments for a command that doesn't accept input
directly.
• Example: if you want to copy one file into several locations, you can use xargs.
xargs -n 1 cp -v file.txt <<<”directory1/my_folder/ directory1/recovery/”
15. find
• The find command in Linux is a versatile tool used to search for files and
directories within a filesystem hierarchy. It's powerful and offers various
options to filter results based on criteria like filenames, sizes, modification
times, and more.
Remember if the terminal says that your command is not found, here are the
following reasons:
1. The tool for the running the command is not installed, for example node
code2.js is resulting in command not found then Nodejs is not installed.
2. The distribution might be wrong for example, sudo apt install (this is for ubuntu
Linux) might not always work, check the distribution, if it is Alpine Linux then
you can use sudo apk add.
3. The command may be used on the wrong OS, Microsoft command may vary
from Linux commands.