Чтобы убить всех зарегистрированных пользователей для :1, используйте эту команду:
awk '/\s:1\s/ {system("sudo kill -9 "$6)}' <<< $(who -u)
В вашем случае user2
user2 :1 2014-08-18 18:21 ? 25745 (:1)
Или все сеансы для user2 по имени пользователя
awk '/^user2\s/ {system("sudo kill -9 "$6)}' <<< $(who -u)
См. 10.1. Манипулирование Strings-TLDP.org для подробного обсуждения манипуляций с строкой bash. Этот ответ unix se имеет неотъемлемую часть ответа. Просто измените «txt» на $ext и «text» на $next. Результирующий скрипт мог бы выглядеть.
#!/bin/bash
read -p "type the path for folder " folder
read -p "type the extension of files to be renamed " ext
read -p "type the extension you want to add " next
# TODO add sanity checks for the user supplied input
cd $folder
# rename
#rename "s/.$ext$/.$next/" *.$ext
# mv in a loop
for f in *.$ext; do
# the '--' marks the end of command options so that files starting with '-' wont cause problems.
# Replaces the first match for '.$ext' with '.$next'.
#mv -- "$f" "${f/$ext/$next}"
# Replaces the any match for '.$ext' with '.$next'.
#mv -- "$f" "${f//$ext/$next}"
# Replaces front-end match of for '$ext' with '$next'
#mv -- "$f" "${f/#$ext/$next}"
# Replaces back-end match of for '$ext' with '$next'
mv -- "$f" "${f/%$ext/$next}"
done
Это 10.1. Манипулирование строк имеет много подходов, которые необязательно нуждаются в цикле. Я бы предпочел rename, см. Прокомментированные строки в приведенном выше скрипте.
См. 10.1. Манипулирование Strings-TLDP.org для подробного обсуждения манипуляций с строкой bash. Этот ответ unix se имеет неотъемлемую часть ответа. Просто измените «txt» на $ext и «text» на $next. Результирующий скрипт мог бы выглядеть.
#!/bin/bash
read -p "type the path for folder " folder
read -p "type the extension of files to be renamed " ext
read -p "type the extension you want to add " next
# TODO add sanity checks for the user supplied input
cd $folder
# rename
#rename "s/.$ext$/.$next/" *.$ext
# mv in a loop
for f in *.$ext; do
# the '--' marks the end of command options so that files starting with '-' wont cause problems.
# Replaces the first match for '.$ext' with '.$next'.
#mv -- "$f" "${f/$ext/$next}"
# Replaces the any match for '.$ext' with '.$next'.
#mv -- "$f" "${f//$ext/$next}"
# Replaces front-end match of for '$ext' with '$next'
#mv -- "$f" "${f/#$ext/$next}"
# Replaces back-end match of for '$ext' with '$next'
mv -- "$f" "${f/%$ext/$next}"
done
Это 10.1. Манипулирование строк имеет много подходов, которые необязательно нуждаются в цикле. Я бы предпочел rename, см. Прокомментированные строки в приведенном выше скрипте.
См. 10.1. Манипулирование Strings-TLDP.org для подробного обсуждения манипуляций с строкой bash. Этот ответ unix se имеет неотъемлемую часть ответа. Просто измените «txt» на $ext и «text» на $next. Результирующий скрипт мог бы выглядеть.
#!/bin/bash
read -p "type the path for folder " folder
read -p "type the extension of files to be renamed " ext
read -p "type the extension you want to add " next
# TODO add sanity checks for the user supplied input
cd $folder
# rename
#rename "s/.$ext$/.$next/" *.$ext
# mv in a loop
for f in *.$ext; do
# the '--' marks the end of command options so that files starting with '-' wont cause problems.
# Replaces the first match for '.$ext' with '.$next'.
#mv -- "$f" "${f/$ext/$next}"
# Replaces the any match for '.$ext' with '.$next'.
#mv -- "$f" "${f//$ext/$next}"
# Replaces front-end match of for '$ext' with '$next'
#mv -- "$f" "${f/#$ext/$next}"
# Replaces back-end match of for '$ext' with '$next'
mv -- "$f" "${f/%$ext/$next}"
done
Это 10.1. Манипулирование строк имеет много подходов, которые необязательно нуждаются в цикле. Я бы предпочел rename, см. Прокомментированные строки в приведенном выше скрипте.