Command Line
Command Line

Command Line

username@system name: current directory $
~ user home directory, /home/username
command options arguments

LS

-l long listing - permissions, owner, group, hard links, timestamp, filename
-r reverse list
-h human-readable file sizes, by default in bytes

History

!number of previous command or history number
!! most recent command
!comand most recent of specifc command
variable1='Something’
echo $variable1
The export command is used to turn a local variable into an environment variable.
Exported variables can be removed using the unset command:
 
which command - displays full path
alias name=command
 
function_name ()
{
commands
}
 
Double quotes stop the shell from interpreting some metacharacters (special characters), including glob characters.
Single quotes prevent the shell from doing any interpreting of special characters, including globs, variables, command substitution and other metacharacters
use a backslash \ character in front of the dollar sign $ character to prevent the shell from interpreting it.
Backquotes, or backticks, are used to specify a command within a command, a process called command substitution.
The semicolon ; character can be used to run multiple commands, one after the other. Each command runs independently and consecutively; regardless of the result of the first command, the second command runs once the first has completed, then the third and so on.
The double ampersand && acts as a logical "and"; if the first command is successful, then the second command will also run. If the first command fails, then the second command will not run.
With the double pipe, if the first command runs successfully, the second command is skipped; if the first command fails, then the second command is run.

MAN

NAME - Provides the name of the command and a very brief description.
SYNOPSIS - Provides examples of how the command is executed.
The square brackets [ ] are used to indicate that this feature is not required to run the command.
DESCRIPTION - Provides a more detailed description of the command
OPTIONS - Lists the options for the command as well as a description of how they are used.
FILES - Lists the files that are associated with the command as well as a description of how they are used.
AUTHOR - Provides the name of the person who created the man page and (sometimes) how to contact the person.
REPORTING BUGS - Provides details on how to report problems with the command.
COPYRIGHT - Provides basic copyright information.
SEE ALSO - Provides you with an idea of where you can find additional information. This often includes other commands that are related to this command.
 
To search a man page for a term, type the / character followed by a search term, then hit the Enter key. The program searches from the current location down towards the bottom of the page to try to locate and highlight the term.
If a match is found, it will be highlighted. To move to the next match of the term, press n. To return to a previous match of the term, press Shift+N. If the term is not found, or upon reaching the end of the matches, the program will report Pattern not found (press Return).

Glob character

* zero or more of any character
? character represents any single character. Each question mark character matches exactly one character
[] characters are used to match a single character by representing a range of characters that are possible match characters.
! character is used in conjunction with the square brackets to negate a range.

Archiving and compression

tar - tape archive
create, extract, list
-c create
-f ARCHIVE use archive file
-z compress/decompress using gzip
-j compress/decompress using bzip2
-t list files in an archive
-x extract
-v verbose
The de facto archiving utility in Microsoft is the ZIP file. ZIP is not as prevalent in Linux but is well supported by the zip and unzip commands.

Pager

less
spacebar - window forward
B - windows backward
Enter - line forward
Q - Exit
H - Help
/ search - n next
? search backward
head / tail. -number or -n number
nl number lines
sort
-t field delimiter
-k field number to sort on
-n numeric sort
wc
-l number of lines
-w number of words
-c number of bytes