SRV_ADMIN_LINUX Telegram 706
Полезные Bash-скрипты для повседневных задач

Ниже — два скрипта, которые могут сэкономить тебе время и нервы.


Перемещение директории


#!/bin/bash

# Проверка существования директории-источника
if [ ! -d "$1" ]; then
echo "$1 doesn't exist"
exit 1
fi

# Проверка существования директории-назначения
if [ ! -d "$2" ]; then
echo "$2 doesn't exist"
exit 1
fi

# Копирование и удаление исходной директории
if cp -r "$1" "$2" && rm -r "$1"; then
echo "Dir $1 was moved to dir $2 successfully"
exit 0
else
echo "Something went wrong"
exit 1
fi



Переименование файла


#!/bin/bash

# Проверка количества аргументов
if [ $# -ne 2 ]; then
echo "2 args needed: file to rename and new name"
exit 1
fi

# Проверка существования файла
if [ ! -f "$1" ]; then
echo "File $1 does not exist or it's not a file"
exit 1
fi

# Переименование через копирование и удаление
if cp "$1" "$2" && rm -f "$1"; then
echo "Name of file $1 was changed to $2"
exit 0
else
echo "Something went wrong!"
exit 1
fi
2👍1



tgoop.com/srv_admin_linux/706
Create:
Last Update:

Полезные Bash-скрипты для повседневных задач

Ниже — два скрипта, которые могут сэкономить тебе время и нервы.


Перемещение директории


#!/bin/bash

# Проверка существования директории-источника
if [ ! -d "$1" ]; then
echo "$1 doesn't exist"
exit 1
fi

# Проверка существования директории-назначения
if [ ! -d "$2" ]; then
echo "$2 doesn't exist"
exit 1
fi

# Копирование и удаление исходной директории
if cp -r "$1" "$2" && rm -r "$1"; then
echo "Dir $1 was moved to dir $2 successfully"
exit 0
else
echo "Something went wrong"
exit 1
fi



Переименование файла


#!/bin/bash

# Проверка количества аргументов
if [ $# -ne 2 ]; then
echo "2 args needed: file to rename and new name"
exit 1
fi

# Проверка существования файла
if [ ! -f "$1" ]; then
echo "File $1 does not exist or it's not a file"
exit 1
fi

# Переименование через копирование и удаление
if cp "$1" "$2" && rm -f "$1"; then
echo "Name of file $1 was changed to $2"
exit 0
else
echo "Something went wrong!"
exit 1
fi

BY Админские угодья





Share with your friend now:
tgoop.com/srv_admin_linux/706

View MORE
Open in Telegram


Telegram News

Date: |

Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. Choose quality over quantity. Remember that one high-quality post is better than five short publications of questionable value. Telegram channels enable users to broadcast messages to multiple users simultaneously. Like on social media, users need to subscribe to your channel to get access to your content published by one or more administrators. The imprisonment came as Telegram said it was "surprised" by claims that privacy commissioner Ada Chung Lai-ling is seeking to block the messaging app due to doxxing content targeting police and politicians. It’s yet another bloodbath on Satoshi Street. As of press time, Bitcoin (BTC) and the broader cryptocurrency market have corrected another 10 percent amid a massive sell-off. Ethereum (EHT) is down a staggering 15 percent moving close to $1,000, down more than 42 percent on the weekly chart.
from us


Telegram Админские угодья
FROM American