Linux simple cmd

mkdir -p da/db/dc

mkdir directory

rm -rf

rmdir directory

command;command2;command3

command1;sleep 10;command3

echo "command1;sleep 10;command3" >>main.c

cp -r da dc:r -recursive

-i:indication

rm -rf :remove -recursive -force

rmdir : remove directory

rm : remove file

rm -f !(main.c):except main.c

find . -not -name "mian.c" -exec rm -rf {} \;

ls -F:-

format

echo *.c

ls *.c

rm *.c

?:one character

*:any character

ls f?

ls f[a-c]

ls f[123abcd]

echo f[4-12]:f[4-1] or f[2]

cat file:

more file:(q:quit)

less file:

head -5 file:show the first 5 lines

tail -3 file:show the last 3 lines

wc file:word count

wc -l file:line count

grep keywords file:search keywords

grep -i keywords file:ignore uppercase or lowcase

grep -v keywords file:search without keywords

cmd 1|cmd 2:cmd1's result is the parameter of cmd 2

eg:grep main|more


 

vim

H:first line

L:last line

M:middle line

ctrl+f:forword

ctrl+b:backspace

:number :locate no. line

number G:no. line go

G:go to end of file

G1:the first line of the file

w:next word

b:previous word

e:word end

set nu //show the line number

set nonu:

I:input at the start of line(Insert)

A:intput ar the end of line(Append)

O:insert a line up;(ON)

x:delete character

5x:delete 5 character

u:undo

p:ctrl+z

P:paste

dw:delete word

de:delete to end word

dd:delete line

d$:from curser to the start of line

8,11 m 18 line:move

8,11 co 18 line:copy

yl:copy

yw:copy word

yy:copy the whole line

3yy:3 lines

r key:replace

cw:

~:change uppercase and lowercase

J:conjuction

/key :search forward key

n:next

?key:search previous

$:sign of the last

%:the whole paper

x:save and exit

telnet

find directory condition [cmd] -- print

eg:

find . -name "f*"

find . -name "*.cpp"

find dir1 condition -exec cp {} target dir2 \;

{} :the file that find

\; escape sequence :the sign of cmd over;

eg:

find /home/user/project -name "*.c" -exec cp {} /home/user \;

who:show anybody who on this machine

users:

whoami:

w:who where when do what

history:show history cmd

!number:run the cmd again

du:

Network

ping IP

ifconfi -a


 

FTP

ls:show ftp

!ls :show local

lcd :local change dir

put:upload files

get:download

mput/mget:multiply put/get

mkdir :make dir

bye:exit

help:show all cmds

env:environment

echo "$PATH"

PATH = $PATH:.

:delimiter

whereis cmd :search cmd location

which cmd:

vim my.sh

echo hello world

sleep 10

echo $USER

echo date

source my.sh = ./my.sh


































 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是代码实现: ```c #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/semaphore.h> #define QUEUE_SIZE 10 #define MSG_SIZE sizeof(struct msg) struct msg { u16 module_id; u16 cmd_id; u16 cmd_subid; u16 complete; u8 data[128]; }; struct queue { struct msg *msgs[QUEUE_SIZE]; int head; int tail; int count; struct semaphore sem; }; struct queue *msg_queue; /* 初始化msg结构体 */ void init_msg(struct msg *m) { m->module_id = 0; m->cmd_id = 0; m->cmd_subid = 0; m->complete = 0; memset(m->data, 0, sizeof(m->data)); } /* 函数一,向队列中添加msg结构体 */ void add_msg_to_queue(struct msg *m) { down(&msg_queue->sem); // 获取信号量,防止并发访问 if (msg_queue->count == QUEUE_SIZE) { // 队列已满 up(&msg_queue->sem); return; } msg_queue->msgs[msg_queue->tail] = m; msg_queue->tail = (msg_queue->tail + 1) % QUEUE_SIZE; msg_queue->count++; up(&msg_queue->sem); // 释放信号量 } /* 函数二,从队列中取出msg结构体并更新complete成员 */ struct msg *get_msg_from_queue(void) { struct msg *m; down(&msg_queue->sem); // 获取信号量,防止并发访问 if (msg_queue->count == 0) { // 队列为空 up(&msg_queue->sem); return NULL; } m = msg_queue->msgs[msg_queue->head]; msg_queue->head = (msg_queue->head + 1) % QUEUE_SIZE; msg_queue->count--; m->complete = 1; // 更新complete成员 up(&msg_queue->sem); // 释放信号量 return m; } static int __init my_module_init(void) { int i; msg_queue = kmalloc(sizeof(struct queue), GFP_KERNEL); if (!msg_queue) { printk(KERN_ALERT "Failed to allocate memory for msg_queue\n"); return -ENOMEM; } msg_queue->head = 0; msg_queue->tail = 0; msg_queue->count = 0; sema_init(&msg_queue->sem, 1); // 初始化信号量 /* 初始化队列中的msg结构体 */ for (i = 0; i < QUEUE_SIZE; i++) { msg_queue->msgs[i] = kmalloc(MSG_SIZE, GFP_KERNEL); if (!msg_queue->msgs[i]) { printk(KERN_ALERT "Failed to allocate memory for msg\n"); while (i > 0) { i--; kfree(msg_queue->msgs[i]); } kfree(msg_queue); return -ENOMEM; } init_msg(msg_queue->msgs[i]); add_msg_to_queue(msg_queue->msgs[i]); } return 0; } static void __exit my_module_exit(void) { int i; for (i = 0; i < QUEUE_SIZE; i++) { kfree(msg_queue->msgs[i]); } kfree(msg_queue); } module_init(my_module_init); module_exit(my_module_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("A simple example Linux module."); ``` 上述代码中,`msg_queue` 是环形队列的结构体,它包含了一个指向 `struct msg` 的指针数组,以及队列的头、尾指针和元素数量。`sem` 是信号量,用于保护队列,避免多个线程同时访问导致的数据竞争问题。 函数 `init_msg` 用于初始化 `msg` 结构体,将 `complete` 成员赋值为 0。 函数 `add_msg_to_queue` 用于向队列中添加 `msg` 结构体,如果队列已满,则直接返回。 函数 `get_msg_from_queue` 用于从队列中取出 `msg` 结构体并更新 `complete` 成员,如果队列为空,则直接返回 `NULL`。 在 `my_module_init` 函数中,我们首先申请了一个 `msg_queue` 结构体的内存,并进行了初始化。然后使用 `init_msg` 函数初始化了队列中的所有 `msg` 结构体,并将它们添加到队列中。 在 `my_module_exit` 函数中,我们释放了队列中所有 `msg` 结构体的内存,并释放了 `msg_queue` 结构体的内存。 当然,上面代码只是一个简单的示例,实际应用中需要根据具体需求进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值