[Linux] Commonly used commands (2)

5a2585dded9b416fb4ea58637b42ed39.png

  Yan-yingjie's homepage

Awareness of the past, not remonstrance, knowing the future, can be pursued  

C++ programmer, 2024 electronic information graduate student


Table of contents

man command    

echo command

Replenish:

The difference between echo and cat?

 CP instruction

mv command

ctrl+c command

which command

Problems encountered in learning:

        1. How do you view instructions?

        2. Before executing the instruction, what should we do first?

nano command

        question:

cat command

more command

less instruction

head command

tail command


man command    

        View command details 

man ls

man pwd

man rm

man printf

man man

man fork

echo command

        Equivalent to the print command

echo "hello Linux"

        

//echo打印指令虽然没有将内容打印到桌面上,
//但是将hello Linux指令写入到test.txt中
echo "hello Linux" > test.txt
//我们将其成为输出重定向

//打印文件内容
cat test.txt

Replenish:

        The echo command actually writes data to the display file, >test.txt, and actually redirects it to write to the disk file

//echo指令

echo "hello Linux"

echo "hello Linux" > test.txt


//同时写入多条字符串
echo "hello Linux" > test.txt
echo "hello Linux" > test.txt
echo "hello Linux" > test.txt
echo "hello Linux" > test.txt
echo "hello Linux" > test.txt
echo "hello Linux" > test.txt

cat test.txt

//重定向虽然什么都没写,但是同样会清空文件
>test.txt

//如何不清空文件内容,向后面直接进行增加内容
echo "hello Linux" >> test.txt

//>叫做重定向,>>叫做追加重定向

         

reason:

        When echo writes to the target file

        ①. Clear the original file first

        ②, write the target file

The difference between echo and cat?

                echo is followed by a string, and cat is followed by a file name

         Output redirection, the data originally printed to the display is written to the file

 CP instruction

        copy normal file

                Copy the data of the test.txt file to the Test.txt file. There cannot be a file with the same file name in the same directory, otherwise

Violating the uniqueness of the file, the CP command can be copied in the same level directory, or copied to the file in the previous directory or the next directory

cp test.txt Test.txt

cp Test.txt ../Test.txt

//拷贝目录

cp Test class_108/Test

                        Since Linux is written in C, most ports are in C 

mv command

       rename && cut and rename

mv 目标名 需要改的命名

mv test.txt test1.txt

//剪切并进行重命名
mv test.txt ../a.txt

//  ./为当前目录,../为上级目录

//补充

//清屏
clear

ctrl+c command

        Termination Because the program or command is abnormal, we cannot enter the command.

//当执行命令时,死循环时,无法输入任何指令
ctrl + c

which command

//查看指令位置

which ls

which ll

which pwd

which cp

which rm

whick mkdir

//补充:
ls -l是ll的重命名

Problems encountered in learning:

        1. How do you view instructions?

                Both instructions and executable programs can be executed, and instructions are executable programs

        2. Before executing the instruction, what should we do first?

                Find the corresponding command in the system first

           Instructions exist under a specific path in the system, and must be some kind of executable program, which may be C/C++/python

Script programs written in languages ​​such as /shell are essentially executable programs, which are no different from programs written by ourselves.

Delete under mycmd, this way is to uninstall, everything under Linux is a file, such as monitor, keyboard, ordinary file

nano command

//编辑文件

nano 指定文件
//比如

nano test.c
//对文件编写完成后直接ctrl+x,进行保存,再退出


//调用该程序
gcc test.c

//查看文件内容
cat test.c

        question:

                   The reason for these two errors is: the program is not installed, we can install it directly

//编译文件时报错
-bash: gcc: command not found

//编写文件报错
-bash: nano: command not found

//解决办法:
yum install gcc

yum install nano  

cat command

        

//单纯cat
cat

//cat默认从后面开始,输入设备输入什么打印什么

//cat+文件名
cat test.txt

//文件名中有什么打印什么


cat -n test.txt
//给每一行加一个编号

//cat不适合看大文本
//如果cat看大文本,直接刷屏,前半部分直接就看不到了

more command

        

//开始打印文本(自上而下,从第一条开始)
more test.txt

//退出用q
//如果想进行查找直接用/99,直接翻到99行

less instruction

less test.txt

head command

//打印文件的前10行
head -10 test.txt

tail command

//打印文件后十行
tail -10 test.txt

//管道指令
//后面会被成为管道文件
head -1020 log.txt | tail -21

Guess you like

Origin blog.csdn.net/m0_73367097/article/details/130792545