⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mvdir.sh

📁 Berkely的学生写的
💻 SH
字号:
#!/bin/sh# Name: mvdir# Desc: Move directories across file systems# Args: $1 -> src dir#       $2 -> dest dirPATH=/bin:/usr/bin ; export PATH# function to print errors and exitprintERROR() { echo "ERROR: $@." >&2 ; exit 1; }# function to print usage message and exitprintUSAGE() { echo "USAGE: `/bin/basename $0` $@." >&2 ; exit 1; }# check if sufficient args are givenif [ $# -lt 2 ] ; then printUSAGE "[src] [dest]" ; fi# check if the source directory existsif [ ! -d "$1" ] ; then    printERROR "The source $1 is not a directory, or does not exist"fi# split up the source dir into its name and its parents name for# easier processing later onSRCDIR_PARENT="`/usr/bin/dirname $1`"SRCDIR_CHILD="`/bin/basename $1`"# if dirname returns a relative dir we will be confused after cd'ing# latter on. So reset it to the full path.SRCDIR_PARENT="`(cd $SRCDIR_PARENT ; pwd ; )`"# initalize the destination directoryDESTDIR="$2"; # check if the destination exitsif [ ! -d "$DESTDIR" ] ; then    # if the destination doesn't exist then assume the destination is    # the new name for the directory    DESTDIR="`/usr/bin/dirname $2`"    NEWNAME="`/bin/basename $2`"fi# if dirname returns a relative dir we will be confused after cd'ing# latter on. So reset it to the full path.DESTDIR=`(cd $DESTDIR ; pwd ; )`# if the parent of the destination doesn't exist,# were in trouble. Tell the user and exit.if [ ! -d "$DESTDIR" ] ; then    printERROR "A parent of the destination directory $2 does not exist"fi# try and cd to the parent src directorycd "$SRCDIR_PARENT" > /dev/null 2>&1if [ $? -ne 0 ] ; then    printERROR "Could not cd to $SRCDIR_PARENT"fi# use tar to copy the source dir to the destination/bin/tar -cvpf - "$SRCDIR_CHILD" | ( cd "$DESTDIR" ; /bin/tar -xvpf - )if [ $? -ne 0 ] ; then    printERROR "Unable to sucessfully move $1 to $2"fi# if a rename of the copy is requestedif [ -n "$NEWNAME" ] ; then    # try and change to the destination directory     cd "$DESTDIR" > /dev/null 2>&1    if [ $? -ne 0 ] ; then	printERROR "Could not cd to $DESTDIR"    fi    # try and rename the copy    /bin/mv "$SRCDIR_CHILD" "$NEWNAME" > /dev/null 2>&1    if [ $? -ne 0 ] ; then	printERROR "Could not rename $1 to $2"    fi    # return to the original directory    cd "$SRCDIR_PARENT" > /dev/null 2>&1    if [ $? -ne 0 ] ; then	printERROR "Could not cd to $SRCDIR_PARENT"    fifi# try and remove the originalif [ -d "$SRCDIR_CHILD" ] ; then     /bin/rm -r "$SRCDIR_CHILD" > /dev/null 2>&1    if [ $? -ne 0 ] ; then	printERROR "Could not remove $1"    fifiexit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -