当前位置: 技术问答>linux和unix
小妹求助Shell Script
来源: 互联网 发布时间:2016-03-22
本文导语: 以下的Shell Script, 用于测试一个已存在的文件,改写此Shell Script, 使文件名由用户从键盘输入,而不是作为第一个命令行参数,并说明此shell script 实现了哪些功能,awk在这里面的使用方法。不生感激! #!/bin/bash ...
以下的Shell Script, 用于测试一个已存在的文件,改写此Shell Script, 使文件名由用户从键盘输入,而不是作为第一个命令行参数,并说明此shell script 实现了哪些功能,awk在这里面的使用方法。不生感激!
#!/bin/bash
# This script gives information about a file.
FILENAME="$1"
echo "Properties for $FILENAME:"
if [ -f $FILENAME ]; then
echo "Size is $(ls -lh $FILENAME | awk '{ print $5 }')"
echo "Type is $(file $FILENAME | cut -d":" -f2 -)"
echo "Inode number is $(ls -i $FILENAME | cut -d" " -f1 -)"
echo "$(df -h $FILENAME | grep -v Mounted | awk '{ print "On",$1",
which is mounted as the",$6,"partition."}')"
else
echo "File does not exist."
#!/bin/bash
# This script gives information about a file.
FILENAME="$1"
echo "Properties for $FILENAME:"
if [ -f $FILENAME ]; then
echo "Size is $(ls -lh $FILENAME | awk '{ print $5 }')"
echo "Type is $(file $FILENAME | cut -d":" -f2 -)"
echo "Inode number is $(ls -i $FILENAME | cut -d" " -f1 -)"
echo "$(df -h $FILENAME | grep -v Mounted | awk '{ print "On",$1",
which is mounted as the",$6,"partition."}')"
else
echo "File does not exist."
|
#!/bin/bash
# This script gives information about a file.
read FILENAME
echo "Properties for $FILENAME:"
if [ -f $FILENAME ]; then
echo "Size is $(ls -lh $FILENAME ¦ awk '{ print $5 }')"
echo "Type is $(file $FILENAME ¦ cut -d":" -f2 -)"
echo "Inode number is $(ls -i $FILENAME ¦ cut -d" " -f1 -)"
echo "$(df -h $FILENAME ¦ grep -v Mounted ¦ awk '{ print "On",$1",
which is mounted as the",$6,"partition."}')"
else
echo "File does not exist."
awk1 :ls -lh $FILENAME第五5字段大小
awk2 :显示当前文件所在的分区文件系统,挂载点