查找可执行文件 当你从命令行中运行一个程序的时候,Linux 系统会搜索一系列目录来查找对应的文件。这些目录被定义在环境变量 PATH 中。如果你想找出系统中有哪些可执行文件可供使
查找可执行文件
当你从命令行中运行一个程序的时候,Linux 系统会搜索一系列目录来查找对应的文件。这些目录被定义在环境变量 PATH 中。如果你想找出系统中有哪些可执行文件可供使用,只需要扫描 PATH 环境变量中所有的目录就行了。
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ bash findExe.sh > /tmp/findExeOutput.txt | head -n 10 /tmp/findExeOutput.txt/usr/local/sbin:
/usr/local/bin:
/usr/sbin:
/usr/sbin/aa-remove-unknown
/usr/sbin/aa-status
/usr/sbin/accept
/usr/sbin/accessdb
/usr/sbin/acpid
/usr/sbin/addgnupghome
/usr/sbin/addgroup
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ cat findExe.sh
# =============================================================================
#
# Author: jiaming - jmzhang2020@lzu.edu.cn
#
# blog : jiaming.blog.csdn.net
#
# Last modified: 2020-11-24 21:02
#
# Filename: findExe.sh
#
# Description:
#
# =============================================================================
IFS=:
for folder in $PATH
do
echo "$folder:"
for file in $folder/*
do
if [ -x $file ]; then
echo " $file"
fi
done
done
创建多个用户账户
将需要添加的新用户账户放在一个文本文件中,然后创建一个简单的脚本进行处理。
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ bash useradd.shadding rich
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
adding christine
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
adding barbara
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
adding tim
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ sudo bash useradd.sh
adding rich
adding christine
adding barbara
adding tim
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ tail /etc/passwd
hplip:x:118:7:HPLIP system user,,,:/var/run/hplip:/bin/false
geoclue:x:119:124::/var/lib/geoclue:/usr/sbin/nologin
gnome-initial-setup:x:120:65534::/run/gnome-initial-setup/:/bin/false
gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false
jiaming:x:1000:1000:jiaming,,,:/home/jiaming:/bin/bash
vboxadd:x:999:1::/var/run/vboxadd:/bin/false
rich:x:1001:1001:Richard Blum:/home/rich:/bin/sh
christine:x:1002:1002:Christine Bresnahan:/home/christine:/bin/sh
barbara:x:1003:1003:Barbara Blum:/home/barbara:/bin/sh
tim:x:1004:1004:Timothy Bresnahan:/home/tim:/bin/sh
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ cat useradd.sh
# =============================================================================
#
# Author: jiaming - jmzhang2020@lzu.edu.cn
#
# blog : jiaming.blog.csdn.net
#
# Last modified: 2020-11-24 20:56
#
# Filename: useradd.sh
#
# Description:
#
# =============================================================================
input="users.csv"
while IFS=',' read -r userid name
do
echo "adding $userid"
useradd -c "$name" -m $userid
done < "$input"
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ cat user
useradd.sh users.csv
jiaming@jiaming-VirtualBox:~/Documents/shellScript$ cat users.csv
rich,Richard Blum
christine,Christine Bresnahan
barbara,Barbara Blum
tim,Timothy Bresnahan