Geody Labs

# Main Index: Debian Linux Magic Spells Cheat Sheet (one liners, how to, tips and tricks)

# Shell Commands

Description of a command:
whatis COMMAND

Manual of a command:
apropos KEYWORD # list all manual pages related to the KEYWORD
apropos . | shuf -n 1 | awk '{print$1}' | xargs man # show a random manual page

Return the path of a command:

Return the type of a command:
# Bash builtins (internal commands): alias, bg, bind, break, builtin, case, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, if, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, until, wait, while.
type COMMAND # Get the command type. If it's a file or an alias, it also returns the path to COMMAND.
type -t COMMAND # Get the command type in a single keyword: alias, keyword, function, builtin, file.

List internal commands:
help COMMAND # show information about an internal command

Identify the type of a file:
file -z PATH/ # Attempts to check the file type of files contained inside a compressed file

alias l="ls -laF --color=auto" # create an alias: makes "l" an alias for "ls -laF --color=auto"
alias {helloworld,hellow}="echo 'Hello World'" # define multiple aliases
alias # list all existing aliases
type ALIAS # show the commands associated to the ALIAS
unalias ALIAS # remove an alias (if the alias was defined together with other multiple aliases, the other aliases will be unaffected and remain active)

Repeat last command:

Start a comment (ignore following text):

Do nothing, successfully:

Do nothing, unsuccessfully:

Execute a command multiple times at a given time interval
watch -n 1 date # Execute the command date every second

Conditional execution:
if [[ 1 == 1 ]]; then echo "true"; fi
if [[ 1 == 1 ]]; then echo "true"; else echo "false"; fi

Execute a random command between two:
((RANDOM%2 == 0)) && echo "Yes" || echo "No"
if [[ $((RANDOM % 2)) == 0 ]]; then echo "Yes"; else echo "No"; fi

Find the time required to perform a command line:
# It may useful to compare commands, or parameters of the same command, and see which one is faster.
# The "real" value is the actual elapsed time which is the data you most likely need, while The "user" value shows the time spent by the code in user mode, and the "sys" value shows the time spent by the code in kernel mode.
time (ls) # Shows the time needed to list the current directory

Shell Security

Test to check if your Bash shell is vulnerable to Shellshock (you should only see a dot if your system is not vulnerable): # Shellshock vulnerability: CVE-2014-6271, discovered on 12 September 2014, initially patched and disclosed on 24 September 2014; related vulnerabilities CVE-2014-6277, CVE-2014-6278, CVE-2014-7169, CVE-2014-7186, CVE-2014-7187. env x='() { :;}; echo Bash vulnerable to Shellshock' bash -c 'echo .'

Please DONATE to support the development of Free and Open Source Software (PayPal, Credit Card, Bitcoin, Ether)

Page issued on 25-Sep-2022 04:30 GMT
Copyright (c) 2022 Geody - Legal notices: copyright, privacy policy, disclaimer