Deleting a Non-existing file - linux

First things first:
I have a windows OS.
I use python in Linux (from a USB stick)
I was writing a code in Python that required it to work with Excel...
so once I created it (in Linux) I got a xlwt file created in the D: drive of my computer.
when I booted into windows I wanted to delete the file but it says
The file you specified is not valid or is too long
so I tried deleting it in command prompt(admin) but it says file does not exist!
when I type dir the file gets displayed
so I went in Linux(Kali Linux) and tried
rm -f xlwt
but same problem:
when I say dir in Linux it says xlwt\r
so I said
rm -f xlwt\r
but still the same problem.

In Linux use tab completion to get the correct escaped version of the file name.
Type the following:
rm xlw
Then press the Tab key and the shell will complete the filename with the right escape chars for the '/r'
You should then be able to press enter to delete the file

Related

Open Sublime from cmd windows 10

I can't open the sublime application or any file via within sublime from the command line. I am currently using Git Bash(SDK-64). I followed this tutorial. I am stumped I am still getting the bash error. bash: subl.exe: command not found
Are you sure, you have Program File folder in C directory? As far as I know C directory has Program Files folder. Add s in Program File.
Write C:\Program Files\Sublime Text 3 instead of C:\\Program File\Sublime Text 3. It should work.
Is necessary to only add your Sublime directory path to the Path list, as you have done in your first pic and use only one "/".
Second step from last picture is not necessary.
Sublime will open with "subl.exe" and can take as argument the name of a file. "subl.exe dummy.txt".
I checked in Git Bash, Powershell and Developer Command Prompt for VS 2017 on win 10.

my npm is broken - Cannot read property 'get' of undefined

I have visual studio 2017 and wanted to make a Cordova app. I have had many problems with it now and have found a problem. Right now I run windows 10 and have installed nodejs but npm does not work. I have tested with different command but I always get the same mistake. I have canceled Node but I can not drive.
Just posting this here to help any future wanderers,
In my case the actual issue was due to the presence of a space in my windows user name folder. Which was also clear by looking at the first line of the stack trace,
Error: EPERM: operation not permitted, mkdir 'C:\Users\FirstName'
Since there is no directory present named FirstName and the actual directory was supposed to be FirstName LastName its trying to run mkdir, for which its getting operation not permitted.
Following is how i fixed it thanks to citoreek, g8up & gijswijs
run npm config edit to edit your config, this will open up a text file in notepad or your configured editor,
then change cache path from
; cache=C:\Users\Gijs van Dam\AppData\Roaming\npm-cache
to
cache=C:\Users\GIJSVA~1\AppData\Roaming\npm-cache
Remember to remove the ; at the start,
next question would be how do we know to replace our user name with GIJSVA~1?
There are a couple of ways to target this,
Go to C:\Users open power Shell and execute following command
cmd /c dir /x
what this does is, list down all the directories in current directory along with their short names which aren't supposed to contain any spaces and normally are 6 characters or less in length. Copy that short name against your user name directory and use this in your cache path.
You will notice these short names only exist for directories either containing spaces or which are longer than 6 characters. (for the rest of the directories their short names should be same as their directory name)
If you don't want to use above command, then simply remove all the spaces from your user name in your cache path, then take the first 6 characters of the user directory name and postfix it with ~1. You should also uppercase it, but it appears not to be making any difference.
After you are done with editing this file, save your changes then try again after closing any active power shell / bash process and reopening them.
I apologize for my question. I just needed to reboot the windows.
In my case this was a permissions problem with the ~/.np* files and directories. These were owned by root by mistake. I did
sudo find "~/.np*" -exec chown myuser {} \;
and that solved it.
base path is specified in the file
.npmrc

Location of .bashrc for "Bash on Ubuntu on Windows" in Windows 10

Microsoft just introduced a Linux subsystem in its Windows 10 Anniversary Edition. The installation is pretty straight forward, but I could not locate bash files on Windows.
How does it work? What does ~ refer to in Windows? Where to find .bashrc?
Since the Windows 10 Fall Creators Update, the location changed to:
C:\Users\USERNAME\AppData\Local\Packages\{DIST}\LocalState\rootfs\home\{LINUXUSER}\
Where:
{DIST} is equal to CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
{LINUXUSER} is the user for which you are looking for the .bashrc file
Just for anyone wondering that came here from Google.
Sorry for the misunderstanding, I check on google and it will be at C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME .
I tried and it works, in the cmd just type cd\ && dir *bashrc* /s it will locate the file, and in my case i see the line C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME but when I want to navigate it with the window browser it doesn't work, but if you copy paste it, it works :-)
I found it here.
Considering that you need to know where a file is located you can use the find command.
The syntax of the command is find {search-path} {file-names-to-search} {action-to-take}by default the action to take is printing the file name.
So if you are finding .bashrc file you can use find / -name .bashrc the bash will return you /home/yourusername/.bashrc
Also, if you want to access to your home directory you can use cd ~
Hope my answer will be helpful :-)
just type
vi ~/.bashrc
and that should put you into the file where ever it is.
You can navigate there simply by doing cd ~
List all files with ls -a and you should be able to see it.
~ means that is user home folder, way like /home/%username%/
you can list files like ls -al and see .bashrc file.
Right now on WSL 2 you can find it under /home/{user_name} and the file is hidden.
You can access it from Ubuntu console by {text_editor} .bashrc
If you want to edit that in Windows just type in ubuntu console explorer.exe . and it opens the current folder and shows all hidden files.
It's weird but works fine.
Other answers doesn't work for me using WSL 2.
The LocalState folder contains a virtual disk so rootfs does not exist,
and AppData\Local folder does not have the Lxss folder.
The solution for me is surprisingly simple:
wsl -u root
This will allow you to get into wsl as root.
From here, you have access to the whole linux.
Fix the .bashrc or anything you want.
Don't screw up the root user. :)
I find my .bashrc file in:
/home/your_user_name
you can run cd /home/your_user_name or cd ~ should work as well
If you previously installed git bash for window, you may also find .bashrc file in your window user profile folder. In Linux subsystem, you may local the file under /mnt/c/Users/your_window_user_name/.bashrc However, modifying that file only works for git bash in window but not for the shell terminal of the Linux subsystem.
Note: my installation of the Ubuntu is 20.04 LTS straight from window store.

cant delete file using variable name in shell script

I want to delete a file whose name is stored in a variable, but it doesn't work. I'm getting
A file or Directory in the path name does not exist
My code is
value=$(<try_text.txt)
rm -f /home/inform/output/$value
when i tried deleting i got :
cannot remove `/home/oracle/Omar2/B2BFiles/bm.txt\r': No such file or directory
where does the \r come from ?
It comes from an editor which wrote the Windows line ending \r\n to try_text.txt. When reading that file, the Linux shell removed the Unix line ending \n, and the \r remained. To get rid of it, see e. g. the answers to the question Line ending issue DOS > Linux > Java.
Try this:
value=try_text.txt
rm -f /home/inform/output/$value
Don't run the value variable in a subshell when it's not needed.
EDIT
Previously misunderstood the question, didn't see the '<'.
This works on my system:
value=$(</home/user/Documents/try_text.txt)
rm -f /home/user/Documents/$value
as #gile said, make sure the try_text.txt is in your working directory.

how to make cygwin build program in windows use windows path

I built and installed a program with cygwin in windows, but the program can not find windows style paths and must use /cygdrive
I just want to know how to spare this burden
The problem is this:
C:\Documents and Settings\Administrator>protoc -If:
f: warning: directory does not exist.
Missing input file.
C:\Documents and Settings\Administrator>protoc -I/cygdrive/f
Missing input file.
This is the common problem with windows stuff, it always uses spaces in paths. Two solutions:
1st. Open your cygwin (black one) terminal and type (I suppose you will be in your home directory):
cp /etc/dev/etc/skel/.bash* .
this will copy all the bash files you need to your current directory to "handle" your cygwin system. To know where you are in your cygwin (ie. the path to your current directory) type "pwd" (without the quotes) and press Enter (or Return for some people).
2nd. Open the .bashrc file already copied and type (I use "vi" editor for this but you can use "pico" which is a bit easier):
alias C="C:\Documents\ and\ Settings\Administrator"
save the .bashrc ("Ctrl+X" in pico I think, and :wq in "vi") and close the terminal. After restarting this console, typing "C" and pressing enter will send you automatically to "C:\Documents and Settings\Administrator"
To know which alias you have, just type "alias" in your terminal and all your alias will show up.
HTH,

Resources