How to copy the content of a a folder which its name is partially known in centos - linux

I have a folder which has another folder inside it (lets say test and insidetest-some random number). Now what I am trying to do is to copy the content of the insidetest-... into another folder. The problem is that I know half of the name of the folder which in test folder and I do not know the the randon number attached to it. (Just for more explanation I get the a zip file from bitbucket api and then after unzip it it has this structure. So I can never know the exact name of the folder inside test. If I knew that I could simply use sth like this:
cp home/test/* /home/myfolder/
But I cannot do it in this situation. Can anyone help?

If some part of the name is constant then use the command like this:-
cp home/test/halfname* /home/folder/ -r

Related

Python - working with unkown directory name versions

I'm using python to download an application from a content distribution network. The application downloads as self extract file cabinet. When executed it creates a directory using a version naming format. For example app-version2/../app.exe, Thus I cannot rely on the folder name as it may change in the future. I'm trying to find the best way to work with the content inside the folder without depending on the actual folder name.
My idea was to rename the folder using os.listdir() and then os.rename(app-version2, myapp) This would work but is not automated. What would be the best automated method to find a folder name that contains version numbers and change that to something more static?
Assuming you want to find the path of the directory which begins with app, you can accomplish this using pathlib.Path:
from pathlib import Path
app_path = next(Path().glob('app*'))
This will give you the path to the first file or directory in your current directory whose name begins with "app".

How can I set an universal working directory?

I'm setting up a new algorithm and I want to share it on another computer. How can I set paths with only the folder name, for example.
I've tried to use the function os.chdir(path), but I don't achieve to reach my folder when I'm not using a 'root path' like C:/../../folder.
os.chdir(../folder_name)
By doing os.chdir(../folder_name), you are referring to the parent dir of the current directory.
You probably are looking for the os.chdir(./folder_name), with one dot? This is the current directory, where your script stands.
More here: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats
Update: After clarification in the comments, you want to refer to folder_name from one of its subfolder (/folder_name/library). Then it is indeed .. that you should use, but .. only:
os.chdir(..)

Node : What is the right way to delete all the files from a directory?

So I was trying to delete all my files inside a folder using node.
I came across 2 methods .
Method 1
Delete the folder using rmkdir. But if I plan on adding the images on the same folder then I use mkdir and creates the same folder again and appends the files to it.
Example: I have an Add Files and Delete ALL button. When I click deleteAll , the folder gets deleted. And when I click add then the folder gets created and the file gets added to that folder
Method 2
Using readdir , I loop through the files and stores in an array and then delete only the files instead of the folder.
Which is the best way to do it ? If its not among these then please advice me a better solution.
The rm function of ShellJS will do the trick. It works as a one-liner, and it works cross-platform, and is well tested and documented. It even supports recursive deletes.
Basically, something such as:
const { rm } = require('shelljs');
rm('-rf', '/tmp/*');
(Sample code taken from ShellJS' documentation.)

MATLAB, Octave: working with folder names that have space in them

In MATLAB, actually Octave, I would like to find a list of all subfolders in the current folder so I use this:
subFolder = dir;
This gives the list of all subfolders in the current folder. This returns a structure whose one element is the name. Assume I have two subfolders with names subfolder 1A and subfolder 1B.
Now I want to go to these folders. Then I do this:
cd subFolder(1).name
But I get this error:
error: subFolder(1).name: No such file or directory
If I do this:
cd "subfolder 1A"
everything works fine. What is the solution?
The space in the folder name is a red herring in this case. It's not the source of the problem. The actual issue is that you need to call the cd function using function syntax instead of command syntax (i.e. use parentheses; related question here):
cd(subFolder(1).name);
When you use the command syntax, subFolder(1).name is itself being treated as the string argument to cd (i.e. it's looking for a folder called 'subFolder(1).name'). With the function syntax, the string contained within the structure array field is used as the argument.
To make your code a little more robust, you could also use the 'folder' field returned by dir:
cd(fullfile(subFolder(1).folder, subFolder(1).name));
This will go to the desired folder regardless of the directory you are currently in, since it specifies an absolute path instead of a partial path (which is relative to the current directory).

Adding files to sourcecontrol on linux using cleartool

I have a file that i want to add to sourcecontrol on linux using cleartool .
I've followed the IBM documentation for this, i've tried this:
cleartool mkelem testScript.sh
I got an error: Can't modify directory "." because it is not checked out.
I also would like to know how can i checkout/checkin files or directories and setting activities.
You need to checkout the parent folder first.
cd /path/to/file/
cleartool mkact newfile
cleartool checkout -c "add file" .
cleartool mkelem testScript.sh
cleartool checkin -nc
The cleartool mkact would work if you are in an UCM view.
It will create and set a new activity, which will record the files and folder you will modify.
Here, the new activity newFile will record the new version of the parent folder, as well as the version 0 and 1 of the file.
You should create separate questions for .. separate questions...
Going back to the original - the reason why it isn't working is, as VonC has pointed out, you haven't checked out the parent of the file. Remember, when you run "cleartool mkelem", you are about to modify the contents of the parent directory (. in this case) by adding a new "pointer" to the element you're now creating. As with everything else in clearcase, when you want to modify the contents of an element, you have to check it out first.
One of ClearCase's greatest strength (and hardest to wrap one's head around) is the concept of an "element", IMO. "Everything" behaves similarly with an element. Making any change to an "element" (file or directory) means you have to check it out first to make that change.
In the case of a file, that's easy to grasp - you're just editing lines in a file. For a directory, it's almost as easy - you can think of a directory as just a list of pointers to data blobs. We make the name of the blob something convenient we can remember (like foo.java or myapplication.cc or README.md). But we can also change the name of the pointer (even though it points to the same data blob) by renaming a file. We can remove the pointer to the blob without impacting the blob itself by using "rmname". That's essentially what "rmname" does.
In ClearCases' case, the mkelem command is a little bit special - it creates the initial datablob, and adds a pointer to that datablob in the current directory (kind of does 2 things at once).

Resources