Batch file equivalent in Linux
In UNIX, a 'batchfile' is known as a shell script. A typical BASH shell script will start with a magic line that tells the operating system which shell to execute the script with, so your example would end up:
#!/bin/bash
cd /home/user/scripts
sh runTHISthing.sh pub
cd /home/user/logs
tailf pub.log
NOTE: After you create the file, you have to mark it as executable, in order for the OS to try executing it:
chmod +x myscript
Related videos on Youtube
Midhun
Vian Esterhuizen Born and half raised in South Africa, I'm now a Calgary based photographer and front-end web developer. Photography Portfolio Tumblr Instagram Facebook Twitter 500px LinkedIn Codepen
Updated on September 18, 2022Comments
-
Midhun over 1 year
I have a few basic commands that I need to run on a Red Hat Linux 5 Virtual Machine with GNOME to start a couple servers.
Example
cd /home/user/scripts sh runTHISthing.sh pub cd /home/user/logs tailf pub.log
Not a crazy amount of code but sometimes I restart VM several times a day. In Windows, I would probably just create a batch file and put it on my desktop. Then it's just a matter of double clicking and off it goes.
Is there anyway to do the same in Linux? I've tried to create a launcher that just runs the emtpy file in terminal with no result.
-
Midhun almost 12 yearsSorry, that last part about marking it executable. How would I do that?
-
Don Simon almost 12 yearsIn a terminal window, issue the command "chmod +x scriptfilename", with the correct path to your script.