1. Locate the source file path for the command
[[email protected] ~]# which lsalias ls= ' ls--color=auto '/bin/ls[[email protected] ~]# which cat/bin/cat# some commands use aliases, So there is alias related information to remove alias related [[email protected] ~]# [[email protected] ~]# which LS | Grep-v "Alias" #使用grep-V Remove alias/bin/ls[[email protected] ~]# which LS | Grep-v "Alias" | awk ' {print '} ' #使用这个命令就能输出源文件路径/bin/ls
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/61/wKioL1X7ywPj4lAeAAbPJN-Fe6Y461.gif "title=" Bash2.gif "alt=" Wkiol1x7ywpj4laeaabpjn-fe6y461.gif "/>
2. Find the file that the command depends on
[[email protected] ~]# ldd/bin/ls# look at the time the/bin/ls execution depends on the library, you can see that it is useful to include/lib64 [[email protected] ~]# Ldd/bin/ls | Grep-o "/lib64.*" #grep-o display only matching [[email protected] ~]# Ldd/bin/ls | Grep-o "/lib64.*" | awk ' {print '} ' #使用此命令就能输出命令依赖的库文件 #/bin/ls taken from which LS | Grep-v "Alias" | awk ' {print '} '
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/61/wKioL1X7zQOj-TdXAAkqY-Cd0Dg382.gif "title=" Bash.gif "alt=" Wkiol1x7zqoj-tdxaakqy-cd0dg382.gif "/>
3. Porting command Scripts
Now that you are porting a command, you need to migrate the command source files and the libraries that you depend on. BINCP the Migration command source file, libcp the corresponding migration dependent library file, create the following script and execute it.
The dirname feature is the path name of the fetch file.
Use the chroot test after the migration is complete.
[[email protected] tmp]# vi /tmp/cp1.sh #!/bin/bash#dest=/mnt/sysroot# set Port of destination LIBCP () { libpath= ' Dirname ${1} ' [ ! -d $DEST $libpath ] && mkdir -p $DEST $libpath [ ! -e $DEST ${1} ] & & cp $1 $DEST $libpath && echo "copy lib $1 finished."} BINCP () { cmdpath= ' dirname ${1} ' [ ! -d $DEST $cmdpath ] && mkdir -p $DEST $cmdpath [ ! -e $DEST ${1} ] && cp $1 $DEST $cmdpath for lib in ' ldd $1 | grep -o "/lib64.*" | awk ' {print $1} '; do libcp $LIB done}read -p "your command: " CMDuntil [ $CMD == ' Q ' ]; do ! which $CMD && echo "Wrong command" && read -p "Input again:" CMD && continue Command= ' which $CMD | grep -v "Alias" | awk ' {print $1} ' bincp $COMMAND echo "copy $COMMAND finished." read -p "continue: " cmddone
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/73/65/wKiom1X73aqiJYwGAA5eO8BQveM843.gif "title=" Move.gif "alt=" Wkiom1x73aqijywgaa5eo8bqvem843.gif "/>
This article is from "Linux Novice learning" blog, please be sure to keep this source http://xzb2015.blog.51cto.com/8796643/1696124
Build your own Linux-02 command to migrate