How to delete folder/files from Databricks mnt directory - databricks

I am running Databricks Community Edition and I would like to delete files from the following mnt directory
/mnt/driver-daemon/jars
I run the dbutils command:
dbutils.fs.rm('/mnt/driver-daemon/jars/', True)
However, when I run the command I get the following message (which basically means the folder hasn't been deleted)
Out[1]: False
Can someone let me know where I going wrong?
Ideally, I would like to delete all the files in the jars folder, however, if someone could just help showing how to delete the folder, that will suffice.

If dbutils.fs.rm() does not work you can always use the the %fs FileSystem magic commands. To remove a director you can use the following.
%fs rm -r /mnt/driver-daemon/jars/
where
%fs magic command to use dbutils
rm remove command
-r recursive flag to delete a directory and all its contents
/mnt/driver-daemon/jars/ path to directory

If you are referring to local /mnt/driver-daemon/jars ,it wouldn't be good idea to remove it since it is symlink to /databricks/jars directory and would impact driver functionality. The path /mnt/driver-daemon/jars/ resolves to dbfs:/mnt/driver-daemon/jars/ whose equivalent local file system directory /dbfs/mnt/driver-daemon/jars. If you want to delete local file system directories, you can prefix file: schema before the path (like file:/tmp/deleteme) with dbutils commands.
%sh ls -ltrh /dbfs/mnt/driver-daemon/jars /mnt/driver-daemon/jars
ls: cannot access '/dbfs/mnt/driver-daemon/jars': No such file or directory
lrwxrwxrwx 1 root root 16 Jul 2 23:14 /mnt/driver-daemon/jars -> /databricks/jars

Related

chmod cannot access to 'uploads/' :file or folder doesn't exist

i did this
sudo chmod -R 775 uploads/
and got this
chmod cannot access to 'uploads/' :file or folder doesn't exist
Your command is syntactically correct. The reason why it is reporting file or folder doesn't exist will be that the file or folder doesn't exist.
As you are using a relative path, you may wish to ensure that the current directory when you type the command is the parent directory of where you expect the uploads directory to reside. Note in particular that sudo will run the chmod command from the existing current directory (for example, it would not change to the home directory of the root user merely because it is running the command as root).
If you wish to check whether uploads is a valid path relative to the current directory, then use the ls command (without command-line arguments) to list the contents of the current directory, and see whether uploads (case-sensitive) is mentioned in the output.

Cannot create directory in tmp(overthewire bandit24)

I'm trying to solve bandit24 on overthe wire on ubuntu virtual machine.
I have already seen the solution.
But i have a problem,when i try to create a directory on tmp as bandit24#bandit i get this message:
Cannot create directory "name_of_directory": file exists.
If I try with find command there is only the "." directory and with ls I get the message:
Cannot open directory '.' : permission denied.
I also have tried with ls -l on tmp and I get the message:
Cannot open directory 'tmp': Permission denied
What else could I do?
What could be the problem?
Try to prepend sudo at your command. Seems you don't have permissions to read the /tmp directory, what is pretty weird.
Example that might works:
To list the /tmp contents:
sudo ls -l /tmp
To create the 'my_new_dir' inside /tmp:
sudo mkdir /tmp/my_new_dir
It means that there is a directory under /tmp/ with the same name that you specified. But since you did not create it (in this case, someone created with a different bandit user), you cannot view it. There is not read permission for bandit24 to access it.
Since /tmp/ is directory accessible for all user accounts, you cannot list the files/directories under it without the root permission. (Which means the root of the bandit machine has configured like that)
What you need to do
Try a random name. Create anything random under /tmp/. It will work.

Files get copied and renamed but I also get errors

I have a script that reads a text file that has all the nodes listed in there:
node1
node2
node3
.
.
.
It creates a ".conf" file for each node in the /etc/icinga2/zones.d/master/hosts/new/ directory
Copies the content of the file name linux-template into each new conf file.
Everything worked as I expected, but I also get errors for each node:
Can anyone please help?
Thanks
This is my script:
#!/bin/bash
cd /etc/icinga2/zones.d/master/hosts/new
while read f; do
cp -v "$f" /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
cp linux-template.conf "$f.conf"
chown icinga:icinga "$f.conf"
done < linux-list.txt
Once everything got copied, I get these errors below (for all the nodes, ie. node 1):
cp: cannot stat ‘node1’: No such file or directory
chown: cannot access ‘node1’: No such file or directory
It looks like it's complaining because there isn't a file called "node1" in your directory and you have verbose mode on.
This script looks like it will also cause undesired behavior if you're not located in the /etc/icinga2/zones.d/master/hosts/new/ directory when you run it.
The script is saying:
Copy files node1,node2,... in my current directory and place the
copy here: /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
Copy linux-template.conf from the current directory and name it "node[1-9].conf" in the current directory.
Chown the "node[1-9].conf" in the current directory.
I suggest using absolute paths and I'm not quite sure why the first cp is necessary. If you're intending to copy linux-template.conf into each node[1-9].conf that you created in step 1, the second copy will create and overwrite the file anyway and step 1 would not be needed.

Difference between ./usr and /usr when running a command

I have two directories in my new CentOS7:
Work_Folder1/my_project/linux_dev.cfg
Work_Folder2/my_project/linux_dev.cfg
If I try to run the command ./usr/bin/buildout -c linux_dev.cfg the build works fine from dir (1). If I try the same from (2) it says the ./usr/bin/buildout not exists.
After trying I see that from (2), /usr/bin/buildout -c linux_dev.cfg command works. So whats the role of . in here?
The command ./usr/bin/buildout looks for usr folder in the current directory.. While /usr/bin/buildout looks for usr in the root folder.. You might have usr folder in root as well as Work_Folder1, but not in WorkFolder2
The . indicates that you want to start looking for the buildout executable in the directory you are currently in. So for ./usr/bin/buildout, we are looking for a usr directory under the current directory, a bin directory under that, and a buildout executable under that.
Without the dot (i.e. /usr/bin/buildout), we begin looking in the root of the filesystem (i.e. /) for a usr directory, and then bin and buildout.
I'll bet if you look in your Work_Folder1/my_project/linux_dev.cfg directory, you'll find a usr directory. If you look in Work_Folder2/my_project/linux_dev.cfg, you won't.

shell script mv is throwing unhelpful error "No such file or directory" even though i see it

I need to use a shell script to move all files in a directory into another directory. I manually did this without a problem and now scripting it is giving me an error on the mv command.
Inside the directory I want to move files out of are 2 directories, php and php.tmp. The error I get is cd: /path/to/working/directory/php: No such file or directory. I'm confused because it is there to begin with and listed when I ls the working directory.
The error I get is here:
ls $PWD #ensure the files are there
mv $PWD/* /company/home/directory
ls /company/home/directory #ensure the files are moved
When I use ls $PWD I see the directories I want to move but the error afterward says it doesn't exist. Then when I ssh to the machine this is running on I see the files were moved correctly.
If it matters the directory I am moving files from is owned by a different user but the shell is executing as root.
I don't understand why I would get this error so, any help would be great.
Add a / after the path to specify you want to move the file, not rename the directory.
You should try this:
mv $PWD/\* /home/user/directory/
Are your variables properly quoted? You could try :
ls "$PWD" #ensure the files are there
mv "$PWD"/* "/company/home/directory"
ls "/company/home/directory" #ensure the files are moved
If any of your file or directory names contains characters such as spaces or tabs, your "mv" command may not be seeing the argument list you think it is seeing.

Resources