Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Created March 12, 2024 21:55
Show Gist options
  • Save pkutaj/06605aa6e354433c4cf7c729f18c4010 to your computer and use it in GitHub Desktop.
Save pkutaj/06605aa6e354433c4cf7c729f18c4010 to your computer and use it in GitHub Desktop.
NR Command Description Example
01 . Executes commands from a file. .bashrc (loads the bash configuration file)
02 : Does nothing (useful as a placeholder). true ; echo "This will be printed" (only the second command executes)
03 [ (or test ) Evaluates expressions for conditional statements. [ -f filename ] && echo "File exists" (checks if a file exists)
04 alias Creates or manages aliases (shorter names for commands). alias ll='ls -l' (creates an alias for ls -l)
05 bg Sends a suspended job to the background. bg %1 (sends job number 1 to the background)
06 bind Defines key bindings for specific actions. bind '"\C-p":history -p' (binds Ctrl+P to previous history command)
07 break Exits a loop or switch statement. for i in {1,2,3}; do if [[ $i -eq 2 ]]; then break; fi; done (loops from 1 to 3, breaks on 2)
08 builtin Runs a command as a built-in, even if it's also defined as a function. builtin cd .. (ensures cd is the built-in version)
09 caller Shows the call stack for the current function. function f { caller; } ; f (shows the call hierarchy)
10 cd Changes the current working directory. cd /home/user (changes directory to user's home)
11 command Runs the actual command, bypassing aliases or functions. command ls (runs the original ls command)
12 compgen Generates completion suggestions for arguments. compgen -A file myprogram (provides filename completions for myprogram)
13 complete Defines or displays command completion behavior. complete -f git (enables filename completion for git)
14 continue Skips the rest of the current loop iteration and moves to the next. for i in {1,2,3}; do if [[ $i -eq 2 ]]; then continue; fi; echo $i; done (skips 2 and prints 3)
15 declare Declares and manipulates shell variables. declare -i var=10 (declares var as an integer)
16 dirs Shows a list of previously visited directories. dirs -v (shows timestamps for visited directories)
17 disown Removes a background job from the job list, but lets it continue running. disown %1 (removes job number 1 from the job list)
18 echo Prints text to the standard output. echo Hello, world! (prints the message)
19 enable Enables a previously disabled shell built-in. enable history (enables the history command)
20 eval Evaluates a string as a shell command. eval var="ls -l"; $var (evaluates "ls -l" and executes it)
21 exec Replaces the current shell process with a new process. exec ls -l (replaces the shell with ls -l)
22 exit Terminates the shell. exit 0 (exits the shell with success code 0)
23 export Makes a shell variable available to child processes. export MYVAR="some value" (exports MYVAR to child processes)
24 false Always exits with a non-zero exit code (failure). false && echo "This won't print" (the second command won't run)
25 fc Manipulates the command history. fc -l -5 (lists the last 5 history entries)
26 fg Brings a suspended job to the foreground. fg %1 (brings job number 1 to the foreground)
27 getopts Parses command-line options. while getopts ":hf:" opt; do case $opt in h) echo "help message"; exit 0; ;; f) file="$OPTARG";; esac; done
28 hash Manages the command lookup cache for faster execution. hash (rebuilds the command hash table)
29 help Provides help information for shell commands. help cd (shows help for the cd command)
30 history Displays the command history. history -c (clears the command history)
31 jobs Shows information about background jobs. jobs (lists running and stopped background jobs)
32 kill Sends a signal to a process or job. kill %1 (sends SIGTERM to job number 1)
33 let Performs arithmetic operations on shell variables. let x=5+3 (assigns 8 to variable x)
34 local Declares a variable with local scope (limited to the current shell). local var="value" (creates a variable var only in this shell)
35 logout Exits the shell (same as exit). logout (terminates the shell session)
36 popd Removes the top directory from the directory stack and changes the working directory to it. pushd /tmp ; popd (changes to /tmp then back to previous directory)
37 printf Similar to echo but offers more control over formatting output. printf "Number: %d\n" 10 (prints "Number: 10" with a newline)
38 pushd Saves the current directory on a stack and changes the working directory to a new one. pushd /tmp (changes directory to /tmp and saves the previous directory)
39 pwd Prints the current working directory. pwd (shows the absolute path of the current directory)
40 read Reads input from the standard input and assigns it to a variable. read name ; echo "Hello, $name!" (reads input and greets the user)
41 readonly Makes a variable read-only (cannot be modified). readonly PI=3.14159 (makes PI a constant)
42 return Exits a function and optionally sets a return code. return 0 (exits the function with success code 0)
43 set Manipulates shell settings and arguments. set -x (enables command echoing for debugging)
44 shift Shifts positional parameters to the left. shift 2 (removes the first two positional parameters)
45 shopt Enables or disables shell options. shopt -s histappend (enables appending commands to the history file)
46 source (or .) Reads and executes commands from a file. see .
47 suspend Suspends the current shell process. suspend (sends SIGTSTP to the shell, use fg to resume)
48 test (or [) Evaluates expressions for conditional statements. see [
49 times Reports elapsed time, user CPU time, and system CPU time used by a process. time sleep 5 (measures the time spent sleeping for 5 seconds)
50 trap Sets traps (actions) to be taken upon receiving signals. trap "echo 'Program interrupted' ; exit" SIGINT (runs the command when Ctrl+C is pressed)
51 true Always exits with a zero exit code (success). true ; echo "This will always print" (the second command always executes)
52 type Identifies the type of a shell command. type pwd (shows whether pwd is a builtin, alias, function, or external command)
53 typeset Similar to declare for managing shell variables. typeset -i var (declares var as an integer, same as declare -i var)
54 ulimit Sets or inquires about resource limits. ulimit -n 1024 (sets the open file limit to 1024)
55 umask Sets the file mode creation mask. umask 022 (sets the umas
56 unalias Removes an alias definition. unalias ll (removes the alias for ls -l)
57 unset Undefines a shell variable. unset MYVAR (removes the variable MYVAR)
58 wait Waits for background jobs to finish. wait %1 %2 (waits for job number 1 and 2 to finish)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment