
Linux
周杰伦今天喝奶茶了吗
喜欢周杰伦,也喜欢优快云博客,这使我快乐!
展开
-
Shell Scripts练习题
编写一个script, 创建目录/tmp/scripts, 切换工作目录到此目录中,复制你home下的某个目录到当前目录,并重命名为test,将test里的文件及其下的目录的其他用户权限改为没有任何权限。#!/bin/bash#创建目录/tmp/scripts, 切换工作目录到此目录中echo "make new dir"mkdir /tmp/scriptsecho "change ...原创 2019-05-04 20:05:06 · 389 阅读 · 0 评论 -
Linux shell(判断条件语句:获取系统时间)
#!/bin/bashecho "time now is:"read hoursif [ $hours -lt 12 ]thenecho "good morning"elif [ $hours -ge 12 ] && [ $hours -lt 20 ]thenecho "good afternoon"elseecho "good night"fi调用系统...原创 2019-05-12 13:42:08 · 7156 阅读 · 0 评论 -
进程控制——exec函数族
系统调用execve()对当前进程进行替换,替换者为一个指定的程序,其参数包括文件名(filename)、参数列表(argv)以及环境变量(envp)。exec函数族不止一个,但它们大致相同,在 Linux中,它们分别是:execl,execlp,execle,execv,execve和execvp一个进程一旦调用exec类函数,它本身就"死亡"了,系统把代码段替换成新的程序的代码,废弃原...原创 2019-05-11 21:52:21 · 399 阅读 · 0 评论 -
linux c语言 执行cd pwd
#include<stdio.h>#define PATH_SIZE 100#define BUF_SIZE 64int cds(const char *p){ char path[PATH_SIZE]; char *start; char *end; int res; int n= 0; memset(path,'\0',PATH_SIZE); // must...原创 2019-05-07 15:39:10 · 1700 阅读 · 2 评论 -
C语言实现linux 的ls命令
#include<stdio.h>#include<sys/types.h> //opendir,reader,closed等函数相关的头文件#include<dirent.h> //opendir,reader,closed等函数相关的头文件void do_ls(char[]); //函数声...原创 2019-05-07 15:07:48 · 913 阅读 · 0 评论 -
UNIX File IO
多数Unix I/O常用的5个系统调用有functions:open,read,write,lseek and close,它们一般被称为无缓冲的I/O无缓冲意味着每一次read, write文件都直接调用了内核的系统调用open函数的三个参数:(1)path是已经存在的文件的路径;(2)oflags参数:若值为 O_RDONLY ,就以只读方式打开文件;...原创 2019-05-09 10:02:01 · 224 阅读 · 0 评论 -
编写一个script判断命令行参数$1是否包含特殊符号
#!/bin/bashinput=$1if [[ $input =~ "*" ]]thenecho "$1 include *"elseecho "$1 doesn't have *"fi利用字符串运算符 =~ 直接判断A是否包含B。https://www.jb51.net/article/100490.htm这篇博客还提供了更多的方法。bash shell sc...原创 2019-05-05 15:39:48 · 348 阅读 · 0 评论 -
编写一个script把某个目录下的所有文件名小写的改为大写
大写变小写#!/bin/bashecho "directory name is:"read fnameecho "cd the directory"cd /home/xx/$fnamepwdecho "change lower to upper"for filename in `ls`do if [[ $filename != *[[:upper:]]* ]];then...原创 2019-05-05 15:25:58 · 817 阅读 · 0 评论 -
编写一个script显示某个文件中从指定行数到下一个指定行数的内容
#!/bin/bashfilename=$3start=$1end=$[$1+$2]cat $filenameecho "show what you want"echo "use cat"cat $filename| head -n $end | tail -n +$startecho "use sed"sed -n "$start,$end p" $filenametai...原创 2019-05-05 14:37:29 · 189 阅读 · 0 评论 -
编写一个script删除当前目录下大小为0的文件
#!/bin/bashecho "new a empty directory"mkdir emptyfilecd emptyfilepwdtouch a.txttouch b.txttouch c.txtecho "list all"ls -alfor filename in `ls`do if [ ! -s $filename ] ...原创 2019-05-04 21:26:43 · 1237 阅读 · 0 评论 -
syntax error near unexpected token `else'
开始我是这样写的,结果报错了#!/bin/bashfilename=$1if [ -e /home/xx/$filename ]echo "exist"elseecho "inexistence"fi 后来发现原来少了一个 then#!/bin/bashfilename=$1if [ -e /home/xx/$filename ]thenecho "exist"...原创 2019-05-04 21:04:29 · 14783 阅读 · 1 评论 -
ShellScript练习题
编写一个script, 显示当前系统日期和时间,而后创建目录/tmp/lstest, 切换工作目录至/tmp/lstest, 创建目录a1d,b56e,6test, 创建空文件xy,x2y,732, 列出当前目录下以a,x或者6开头的文件或目录, 列出当前目录下以字母开头,后跟一个任意数字,而后跟任意长度字符的文件或目录。#!/bin/bashecho "显示系统当前时间:"echo `...原创 2019-05-04 20:54:35 · 419 阅读 · 0 评论 -
ShellScript练习题
编写一个script能接受一个目录作为命令行参数,如果传入的参数个数多于或少于1,显示一个使用信息提示,比如:“usage: program directory”。如果这个参数不是一个目录,显示一个错误信息。如果是一个目录,显示出此目录下的所有文件,然后再显示出最大的五个文件。#!/bin/bashif [ $# -ne 1 ]thenecho "usage: program dire...原创 2019-05-04 20:37:44 · 206 阅读 · 0 评论 -
Linux shell 批量改后缀名
#!/bin/bashecho "change tail of file"cd /home/testmyselftail=$1 for filename in `ls`domv $filename ${filename}.$tail#我试了一下,mv $filename $filename.$tail 写成这样也可以done...原创 2019-05-12 17:52:29 · 353 阅读 · 0 评论