linux经典shell语句

1.查看文件权限,以数字显示

[oracle@oracledb ~]$ ls -l /tmp/oracle.tmp| awk '{k=0;s=0;for(i=0;i<=8;i++ ){k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i))}j=4;for(i=4;i<=10;i+=3){s+=((substr($1,i,1)~/[stST]/)*j);j/=2}if(k){printf("%0o%0o ",s,k)}print}'
0644 -rw-r--r-- 1 oracle oinstall 5587 7月  15 14:29 /tmp/oracle.tmp

 

或者

[root@vps197121 ~]# wget http://www.dwhd.org/script/lsmod -O /bin/lsmod && chmod +x /bin/lsmod && echo 'alias ls="/bin/lsmod"' >> ~/.bashrc && . ~/.bashrc
--2015-09-08 21:25:13--  http://www.dwhd.org/script/lsmod
Resolving www.dwhd.org... 133.130.100.22, 2400:8500:1301:737:a133:130:100:220
Connecting to www.dwhd.org|133.130.100.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 783 [application/octet-stream]
Saving to: “/bin/lsmod”
 
100%[===============================================================================>] 783         --.-K/s   in 0s      
 
2015-09-08 21:25:14 (75.5 MB/s) - “/bin/lsmod” saved [783/783]
 
[root@vps197121 ~]# ls -l
0200 total 28
0644 -rw-r--r--  1 root root  3886 Sep  7 20:08 bench.sh
0644 -rw-r--r--  1 root root  4398 Aug 28 22:26 init.sh
0644 -rw-r--r--. 1 root root 10281 Dec  1  2014 install.log
0644 -rw-r--r--. 1 root root  3317 Dec  1  2014 install.log.syslog
[root@vps197121 ~]# ls -la
0200 total 100
0550 dr-xr-x---.  5 root root  4096 Sep  8 19:00 .
0555 dr-xr-xr-x. 24 root root  4096 Aug 31 02:47 ..
0600 -rw-------.  1 root root  3376 Sep  8 18:37 .bash_history
0644 -rw-r--r--.  1 root root    18 May 20  2009 .bash_logout
0644 -rw-r--r--.  1 root root   176 May 20  2009 .bash_profile
0644 -rw-r--r--   1 root root    22 Sep  8 21:25 .bashrc
0644 -rw-r--r--   1 root root  3886 Sep  7 20:08 bench.sh
0644 -rw-r--r--.  1 root root   100 Sep 23  2004 .cshrc
0644 -rw-r--r--   1 root root  4398 Aug 28 22:26 init.sh
0644 -rw-r--r--.  1 root root 10281 Dec  1  2014 install.log
0644 -rw-r--r--.  1 root root  3317 Dec  1  2014 install.log.syslog
0755 drwxr-xr-x   5 root root  4096 Aug 31 05:24 .ipython
0740 drwxr-----   3 root root  4096 Aug 31 05:19 .pki
0644 -rw-r--r--   1  501  501  4149 Jul  9 11:40 .screenrc
0700 drwx------.  2 root root  4096 Sep  7 21:28 .ssh
0644 -rw-r--r--.  1 root root   129 Dec  3  2004 .tcshrc
0600 -rw-------   1 root root  4328 Sep  8 17:39 .viminfo
0644 -rw-r--r--   1  501  501  4546 Jul 16 11:33 .vimrc
0600 -rw-------   1 root root   126 Sep  8 18:43 .Xauthority
[root@vps197121 ~]# ls /etc/fstab 
/etc/fstab
[root@vps197121 ~]# ls /etc/fstab -l
0644 -rw-r--r--. 1 root root 585 Aug 31 02:45 /etc/fstab
[root@vps197121 ~]#

 

2.linuxShell程序编写输出四位数的千位,百位,十位和个位

#!/bin/bash
read -p "请输入一个四位整数: " num
echo "千位: ${num:0:1}"
echo "百位: ${num:1:1}"
echo "十位: ${num:2:1}"
echo "个位: ${num:3:1}"
#!/bin/bash

read -p "请输入一个四位整数: " num  #读取用户输入,赋值给变量num

echo "千位: ${num:0:1}"  #取第1个数字,从index为0开始取1个字符

echo "百位: ${num:1:1}"  #取第2个数字,从index为1开始取1个字符

echo "十位: ${num:2:1}"  #取第3个数字,从index为2开始取1个字符

echo "个位: ${num:3:1}"  #取第4个数字,从index为3开始取1个字符
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

架构师之路魂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值