I have been working on a couple of projects now. Always as I am firing up my terminal, in mac, I start at the root folder, which is fine for most of the times. But I was wondering if there is a possibility to make a file which redirects you instantly to a map. Say for instance I have to type:
cd Desktop/justamap/justanothermap/andamap/etc.
Would it be possible to create a command file in the rootfolder, containing the full adress of the designated map, which would take me to the selected map just by for instance running it?
This could save me a lot of time when working on projects with time between them.
I am truly sorry if I am reposting a question but I just couldnt find something with my keywords.
Thx in advance, your help is appreciated!
Greetings,
Kipt Scriddy
You can create a simple sh file (for instance ./anything_here) and run it:
#!/bin/sh
cd Desktop/justamap/justanothermap/andamap/etc
$ chmod +x ./anything_here
$ ./anything_here
You can also create a symlink to the folder, and then cd into the symlink (this will act like the folder is, in fact, ./anything_here):
$ ln -s ./anything_here Desktop/justamap/justanothermap/andamap/etc
$ cd ./anything_here
Or you can create an alias, and write it on the console, putting this on your ~/.bashrc or ~/.bash_profile file:
alias anything_here="cd Desktop/justamap/justanothermap/andamap/etc"
$ anything_here
Try using
vi ~/.bash_profile
it will open in vim u can use mate or anyhing else
alias project='cd Desktop/justamap/justanothermap/andamap/etc.'
close your terminal and restart it. Bingo should work for you.
Working Great for me :)
Related
I am a rookie in Python who has been working on Learn Python the Hard Way. This whole process goes well as I have a smattering knowledge on Python until I march into ex46 where I get stuck in the 'Creating the skeleton Project Directory' section. I have no idea where I should run those commands guided on this book. Following are the excerpt of this part:
First, create the structure of your skeleton directory with these commands:
$ mkdir projects
$ cd projects/
$ mkdir skeleton
$ cd skeleton
$ mkdir bin
$ mkdir NAME
$ mkdir tests
$ mkdir docs
I have tried to run these commands in Windows Powershell, only to be warned that these commands can’t be recognized. I also fumbled to execute them in Pycharm, but all in vain. Could someone point out how I could get it done?
In addition, I am somewhat curious about this method because there seems to be handy way to approach this on Pycharm. Could I achieve the same goal on that?
I am using Python 2.7 and all previous exercises operate well until ex46.
You get that error because you're typing a superfluous $ at the beginning of each command. That $ is the (Linux) command prompt. On your Windows machine, it's something like C:\WINDOWS\system32>. Don't type that.
Just type
mkdir projects
and press Enter. That creates a folder (directory) named "projects". Then type
cd projects
and press Enter. That changes the current directory to that new folder you just created. And so on.
Content migrated from comments since this is what actually solved the issue.
Remove the dollar sign $ from the statement, as this is just the symbol used as a CLI prompt not part of the statement itself.
Then type the mkdir command and it should work e.g.
mkdir my_directory
I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali
Hello wonderful people.
I'm having a problem when following this tutorial to make a program that once worked on a mac work again after the upgrade.
http://bit.ly/1RkmdBA
However i'm not allowed to move anything over to lib folder. Im getting a circle with a line in it. Even while i'm holding the option key,and yes i'm the administrator.
The next step the writer suggested is to use sudo command. Im not so savy with code. Can someone tell me the exact command line.
If you would prefer to move from one location to another:
sudo mv ~/initial/file/location ~/destination/location
if you you would rather copy instead:
sudo cp ~/initial/file/location ~/destination/location
You simply add the sudo command to the beginning of another command, and it runs the command as root (it will prompt for your password first). For example, of you want to run this as root:
mv this-file /usr/lib/
Then you would change it to:
sudo mv this-file /usr/lib/
I'm using git portable on windows. It's rather user friendly, but there is one thing that bothers me. Every time I run it I have to type the entire path to the project directory, which is quite long sometimes. Maybe it's not a serious problem, but it would be very nice to shorten it. I tried the following:
bash script.sh // cd in this file // nothing happens
create symbolic link it - it just copies the directory
create windows shortcut - can't open it within git console
Anybody managed to solve this?
You can right click on the Windows shortcut that launches Git Bash, edit its properties and modify the "Start in" path to your project path. Every time you launch this shortcut, it will cd into that project path.
Or you can add an alias to your ~/.bashrc like below:
alias proj="cd /path/to/project/"
This will allow you to cd into the project dir on demand by typing the alias name at the prompt.
If you run git-bash.bat from Portable git, it should work mostly as normal git installation. So, to work with a specific repository, just cd into it:
cd /c/code/MyRepo/
git whatever
I've added
cd /c/dev
to
~/.bashrc
with
echo cd /c/dev >> ~/.bashrc
But I'm running MSysGit the non-portable version. Hope this helps in some way anyway.
First off I am very very new to shell scripting. I am trying to write a script that takes in one parameter and then copies a folder in a different directory naming it using the parameter. This is the current code that I have:
#!/bin/sh
cd /var/www/html/fbplugin/chrome
sudo mkdir temp/$1
sudo cp -rf "/var/www/html/fbplugin/chrome/fbplugin" "/var/www/html/fbplugin/chrome/temp/$1"
When I run this code it says can't cd to /var/www/html/fbplugin/chrome. I'm not sure why it is saying this because I know the directory exists. I have copied the line directly and it works in terminal. If anyone could help me out that would be great.
If it matters in order to run the script I am typing "sh build.sh"
If that directory really exists, then you must have executed that script with a different user (cron, webserver, etc).
Check the rights for that directory.
I don't know why you're getting the error about cd, but it looks like you could just use absolute paths throughout. That would solve the larger problem of the script working correctly.