Common Shell Commands in Linux

Shell is a command interpreter
[login user name@hostname current directory] Prompt
Shell has two prompts
# indicates that the terminal is opened by the root user
$ indicates that the terminal is opened by a general user



(wildcard)
* abc* means all files starting with adc
? abc? means all files starting with adc with a length of 4 characters
(Shell command)
ls (display command) (no hidden files will be displayed)
-a show all files and directory

-l display file information in long format (can be abbreviated as ll )

-t sorts the results by modification time, new files or directories come first
-R If there are files in the directory, list all files in the directory

 ~ Display all file names and subdirectories in the starting directory

eg: ls -al / Display complete information of all files in the root directory         

eg:ls -at a* displays all files starting with a in the current directory, new files are listed first




pwd shows the absolute path where the current directory is located
cd changes the current directory
cd .. switches to the parent directory of the current directory




mkdir create directory

-p         If the upper directory of the directory to be created does not exist, create it first

eg:mkdir -p dir1/dir2 creates dir1/dir2 in the current directory, if dir1 does not exist, create it first



rmdir delete directory

-p         When the specified directory is deleted, if the parent directory of the directory is empty, it will also be deleted

eg:rmdir -p dir1/dir2 delete the dir2 subdirectory in the dir1 directory under the current directory, if dir1 becomes an empty directory after deleting dir2, it will also be deleted



cat                          file content viewing and connection
-n/--number                  to output the content by line number
-b/--number-nonblock is similar to -n, except that no numbering is performed for blank lines
-s                          when encountering more than two consecutive lines of blanks line is replaced with a blank line

-v                         show unprintable characters

eg:cat -n test.c adds the content of the file test.c to the line number and displays the output

eg: cat test1.c test2.c concatenate the contents of the files test1.c and test2.c together and output the


cp file copy
-r If there are files or directories in the source directory, they will be copied to the destination

-f If there is already a file with the same name in the target directory, delete it and copy the source file to the target directory

eg:cp test.c tmp/program.c Copy the test.c file in the current directory to the /tmp directory and name it program.c

eg:cp *.c /tmp Copy all files ending in .c in the current directory to the /tmp directory


rm file delete
-d delete the specified directory
-i ask for confirmation before deleting
-r If the directory is not empty, then delete all files in the directory

-f force delete

eg:rm *.c delete all files ending with .c in the current directory

eg:rm -rf typ forcibly delete all files and subdirectories in the typ directory, all files or directories in the subdirectories are deleted


mv 1: move

    2: Rename (=rename)

eg: mv 123 456 [if 456 exists, move and rename if it does not exist]


Halt shutdown (must be root privileges)


touch create file

touch linux-{1..3}.c will create linux-1.c, linux-2.c, linux-3.c three files


mkfifo creates the famous pipe


echo to input a string of characters to the screen, similar to the printf() function of C language.
Syntax: echo [-n/e][string] or echo [--help][--version]
Description: echo will send the input string to standard output. The output strings are separated by whitespace characters and appended with a newline at the end.
Parameters:
-n Do not wrap the line at the end
-e If the following characters appear in the string, they will be processed specially, and will not be
output as normal text:
\a emit a warning sound;
\b delete the previous character;
\c last Do not add a newline;
\f wraps the line but the cursor remains at the original position;
\n wraps the line and moves the cursor to the beginning of the line;
\r moves the cursor to the beginning of the line, but does not wrap;
\t inserts a tab;
\v and \f same;
\\ insert \ character;
\nnn insert ASCII character represented by nnn (octal);
--help display help
--version display version information

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325637496&siteId=291194637