Skip to content

Tag: bash

Delete logs that ended with date format

I created the following cli in order to delete the logs with date format that oldest then 500 min date format is: the cli that should removed the logs as we can see the logs still exists where I am wrong? Answer Your regex does not match the files. Change ‘.*.log.[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,10}$&…

Exiting bash script without terminating ssh connection

I’m pretty new to bash scripting and I’m attempting to write a script that does some basic operations. I want to check certain conditions and if they are met, terminate the script. So for example, I want to check whether the zip of files was successful: What happens though is that the exit 1 signa…

How to create folders and files from paths given in text file

I have a text file named creating.txt. In this file, each line has a path. If line starts with D it means that I have to create directory. If line starts with F, I have to create a file. For example: I need to go line by line, first check if first letter is D or F, then ignore the

Is it possible to get command arguments now executing?

I want to declare aliases which append argument if no argument specified. For example, I expected executing vimtutor with no argument is replaced to vimtutor ja.utf-8, but it doesn’t work properly. So, I tried some tests on bash shell. And I understood it is impossible to get command arguments now executing i…

Switch to root user within bash script

Im currently logged in as admin and I want to edit the /etc/hosts file which required root access. I’m not able to make the changes. The script gets executed sucessfully but the changes arent made. My Script – Runs Sucessfully when executed from terminal sudo -s – switches to root without pa…