I'm trying to create files with names such as: asterisk, pipe, uppercase letters and lowercase letters but Windows doesn't allow me for that. Is there command for enabling such feature? I'm using NTFS file system.
I tried using WSL and it didn't work, when I tried creating file using touch a.txt and touch A.txt and it didn't create second file named A.txt.
I don't think you can do it for at least these forbidden characters \ / : * ? " < > |. Window by default will not allow you to do that by any means.
Related
I'm writing a basic shell script that creates directories and changes directories to that folder to write in it.
Right now I have the following:
mkdir -p "Home/first/second/third"
cd "Home/first/second/third"
This produces undesired results as the file structure looks as follows:
- Home
- first
- second
- third\r
I'm looking to get rid of the \r on the third\r but am unsure why it is doing so. I've tried a ton of different variations and can't seem to figure out what the issue is with adding that extra \r
Are you sure that's the exact script?
Because the mkdir -p "Home/first/second/third" should and does create a structure like.
Home
- first
- second
- third
You do need to clarify what OS and shell you are using.
Did you create the file on the host or copy it to the host from a windows machine?
-EDIT
Use
dos2unix script.sh
to get rid of those pesky \r characters that windows put in.
Credit to #Klox for figuring this out.
Files edited on a Windows computer end in \r\n, while files edited on Linux computers end in \n.
Therefore, despite the code being compiled on Linux, it still ends created files with \r\n, causing the last directory created in a mkdir to end with \r. In order to remove this \r, files must be written in the linux environment.
I have a perl script that takes input file path from the terminal. So, while entering the file path, I can drag and drop the file to the terminal (Mac). If I have file paths like
/Users/San/abc(ev50)_xyz.tif,
then dragging and dropping the file will result in
/Users/San/abc\(ev50\)_xyz.tif
being pasted on the terminal. Is there a way to copy paste (drag and drop) the file path as is? I saw in some of the forums, they had mentioned about creating a service and so on. But, I want to know if there is an easy way to paste it as is.
Drag/drop enters the filename, with characters that might present problems to shell scripts escaped with backslashes (such as bash). Reading the filename directly, you of course do not have this problem. The solution is to remove the extra backslashes, e.g., as done in #Ether's answer to How can I unescape backslashes in a Perl string?.
I have a document I want to find using the terminal on my mac. While using the cd and ls and tab tab commands, what is the command to search for a folder or document in terminal?
Thus, to locate a file typically found on an HFS Extended volume on a server that has netboot clients, enter:
find / -name "Mac NC #" -print &
This should return all occurrences of files or directories on "/" whose names include the string specified in quotes, and print it to standard io (the screen). The ampersand "&" specifies to do this in the background.
Note: In this example, the search string is in quotes; these quotes are necessary because of the space characters included in the string. Searching for a name that is all one word with no illegal characters, such as "hostconfig", does not require quotes. As in traditional BSD unix, the backslash character, "\", may be used before an illegal character to cause it to be parsed as part of the search string:
find / -name Mac\\ NC\\ # -print &
You can also use the "locate" command, which is easy to use and faster than find. Simply type "locate" followed by the name or part of a name of files you are looking for and press Return. You should get a list displaying the paths to those files. The locate command searches a database of files on the drive, which can get out of date. If you are searching for a file that you know exists but is not found, you can run the 'weekly' script manually to update this database. To do so type the following command:
sudo sh /etc/weekly
Press Return, enter your password, and the weekly script will run and update your locate database.
Execute "man find" or "man locate" at the command line to get more information on using these commands.
source: http://support.apple.com/kb/TA25275
I have written a batch script that logs into my ftp server, then navigates to a directory. I am having trouble with the mget command, I want it to download every .dat file in the directory, but it simply returns this error:
Cannot access file '/home/minecraft/multicraft/servers/server267/world/players/*.dat':No such file or directory.
200 Type set to: ANSI
Cannot find list of remote files
Here is my script (ran from cmd)
open 66.71.244.202
USER
PASSWORD
cd /world
cd players
mget *.dat
That is by design. The most recent update to the FTP specification (RFC 3659) explicitly forbids it (see section 2.2.2):
For the commands defined in this specification, all pathnames are to be treated literally. That is, for a pathname given as a parameter to a command, the file whose name is identical to the pathname given is implied. No characters from the pathname may be treated as special or "magic", thus no pattern matching (other than for exact equality) between the pathname given and the files present in the NVFS of the server-FTP is permitted.
Clients that desire some form of pattern matching functionality must obtain a listing of the relevant directory, or directories, and implement their own file name selection procedures.
When you execute your script file with ftp, you have to turn off the globbing which will allow the use of wildcards in the script. For example:
ftp -n -i -s:scriptfile.txt
should work but
ftp -n -i -g -s:scriptfile.txt
will not.
I know this is old, but it might help someone. I had the same issue with wildcards on MGET from Windows FTP, but it was not consistent in that it worked talking to some remote systems, but not to all of them.
My script was doing this:
cd /folder/folder
mget ./-400TA/folder/*_XYZ
In the folder structure I have a set of different folders that begin with hyphens, and for whatever reason the script CD's down to just above there, and uses the relative path in the MGET. I had the same issue that some of you reported, that if I connected interactively and typed the commands one by one, it worked. But in batch, it didn't.
I followed the suggestions in this and other posts, but no joy. I don't have access to the remote systems at the moment to look at them to figure out why some worked and some didn't.
However, what I did find was this. Changing my script as follows:
cd /folder/folder/-400TA/folder
mget *_XYZ
did the trick. Simple. There's some strange interaction going on somewhere possibly with folder protections or something, but it just shows that trying out different things may get you there in the end.
I would make sure glob is on, when turned off the file name in the put and get commands is taken literally and wildcards will not be looked at.
More info:
glob:Toggle filename expansion for mdelete, mget and mput. If globbing
is turned off with glob, the file name arguments are taken literally
and not expanded. Globbing for mput is done as in csh. For mdelete and
mget, each remote file name is expanded separately on the remote
machine and the lists are not merged. Expansion of a directory name is
likely to be different from expansion of the name of an ordinary file:
the exact result depends on the foreign operating system and ftp
server, and can be previewed by doing ‘mls remote-files -’ Note: mget
and mput are not meant to transfer entire directory subtrees of files.
That can be done by transferring a tar archive of the subtree (in
binary mode).
Once you are inside your ftp try to check the glob and set it on if it is off. The default behaviour is on, from the command line when connecting to ftp with the option -g you can turn off the file name globbing.
It could very well also be a firewall issue where it is not permitting or forwarding the servers inbound connection. Happened to me.
To create a playlist for all of the music in a folder, I am using the following command in bash:
ls > list.txt
I would like to use the result of the pwd command for the name of the playlist.
Something like:
ls > ${pwd}.txt
That doesn't work though - can anyone tell me what syntax I need to use to do something like this?
Edit: As mentioned in the comments pwd will end up giving an absolute path, so my playlist will end up being named .txt in some directory - d'oh! So I'll have to trim the path. Thanks for spotting that - I would probably have spent ages wondering where my files went!
The best way to do this is with "$(command substitution)" (thanks, Landon):
ls > "$(pwd).txt"
You will sometimes also see people use the older backtick notation, but this has several drawbacks in terms of nesting and escaping:
ls > "`pwd`.txt"
Note that the unprocessed substitution of pwd is an absolute path, so the above command creates a file with the same name in the same directory as the working directory, but with a .txt extension. Thomas Kammeyer pointed out that the basename command strips the leading directory, so this would create a text file in the current directory with the name of that directory:
ls > "$(basename "$(pwd)").txt"
Also thanks to erichui for bringing up the problem of spaces in the path.
This is equivalent to the backtick solution:
ls > $(pwd).txt
To do literally what you said, you could try:
ls > `pwd`.txt
which will use the full pathname, which should be fine.
Note that if you do this in your home directory, which might
be in /home/hoboben, you will be trying the create /home/hoboben.txt,
a text file in the directory above.
Is this what you wanted?
If you wanted the directory to contain a file named after it, you would get
the basename of the current directory and append that with .txt to the pwd.
Now, rather than use the pwd command... why not use the PWD environment variable?
For example:
ls > $PWD.txt
or
ls > ${PWD}.txt
is probably what you were trying to remember with your second example.
If you're in /home/hoboben and you want to create /home/hoboben/hoboben.txt, try:
ls > ${PWD}/${PWD##*/}.txt
If you do this, the file will contain its own name, so most often, you would remedy this in one of a few ways. You could redirect to somewhere else and move the file or name the file beginning with a dot to hide it from the ls command as long as you don't use the -a flag (and then optionally rename the resulting file).
I write my own scripts to manage a directory hierarchy of music files and I use subdirectories named ".info", for example, to contain track data in some spare files (basically, I "hide" metadata this way). It works out okay because my needs are simple and my collection small.
I suspect the problem may be that there are spaces in one of the directory names. For example, if your working directory is "/home/user/music/artist name". Bash will be confused thinking that you are trying to redirect to /home/user/music/artist and name.txt. You can fix this with double quotes
ls > "$(pwd).txt"
Also, you may not want to redirect to $(pwd).txt. In the example above, you would be redirecting the output to the file "/home/user/music/artist name.txt"
The syntax is:
ls > `pwd`.txt
That is the '`' character up underneath the '~', not the regular single quote.
Using the above method will create the files one level above your current directory. If you want the play lists to all go to one directory you'd need to do something like:
#!/bin/sh
MYVAR=`pwd | sed "s|/|_|g"`
ls > /playlistdir/$MYVAR-list.txt
to strip all but the directory name
ls >/playlistdir/${PWD##/*}.txt
this is probably not what you want because then you don't know where the files are (unless you change the ls command)
to replace "/" with "_"
ls >/playlistdir/${PWD//\//_}.txt
but then the playlist would look ugly and maybe not even fit in the selection window
So this will give you both a short readable name and usable paths inside the file
ext=.mp3 #leave blank for all files
for FILE in "$PWD/*$ext"; do echo "$FILE";done >/playlistdir/${PWD##/*}.txt