Linux Commands

Linux includes a large number of commands for doing system administration tasks from the command line. This article contains a short list commands that every Linux user should know.

This is not an exhaustive list, but it is a good place to get started using the command from the console.

MAN Sections Numbers and Meaning


1: User Executable Programs or Shell Commands

2: System Calls (Functions provided by the Kernel)

3: Library Calls (Functions within program libraries)

4: Devices and Special Files (generally found in /dev)

5: File Formats and Conventions (i.e. /etc/passwd)

6: Games

7: Miscellaneous (includes macro packages and conventions), e.g. man(7), groff(7)

8: System Administration tools and Daemons (requires root)

9: Kernel routines [Non standard]


Tricks:

Tips and Tricks


Creating One-Liners Command (i.e. stringing together commands)


You can use the following options to recall the last command or arguments from the last command.

Utilities


Reference: Process States

D: Uninterruptible sleep, R: Running, S: Sleeping, T: Traced (stopped), Z: Zombie 

File System


Reference: Permission Codes 


Runs commands with arguments suppressing shell function lookup.

Ex: command -v grep

Ex: command -V grep

Displays possible completions depending on the options.

Ex: compgen -v

Specify how arguments are to be completed by Readline.

Ex: complete -p

Sets variable values and attributes.

Ex: declare -p 

Display the list of currently remembered directories.

Note: Works with popd and pushd

Ex: dirs -v

Removes a job from the table of active jobs.

Note: Works with bg command.

Ex: disown <jobID>

Enables and disables builtin shell commands.

Ex: enable -a

Executes arguments as a shell command. 

Note: This is useful when you build dynamic commands via scripts

Ex: cmd="echo"; txt1="Hello, "; txt2="World!"; eval $cmd $txt1 $txt2

Replace the shell with the given command.

Ex: exec > fileName.ext (redirection the output to a files)

Creates an environmental variable 

Ex: export country=USA

Mark a variable or function as read-only, so that it can not be changed

Ex: readonly [-af] [name[=value] ...]

Creates a function, multiple command working together to complete a specific task.

Syntax: functionName() { commandName ; commandName } 

Ex: 

Shift the positional parameters left by N number of times and renames 

Ex: shift [n]


 getopts optstring name [arg]

 jobs [-lnprs] [jobspec ...] or job

 let arg [arg ...]

 local name[=value] ...

 

 select NAME [in WORDS ... ;] do CO

 set [--abefhkmnptuvxBCHP] [-o opti

 shopt [-pqsu] [-o long-option] opt

 suspend [-f]

 test [expr]

 times

 trap [-lp] [arg signal_spec ...]

 typeset [-afFirtx] [-p] name[=valu

 ulimit [-SHacdfilmnpqstuvx] [limit

 umask [-p] [-S] [mode]

 

Networking


User Management


=====

Scripting



Variables Constants


Miscellaneous


Controlled Failures


Login shells 


When you log in to a local system, you loading an interactiveconsole shell (i.e. Bash, Zsh, etc.).  These are shells that accept commands, and have the OS execute them. There are two type of shells interactive which can be logged into, and non-interactive (or non-login) which can't be logged into.

Bash supports the following list of script files (i.e. ~/.bashrc) that are automatically executed when the shell starts (or when you log out):

Login Script Files

~/.bashrc

/etc/profile

~/.bash_profile

~/.bash_login

~/.profile

Logout Script Files

~/.bash_logout

/etc/bash.bash_logout

Input and Output Redirection


By default, shell commands read their input from the STDIN (aka Standard Input stream [0]) and write to the STDOUT (aka Standard Output stream [&1>]), unless there is an error which is written to STDERR (Standard Error stream [&2>]).

The '|' pipe operator, redirects the output of the first command as the input of the second command.

Ex: ls -l | more

The '<' redirects input from another source, other then STDIN.

Ex: sort <(printf "1\n3\n2")

The '>' redirects STDOUT into a file.

Ex: ls -l > fileName.ext

The '&1>' redirects STDOUT into a file.

Ex: ls -l &1> fileName.ext

The '&2>' redirects STDERR into a file.

Ex: ls -l &2> fileName.ext

The '&>' redirects all STDOUT into a file.

Ex: ls -l &> fileName.ext