LINUX_SRV Telegram 417
Полезные 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/linux_srv/417
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/linux_srv/417

View MORE
Open in Telegram


Telegram News

Date: |

Members can post their voice notes of themselves screaming. Interestingly, the group doesn’t allow to post anything else which might lead to an instant ban. As of now, there are more than 330 members in the group. Select: Settings – Manage Channel – Administrators – Add administrator. From your list of subscribers, select the correct user. A new window will appear on the screen. Check the rights you’re willing to give to your administrator. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” 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.
from us


Telegram Типичный Сисадмин
FROM American