Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

UNIX Quick Start Guide


May 23, 2021 UNIX Getting started


Table of contents


Unix Quick Start Guide

What is Unix?

A UNIX operating system is a set of scenarios that act as a link between a computer and a user.

  • UNIX was originally developed in 1969 at Bell Labs, which included Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna.

  • There are various Unix variants on the market. /b10> Unix's Solaris, AIX, HP Unix and BSD are some examples. /b11> Linux is unix's same taste which is provided free of charge.

  • Several people can use UNIX computers at the same time; /b10> UNIX is therefore known as a multi-user system.

  • Users can also run multiple programs at the same time; /b10> UNIX is therefore known as multitasth.

Sign in to Unix

You can log on to the sign-in command using the system as follows-

login : amrood
amrood's password:
Last login: Sun Jun 14 09:32:32 2009 from 62.61.164.73
$

Cancellation

When you finish your session, you need to exit the system to make sure no one else accesses your files while masquerading as you.

To log off

  1. Simply type Out command at the command prompt and everything will be cleaned up and disconnected

File management

There are three basic types of files in UNIX -

  1. List of normal files: An ordinary file is a file that contains data, text, or program instructions on the system. /b20> In this tutorial, you look at the work with normal files.

  2. Directory: The directory stores both special and normal files. /b20> For users familiar with Windows or Mac OS, the UNIX directory is equivalent to a folder.

  3. Special files: Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. /b20> Other special files are similar to alias or shortcuts, allowing you to access a file with a different name.

The file name is replaced

Command Describe
ls - [L] The list file is in the current directory
ls - [L] List hidden files
The home directory
〜user Another user's home directory
A foreign card that matches a single character
* Foreign card, multiple characters match

The file name action

Command Describe
Cat file name
Displays the contents of the file
cp source file path Copy the source file to the destination
mv Old name New name Move (rename) using oldName for newame.
rm file name Delete (delete) the file name
chmod NNN file name Change permissions
Touch file name Change the modification time
ln s old file name New file name Created using oldName soft links
ls -F Displays information about the file type.

Directory management

Command Describe
mkdir directory name Create a new directory directory name
rmdir directory name Delete the existing directory as long as it is empty.
Cd directory name Change the directory to the directory name
cd - Switch to the last working directory.
cd〜 Switch to the home directory
Pwd Displays the current working directory.

Environment settings

When you type any command under the command prompt, the shell has a positioning command that can be executed before. /b20> The PATH variable specifies where the command should be found in the shell.

PS1 and PS2 change

The shell display is stored as a command prompt in the character of the variable PS1.

When you issue a command that is incomplete, the shell displays a prompt for a follow-up, waiting for you to complete the command and hit the input again. The default secondary prompt is greater than the sign, but can be changed by redefining the PS2 shell variable -

Escape characters

Escape sequence Describe
\t The current time, expressed as HH:MM:SS.
\d The current date, which is expressed as the work day and month day
\n The new team.
\s The current shell environment.
\W The working directory.
\w The full path to the working directory.
\u The current userna name of user.s.
\h The host name of the machine is currently.
\# The command number of the current command. /b10> As each new command increases the input.
\$ If the valid UID is 0 (that is, if you log in as root), end the prompt with the character; /b10> Otherwise, $is used.

Environment variables

The following is a partial list of important environmental variables. These variables will be set and accessed as described above -

Variable Describe
DISPLAY Contains identifiers for the X11 program that should be used by default for the monitor.
HOME Represents the current user's home directory: For the default parameters in the built-in command disc.
Ifs Indicates that the word splits the internal field separator after the parser used is inflated.
Lang LANG extends to the default system locale; /b10> LC_ALL can be used for overlaying. /b11> For example, if its value is PT_BR, then set the language to (Brazil), Portuguese, and the language environment to Brazil.
LD_LIBRARY_PATH When a dynamic link to many Unix systems contains process images established after Exec, the dynamic link program should search for a colon-separated list of shared object directories before searching in any other directory.
PATH Indicates the search path for the command. /b10> This is a colon-separated list of commands that look like shells in the catalog.
Pwd Refers to the current working directory as set by the cd command.
RANDOM Generates random integers between time 0 and 32,767 per reference.
SHLVL One of the increments at the start of each bash instance. /b10> This variable is useful for determining whether the built-in exit command ends the current session.
TERM Refers to the display type
TZ Refers to the time zone. /b10> It can be like numerical GMT, AST, etc.
Uid Extends the digital user ID of the current user to initiate initialization in the shell.

Filters and pipes

Command Describe
WC [-l] Word/line count
tail [-n] Show n lines from the last n lines of the file
sort [-n] Sort the rows

pr -t

Multiple columns of output
Grep "mode" file name Search uses grep mode
pg or more The contents of the peddle file are displayed.

Special variables

Variable Describe
$0 The file name of the current script.
$n These variables correspond to parameters that are called with a script. /b10> The n here is the positive ad order corresponding to the position of a parameter (the first argument is $1, the second argument is $2, and so on).
$# The number of parameters supplied to the script.
$* All parameters are double quotes. /b10> If the script receives two parameters, $ is equal to $1 $2.
$@ All parameters are quoted separately. /b10> If the script receives two parameters, $ is equivalent to $1 $2.
$? The exit state of the last command is executed.
$$ The current shell's process number. /b10> For shell scripts, this is the process ID they are executing.
$! The process number of the last background command.

The basic operation of Shell

Arithmetic operator

Suppose the variable contains 10 and variable b holds 20 words -

The operator Describe Cases
+ Also - values will be valued on both sides of the operator '$ EXPR A plus $B' will give 30
- Subtract - Subtract the operation of the right hand from the left hand 'Expr's dollar - $B' will give -10
* Multiplication - Multiply the values of either side of the operator 'EXPR $ A - $B' will be given 200
/ Division - operated by the right-hand operator divided by the left-handed operation 'EXPR $ B / $' will give 2
Mode - operated by the right-hand operator and the remaining proceeds divided by the left-handed operation 'EXPR $ B $%A' will give 0
= Assignment - Operates to the right of the assignment left operator The B value that will be allocated by a
== Equality - Compare two numbers and return true if both are the same. The return of the false will be returned.
!= There is no equality - compare two numbers and return true if the two are different. [$ A! The true is returned.

The relationship operator

Suppose the variable contains 10 and variable b holds 20 words -

The operator Describe Cases
-eq Check that the values of the two operasts are equal or not, and if so, the condition is true. It is incorrect that the .$ A $ -eq B is incorrect.
-ne Check if the values of the two operasts are equal or not, and if the values are not equal, the condition becomes true. ($one-ne$B) is real.
-gt Check that the value of the left operance is greater than the value of the right operast? It is incorrect that the .$ A $ -gt B is incorrect.
-lt Check that the value of the left operanzo is less than the value of the right operans, and if so, the condition is true. It's true.
-ge Check that the value of the left operance is greater than or equal to the value of the number of operations on the right, and if so, the condition is true. It's not true that the .$ A$ -ge B is incorrect.
-le Check that the value of the left operance is less than or equal to the value of the number of operations on the right, and if so, the condition is true. One-le$B is real.

Boolean operator

Suppose the variable contains 10 and variable b holds 20 words -

The operator Describe Cases
This is a logical negation. /b10> This reversal condition is true or false, and vice versa. [! /b10> False is true.
-o This is logic or. /b10> If an operance is true, the situation will be true. a -lt 20 -o $ B -gt 100) is real.
-a This is logic and. /b10> If the two operasts are true, then the situation will be true, otherwise it will be wrong. a -lt 20 -a $ B -gt 100 is false.

String operator

Assuming that the variable holds "ABC" and variable b holds "EFG", then -

The operator Describe Cases
= Check that the values of the two operasts are equal or not, and if so, the condition is true. It is incorrect to have a "$one" .
!= Check if the values of the two operasts are equal or not, and if the values are not equal, the condition becomes true. [$ A! The . .
-z Check that the given string operanoper size is zero. /b10> If the length is zero, true is returned. It's not true.
-n Check if the number of operations of a given string is non-zero. /b10> If it is non-zero length, it returns true. It's not a fake.
Str Check that the str is an empty string. /b10> If empty, the false is returned. ($ A) is not fake.

The file test operator

Suppose a variable file holds an existing file name "Test" that is 100 bytes in size and has read, write, and execute permissions-

The operator Describe Cases
-b fiel The check file is a special block file, and if so, the condition is true. The (-b$ file) is false.
-c fiel The check file is a special character file, and if so, the condition is true. The (-C$ file) is a fake.
-d fiel Check that the file is a directory and, if so, the condition is true. The (-d$ file) is incorrect.
-f fiel Check the file instead of a directory or special file if it is then the condition becomes a real normal file. The file is real.
-g fiel Check that the file has its Settings Group ID (SGID) if it is then the condition becomes a real-bit setting. The (-g$ file) is a fake.
-k fiel Check if the condition is true if the file has its sticky bit settings. The .-k$file is a fake.
-p fiel The check file is a named pipe, and if so, the condition is true. The (-p$ file) is a fake.
-t fiel Check that the file descriptor is open and, if so, that the condition becomes true and associated with the terminal. The .-t$file is false.
-u fiel If the file has its settings user ID (SUID) check is then the condition becomes a real bit setting. The file is fake.
-r fiel Check if the file is then the condition becomes true readable. The file is real.
-w fiel Check the file if it is then the condition becomes true. The file is real.
-x fiel Check if the file is then the condition becomes true execution. The file is real.
-s fiel Check that the file has a size greater than 0, and if so, the condition is true. The file is real.
-e fiel Check if the file exists. /b10> In fact, even if the file is a directory, it exists. The (-e$file) is real.

Shell judgment statement

if... The fi statement

if [ expression ]
then
   Statement(s) to be executed if expression is true
fi

if... e lse... The fi statement

if [ expression ]
then
   Statement(s) to be executed if expression is true
else
   Statement(s) to be executed if expression is not true
fi

if... e lif... The fi statement

if [ expression 1 ]
then
   Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
   Statement(s) to be executed if expression 2 is true
elif [ expression 3 ]
then
   Statement(s) to be executed if expression 3 is true
else
   Statement(s) to be executed if no expression is true
fi

case... esac statement

case word in
  pattern1)
     Statement(s) to be executed if pattern1 matches
     ;;
  pattern2)
     Statement(s) to be executed if pattern2 matches
     ;;
  pattern3)
     Statement(s) to be executed if pattern3 matches
     ;;
esac

Shell loop statement

While loop

while command
do
   Statement(s) to be executed if command is true
done

For loop

for var in word1 word2 ... wordN
do
   Statement(s) to be executed for every word.
done

The until loop

until command
do
   Statement(s) to be executed until command is true
done

Select loop

select var in word1 word2 ... wordN
do
   Statement(s) to be executed for every word.
done

Shell loop control

Break statement

break [n]

The continue statement

continue [n]

Shell replacement

When it encounters an expression shell that contains one or more special characters to replace.

Command replacement

When the command gives an execution command replacement -

`command`

Variable replacement

Here is the table below for all possible replacements -

Forms Describe
$ {VAR} The value variant of the replacement.
$ {VAR:-word} If the VAR is null or canceled, the word replaces the variant. /b20> The value of VAR does not change.
$ ( VAR: . If the VAR is null or canceled, the VAR is set to the value word.
$ (VAR:Message) If the VAR is null or canceled, the message is printed to a standard error. /b20> This checks that the variables are set correctly.
$ ( VAR: . If the variant is set, the value VAR of the word instead of the variant does not change.

Redirect commands

Here's a complete list of commands you can use to redirect -

Command Describe
pgm > file The output of the platinum family metal is redirected to the file
pgm < file Schedule the PCM to read the input of the file.
pgm >>file The output of the platinum family metal is appended to the file.
n > file The output from the file descriptor n stream is redirected to the file.
n >> file Attach to the file from the stream output file descriptor n.
n >&m Merge the output from stream n to stream m.
n <&m Stream n and Stream M will be entered.
<< tag The standard input is from here by starting the next label on the line.
| Need to output from one program, or process, and send it to another.

Shell help page

This quick guide lists the commands, including syntax and brief instructions. For more details, use unix common commands

$man command