SRV_ADMIN_LINUX Telegram 707
Полезные 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/707
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/707

View MORE
Open in Telegram


Telegram News

Date: |

Telegram iOS app: In the “Chats” tab, click the new message icon in the right upper corner. Select “New Channel.” 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. The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Don’t publish new content at nighttime. Since not all users disable notifications for the night, you risk inadvertently disturbing them. Telegram Channels requirements & features
from us


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