I'm pretty new using command line with ubuntu and I need to create a .sh file and inside the sh file I need to create a file using nano for a server block, I'm trying to create that but I do not know how to do that?
example:
nano /etc/xyz/file
Code that goes inside the nano file
close file and save.
And then continue with the other commands inside the .sh file, is that possible?
Related
In my shell script I would like to list all the files and directories in my current directory.
I know the command is ls, but I have no idea how to run it in a shellscript.
Thanks for anyhelp.
So you're basically asking: what is a shell-script, how do I create one, and how do I run it ....
Use your editor of choice to create a file, give it the following content:
#!/bin/sh # change to your preferred shell, sh being a low common denominator
command # in your immediate question that would be `ls`
Save the file.
Run chmod u+x file (not the word file, but what you called your saved script).
Then you can execute your file like so:
./file
[dawidn:/mnt/c/Users/dawin]$
This is my default shell directory, all of my projects are on partition d. Is there a way to make my shell start at a certain folder by default?
Edit the file ~/.bashrc
At the end of the file add the line:
cd /mnt/d/.....
Save an close the file.
On logging back into bash, you should have the specified directory as your initial current working directory.
Beginner linux user here,
I want to create an sh file which will open firefox, file explorer and sublime text, rather than execute these commands separately. I have created a bin folder in /home/user and have saved my .sh file there.
Everything runs as I want to except for running the sublime_text executable.
It cannot find the directory as I am running the sh file from the bin directory.
So, my question is, how can I open sublime text from another directory without creating another shell process to do so.
#!/bin/bash
cd /home/user/
./Documemnts/sublime_text_3/sublime_text
xdg-open ~/Documents/sublime_text_3/sublime_text
firefox -new-tab -url https://www.google.com
xdg-open Documents/Work/
I get No such file or directory
or
error: error opening location: No application is registered as handling this file
It looks like the directory on line 2 is misspelled:
./Documemnts/sublime_text_3/sublime_text
Notice Documemnts vs. Documents
I'm trying to write my first bash script to automate some boring stuff I have to type everytime but can't get it working.
I've created pgAdmin.sh in my home directory:
#!/bin/bash
cd /opt/enviromentpy/pgadmin4
source bin/activate
python lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
When I run it using ./pgAdmin.sh I get:
./pgAdmin.sh: line 2: cd: /opt/enviromentpy/pgadmin4: No such file or
directory
./pgAdmin.sh: line 3: bin/activate: No such file or directory
python: can't open file 'lib/python2.7/site-packages/pgadmin4/pgAdmin4.py': [Errno 2] No such file or directory
But when I open terminal and just put those commands one by one from Home directory it works just fine.
You have made a simple spelling mistake.
Instead of enviromentpy you probably meant to write enviromentpy (notice the extra n)
I am trying to add a tar command to the /test/backup/backup.sh that creates a full backup of everything in my file system except the /text directory to a file called /test/backup.dat. Plus redirect the standard output from this command to a file called /test/backuplog.txt. Redirect the standard error from this command to a file called /test/errlog.txt. How would I get this done? Thank you.
You can do that by adding this at the end of each command
<command> >>/test/backuplog.txt 2>>/test/errlog.txt
also you need to make sure that /test/backuplog.txt and /test/errlog.txt is writable