Recently I downloaded some files from a website, but their names contain strange unicode characters, which my console doesn't show them properly. Now I want to rename these files to be able to use these files, but I get the following error:
mv: cannot stat`FILENAME': No such file or directory
But I am sure that these files exist.
I wonder how I can rename these files, properly.
Any ideas?
Using globbing characters (like ? or *): mv *some-typeable-and-unique-substring* ...
Using the tab-completion of your favourite shell: your start typing mv, then the beginning of the filename, then you press TAB, and then you can enter the second parameter.
If there are other files in that directory, you might have to move them to another directory to be able to use the tab-completion or the wildcards.
Related
I accidently renamed all of my files by adding a prefix multiple times to each directory. I have tried the "rename" command and some peal scripting but I still can't resolve name changes. Any ideas on how to remove all the dates at once so that I just have directory?
Example
mv 2020-11-30-2020-11-30...2020-11-30-Documents Documents/
mv 2020-11-30-2020-11-30...2020-11-30-Documents Documents/
Assuming your filenames don't contain linebreak, quotes. or other special chars:
\ls -1|sed 's/.*-\(.*\)/mv "&" "\1"/'
You can check the output produced by the above command, if it looks good, pipe the output to |sh
NOTE: the backslash before ls is for ignoring your alias if you had ls alias.
These commands both worked:
ls -1 | sed 's/.*-\(.*\)/mv "&" "\1"/'
rename 's/2020-11-30-//g' 2020-11-30-*
Here is a solution which does not require the use of regex. Based on vimv and the multi-cursor edition in Vscode:
Both packages are shipped in most Linux distributions:
apt install vimv codium
Open a terminal and setup codium as your editor: export EDITOR="codium -w"
Browse the terminal in the appropriate folder and type vimv. Hit enter
Vscodium opens, and shows the list of files and folders
Add cursors where you want. Quoting from the doc:
You can add secondary cursors (rendered thinner) with Alt+Click. Another
common way to add more cursors is with Shift+Alt+Down or Shift+Alt+Up
that insert cursors below or above.
Delete whatever you want, save the file, and exit
The files and folders should be renamed accordingly
Checkout the website of vimv for more informations and screencasts
I'm setting MariaDB with Linux up.
And I was going to edit property "bind-address" to accept external connection.
So I need to edit 'my.cnf' file. I found this file and tried to "vi my.cnf" and my linux shows
where can I find "bind_address" property and edit it?
Did i find right file?
From the last two lines in this file, you can see that it loads all the files in /etc/mysql/conf.d/ and /etc/mysql/mariadb.conf.d/. So you also have to look in those directories for a files that have a "bind-address" line.
You can look for "bind-address" automatically using the following command:
grep -r 'bind-address' /etc/mysql/conf.d/ /etc/mysql/mariadb.conf.d/
This command looks for lines containing "bind-address" in all the files in each directory, and for each matching line it will print the filename and the line. You can then edit the files that it finds using your favourite text editor.
When I build/update my tags file, ctags starts at the current directory and works its way down recursively.
I would like for it to also include a completely different search path, a mapped network drive, and add those results to my tags file as well.
Is there any way to do that?
When the files in the other directory are related and often change together with the current directory hierarchy, I'd write a custom :Ctags command that supplies the other path to the :!ctags call.
If the other files are unrelated, and rarely update (as based on your comments seems to be the case), I'd run ctags there separately and include them via
:set tags+=/path/to/other/dir/tags
NOTE: Add the tag filename at the end, else there will be "tag not found" error. By default the name is tags but it could be renamed with -f option as below.
ctags -f my_tags -R
:set tags+=/path/to/other/dir/my_tags
I just installed ctags via homebrew and appended the following line in my ~/.vimrc:
set tags=./tags,tags;$HOME
And then I ran /usr/local/bin/ctags -R . on some of my directories and opened some files stored in the directories, then some of those scripts succeeded in importing tags file but others didn't.
For example, I opened up test.py on my Python workspace, which I already run the above command in, and then I tried to put Ctrl+] on my GVim, it looks like successfully imported the tags file.
I also opened up hello.go located in ~/go/src/github.com/user/hello, in which I already executed the above ctags command, successfully imported the tags file. However, my test.rb file, which I just put on the Go's directory in order to do test purpose, didn't import the tags file correctly.
Also, when I executed the ctags command on ~/another_go_workspace/src, and then opened up the file located in ~/another_go_workspace/src/hello/hello.go, then the file didn't import the tags file... However, since I appended set tags=./tags,tags;$HOME on my ~/.vimrc, doesn't it automatically look for higher directories, right?
So what am I missing?
And if it doesn't import the tags file in higher directories, do I have to execute the ctag command on EVERY directory, i.e. on ~/go/src/soccer_analysis, ~/go/src/coffee, ~/go/src/utility, etc, etc... ?
Thanks.
Your value for the tags option is correct and your assumptions about its behaviour are correct too.
With your setting, set tags=./tags,tags;$HOME, Vim will search for a tags file in the directory of the current file first then for a tags file from the working directory upward to $HOME.
This allows you to generate a tags file at the root of your project and be sure that Vim will pick it up wherever you are in your project and whatever the working directory is.
With the following structure and your current settings:
project/
bar/
bar.js
foo/
foo.js
project.js
tags
Vim should find tags in all the following scenarios and their variants:
$ vim project.js
$ cd foo && vim foo.js
$ cd bar && vim bar.js
$ vim foo/foo.js
$ vim bar/bar.js
$ cd bar && vim bar.js ../project.js
Every time you add a new file to your project or write to an existing file, you must re-index your whole project. From what you wrote about the ruby file, it looks like you didn't run ctags after adding the file. Try this for a selection of files in your project: :echo tagfiles().
No, vim doesn't go up directories to find tags files. I recommend you start vim from the top level directory (where you generated your tags), then traverse to whatever file you want.
vim go/src/coffee
Vim is capable of navigating filesystems nicely with commands like :Explore.
EDIT: I was wrong, semicolon can be used to search upwards. See :help file-searching
Also, I noticed that you tried to add $HOME to your tags, which isn't going to work for a number of reasons.
Documentation (:help 'tags') says:
Filenames for the tag command, separated by spaces or commas.
Therefore:
The delimiter is incorrect
$HOME is going to be treated like a tags file
So the "correct" way of doing this would be:
set tags=./tags,tags,$HOME/tags
Even if you do that though, I don't think it's going to work. Tags files comprise primarily of 2 elements, a search pattern and a filename. If you generated the file from the top, all filenames will be relative to that directory.
So if you are deep down in some subdir, vim will try to open the file using the relative filepath from the top, starting at that subdir.
The problem may have been caused by a typo. I think
set tags=./tags,tags;$HOME
should be
set tags=./tags;,tags;$HOME
Is there a way to open all the files in a directory from within Vim? So a :command that would say in effect "Open all the files under /some/path into buffers".
Ideally, it would be great to open all the files under a dir recursively.
The command you are looking for is args:
For example:
:args /path_to_dir/*
will open all files in the directory
Why it doesn't work if I want to open all files ending with a certain extension?
I tried
:n ./**.cs
and opens only the files in the currenty directory.
I found the answer.The correct code is :n **/*.cs
For more information :h find
Did you try
:n /some/path/*
It will open all files in /some/path
I don't think it'll open file recursively though.
EDIT
Maybe using ** will open recursively as daf mentionned
A method that doesn't require messing with args is to put the list of files in a text file, and then use the :so command to run the commands in that file.
For example, if you want to open all the files that end in .php in a given directory, first create files.txt containing the list of files, prepended with whatever command you want to use to open them.
sp alpha.php
sp bravo.php
sp charlie.php
Then, within vim:
:so files.txt
If the list of files is large, it's relatively trivial to generate the files.txt file quickly, by redirecting the output of ls to a file, and then using a vim macro to prepend sp before each filename.
This obviously isn't as elegant as using the args and argdo commands, but those commands are also a lot more complicated.
There also might be a way to do this with a single command on the command line, but even after 16 years I still find vim programming to be strange and arcane.
Another way to open files recursively
find . -type f -exec vi {} \;
If you'd like to add to the argument list;
:arga what_you-d_like_to_add
see
:he arga
from/in vim for more information.