Deleting spotify folder at startup - bash

I have installed spotify on my ubuntu 12.04 machine. When I start Spotify it simply closes. I found a way to circumvent this problem in some forum: simply remove the folder ~/.cache/spotify
It is however rather annoying that I have to delete this folder every time I want to use Spotify.
My question is, is there a way to tell Ubuntu that it should delete this folder and its content when I start my computer? And if so, how do I do that?
My idea is to add something like the following to the .bashrc file
if [ -d ~/.cache/spotify ]; then
rmdir ~/.cache/spotify
fi

If you need to execute one task at the linux startup I suggest to use /etc/rc.local file.
However, given this is only a workaround you can modify the startup-script of spotfiy adding the rm -rf /home/your_username/.cache/spotify before the actual execurion of the program.

You can set up a simple alias:
alias spotify="rm -rf ~/.cache/spotify && spotify"
Add this to your .bashrc file and every time you run spotify, the cache directory is first deleted (or ignored if it doesn't exist).

what version of Spotify are you using? What happens if you set the maximum size for cache in the Preferences to 0?

Related

Change directory where git bash launches without shortcut or modifying $HOME

The company I work for has a code repository deep within a folder structure, the path of which I have saved in a text file. As I was copying that path from notepad++ and pasting it into a cd command for the hundredth time after launching git bash I began to get the feeling that I was wasting time. Being the good programmer that I am, spending an hour researching how to do something programmatically is obviously preferable to doing something that takes four seconds over and over again. However I have been disappointed to find that all of the readily-available solutions offer one of two recommendations which both feel more like workarounds than an actual config change:
Create a shortcut and modify the "start in" field. This is not acceptable for me because I launch git from the start menu (windows key + type "git"). I don't want to add the extra steps of navigating to the folder where I created the shortcut. Even if I give the shortcut a unique name such as "stupidshortcutname", I am not able to access this shortcut by searching in the windows start menu.
Modify the Windows environment variable HOME. This is not acceptable because I still want cmd to launch in its default location of C:\Users\MyUserNameHere.
With some further research I also found the option of creating a file called .bashrc in my C:\Users\MyUserNameHere directory, and having this run cd <folder I want to go to>, but this still feels pretty hacky for something that I feel should be a configuration somewhere.
Git has its own config files, I would be shocked if none of them allowed for setting the location git will default to launching in. Am I out of luck and/or being too picky?
Create a batch file with name like LaunchGit.bat & write the following command:
start F:\Program" "Files\Git\git-bash.exe --cd=D:\your\deep\workspace\path
Now you can launch it from desktop or place it in your Git home directory (and launch from there)
This may not be the most perfect solution, but it will solve your problem.
And ofCouse this is just an idea and you can change/improve it.
Use git-bash configuration to change the directory, if this is what you want.
In ~/.bash_profile (create it if it does not exist), add
cd /path/to/git/repository
The reason to use ~/.bash_profile instead of ~/.bashrc is because the latter is read and executed when an interactive shell that is not a login shell is started (if exists).

File disappeared after trying to move it in terminal

Can anyone tell me where my file may have gone after this command?
The file I'm missing is stats.cpp
And what is the correct command to move it from directory prog3a to prog3c?
Thank you.
Since you did not post the actual command you used I cannot tell you what happened to the file. What I can say is that unless you used the rm command, the file is not gone. Probably got its name changed if you cannot find it or it got moved somewhere else other than the intended destination.
The correct command you should use is
mv prog3a/stats.cpp prog3c/stats.cpp
This command should be run in the directory where both prog3a and prog3c folders exist (cd to it before running the command. This is assuming they're both inside the same directory).
A more specific answer can be provided if you tell us which command you initially ran specifically and the full paths of each folder.

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

Vim Can't Save File (E212)

Sometimes when I create a file using vim some/path/newfile, vim lets me edit it, only to complain when I attempt to save my changes.
E212 Can't open file for writing.
This appears to happen only when the new file is located in a system directory.
:w! does not override this error.
How can I write the current buffer, without having to save it to a temporary location, exit, then rename it using sudo?
This will ask you for the root password, then save your changes as you requested:
:w !sudo tee %
Then type (L)oad at the prompt, to re-load the file after it is saved.
You can mkdir first, then save it.
Add this line to your .vimrc:
cmap w!! %!sudo tee > /dev/null
and then you can do
:w!!
when you get into this position, and it will write the file using sudo. Very handy.
You can avoid this problem by using "sudo" to start the editing session.
sudo vi name-of-file
If you want a robust, easy-to-remember solution and don't mind installing a plugin, try SudoEdit.vim - Edit Files using sudo or su or any other tool.
If this is the case in Windows 7 or later editions, run the VI editor as Administrator. Right Click of the application and select "Run as Administrator". This issue will be resolved. Moreover, the error is due to Administrative Privileges.
vim some/path/newfile
you can try to do it in two steps,first create the folder 'some' and 'path' by use mkdir ~ ;second you go into the 'path' folder,use the command:sudo vim newfile.then save it
Make sure the directory where you are trying to save the file exists and that you have permission to edit the file.
You can type :help message in Vim to get more information on this and other error messages. Try searching by typing /E212 once the docs come up. You can also view the documentation online at http://vimdoc.sourceforge.net/htmldoc/message.html and CTRL-F to find it.
For what it's worth, you may also want to ensure you have sufficient storage in the partition where you're attempting to save the file. I had to free up some space in my /home drive and that resolved the issue.
I know this is an old question, but this is what fixed it for me. Your file might be set to immutable meaning that you can't edit it.
You can check this with lsattr /path/to/file.txt
If it is use
chattr -i /etc/resolv.conf to make it no longer immutable.
Just had this issue outside of system directory.
When I tried to open a file vim src/help/tips.c. Turns out help directory did not exist, the directory was named differently and it was one of those very rare occasions that I did not auto-complete with Tab.
So, in conclusion, if this happens for a file that is not at a place where you may have permission issues, look if the path leading up to the file is a valid one.
I have experienced this in Kali!! The default account requires escalation to root with "sudo" in order for the file to be editable.
e.g: sudo vim / at this point all standard expectations appear to follow.

Terminal redirection command

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 :)

Resources