Chapter Three: Basic bash shell commands
The Bash program uses command-line arguments to modify the type of shell being started
Parameters |
Describe |
-C string |
Read the commands from a string and process them |
-R |
Launch restrictive shell to restrict user activity in default directory |
-I. |
Start the interactive shell, allowing the user to enter |
-S |
Read commands from standard input |
Environment Variables PS1, PS2
PS1: Controlling the default command-line prompt format
PS2: Controlling subsequent command-line prompt formatting
Special characters used in the Bash shell prompt string
Character |
Describe |
\a |
Alarm characters |
\d |
Date in "Sun Moon Year" format |
\e |
ASCII escape character |
\h |
Local Host Name |
\h |
Fully qualified name (FQDN) |
\j |
The number of tasks currently administered by the shell |
\l |
The base name in the Shell's Terminal device name |
\ n |
ASCII line break |
\ r |
ASCII return character |
\s |
The name of the shell |
\ t |
Current time in 24-hour HH:MM:SS format |
\ t |
Current time in 12-hour HH:MM:SS format |
\@ |
Current time in 12-hour AM/PM format |
\u |
User name of the current user |
\v |
Version of Bash shell |
\v |
The release version of the Bash shell |
\w |
Current working directory |
\w |
Base name of the current working directory |
\! |
The location of this command in the bash shell history |
\# |
The position of this command at the current command line |
\$ |
The dollar symbol under the ordinary user, the pound number under the root user |
\nnn |
Characters corresponding to the 8 binary nnn |
\\ |
Reverse Slash |
\[ |
Starts a sequence of control characters |
\] |
End a sequence of control characters |
Linux file system
The first hard drive installed on a Linux PC is the root drive. The root drive contains the core of the virtual directory, and the other directories are created from there
Mount point is the directory in the virtual directory that is used to allocate additional storage devices
Ls
(See the remaining parameters and examples)
Single letter |
Whole word |
Describe |
-A |
--almost-all |
Do not output "." and ".." File |
|
--author |
Author |
-B |
--escape |
Output 8 binary values of non-printable characters |
|
--block-size=size |
Block Size (block count) by size byte |
-B |
--ignore-backups |
Do not list entries with a wavy line (~) in the name (wavy lines are used to represent a copy of the backup) |
-F |
--classify |
Append a file type identifier to an entry |
|
--file-type |
Append a file type identifier only after a partial file type (not an executable file) |
|
--format=word |
Format output as across (cross), commas (comma), horizontal (horizontal), long (long), Single-column (single row), verbose (verbose), or vertical (vertical) |
|
--group-directories-first |
List all directories before the file |
-G |
--no-group |
Long list output format, do not display group name (in a long listing, don ' t print Group names) |
-H |
--human-readable |
Print size |
|
--si |
Same as-H, but binary is 1000 |
-I. |
--inode |
Displays the index value (inode) for each file (see # #) |
-L |
--dereference |
For linked files, display the original file information |
-N |
--numeric-uid-gid |
Displays the UserID and GroupID of the numeric type in place of the name |
-O |
|
The long list output format does not display group information (like-l, but does not list group information) |
-S |
--sort=size |
Sort output by File size |
-U |
--sort=none |
Do not sort the output |
-V |
--sort=version |
Sort by text version |
-X |
|
Output entries by row rather than column |
-X |
--sort=extension |
Sort output by file name extension |
Create file (Touch) (see # #)
Copy file (CP) (see # #)
CP Command Parameters
Parameters |
Describe |
-A |
Archive files and retain their existing properties |
-B |
Create a backup of a target file that already exists, rather than overwrite it |
-D |
Keep |
-F |
Force overwrite the existing target file without prompting |
-I. |
Prompt before overwriting the destination file |
-L |
Create a file link rather than copy a file |
-P |
If possible, keep the file properties |
-R |
Recursively copying files |
-R |
Recursively replicating directories |
-S |
Create a symbolic link rather than copy a file |
-S |
Overwrite the suffix of the default backup file (default = ~) |
-U |
Copy only if the source file is newer than the target file |
-V |
Verbose mode, explaining exactly what happened. |
-X |
Replication only for current file systems |
(See # # #)
Link File (see # # #)
A hard link creates a separate file that contains the information and location of the source file. Referencing a hard-link file is equivalent to referencing a source file
You can only create hard links between files on the same storage medium. You cannot create a hard link between files under different mount points, but you can create a soft link
If you use CP to copy a file that is linked to another source file, the copy is another copy of the source file, not the linked file
You can create a new link to the source file without copying the linked file
You can create multiple links to the same file, but do not create multiple symbolic links to other symbolic link files (this generates a chain of linked files, which is easy to confuse and break down)
Rename file (mv) (see # #, #2)
Delete File (RM) (see # #)
This file is deleted when all hard links to this file are deleted
Soft links point to invalid files after you delete a soft link to a file
Create a directory (mkdir) (see # #)
Delete directory (rmdir) (see # #)
View file Statistics (STAT) (see # #)
View file type (files) (see # #)
View the entire file (cat, more, less) (see #16, #21)
CAT-T: Tab with ^i instead
More
Grammar
More [-s ] [file ...]
-S (Squeeze, squeeze): compresses multiple blank lines into a single
Basic commands |
H |
Display Help information |
<Space>, Z |
Forward one screen |
Q |
Exit program |
|
Advanced Commands |
= |
Show Current line number |
<Return>, S |
Forward line |
D |
Forward (down) half screen |
F |
Forward one screen |
B |
Back one screen |
/pattern |
Search forward specified mode |
/ |
Repeat Last Search |
!command |
Executes the specified shell command |
V |
Start the VI editor with the current file |
. |
Repeat the previous command |
N |
Find in file the overflow matches the content of the specified expression |
‘ |
Jumps to the first content that the specified expression matches to |
Ctrl+l |
Redraw the current screen |
|
View Some files (head, tail) (see #16)
"Linux command line and Shell Scripting Encyclopedia" chapter III study notes