xx#xx-PC ~/xampp/htdocs/sites
$ rmdir /s "yo-2"
rmdir: `/s': No such file or directory
rmdir: `yo-2': Directory not empty
xx#xx-PC ~/xampp/htdocs/sites
$ rmdir "yo-2"
rmdir: `yo-2': Directory not empty
I cant seem to get rmdir to work in git bash. Its not in a git repo and I've tried the above. Mkdir works as expected, why doesnt this?
rmdir will not work if directory is empty
Try
rm -rf yo-2
git-bash is a Linux like shell
If you are trying to remove an entire directory regardless of contents, you could use:
rm <dirname> -rf
just use the command below:
rm -rfv mydirectory
After trying out a couple of other commands, this worked for me:
rm dirname -rf
A bit late, but I believe it still can help someone with performance problems on Windows systems. It is REALLY FAST to delete on Windows using git bash comparing with just the ordinary rm -rf. The trick here is to move the file/directory to another random name in a temporary directory at the same drive (on Windows) or at the same partition (on *nix systems) and invoke the rm -rf command in background mode. At least you don't need to wait for a blocking IO task and OS will perform the deletion as soon it gets idle.
Depending on the system you are using you may need to install the realpath program (ie macOS). Another alternative is to write a bash portable function like in this post: bash/fish command to print absolute path to a file.
fast_rm() {
path=$(realpath $1) # getting the absolute path
echo $path
if [ -e $path ]; then
export TMPDIR="$(dirname $(mktemp -u))"
kernel=$(uname | awk '{print tolower($0)}')
# if windows, make sure to use the same drive
if [[ "${kernel}" == "mingw"* ]]; then # git bash
export TMPDIR=$(echo "${path}" | awk '{ print substr($0, 1, 2)"/temp"}')
if [ ! -e $TMPDIR ]; then mkdir -p $TMPDIR; fi
fi
if [ "${kernel}" == "darwin" ]; then MD5=md5; else MD5=md5sum; fi
rnd=$(echo $RANDOM | $MD5 | awk '{print $0}')
to_remove="${TMPDIR}/$(basename ${path})-${rnd}"
mv "${path}" "${to_remove}"
nohup rm -rf "${to_remove}" > /dev/null 2>&1 &
fi
}
# invoking the function
directory_or_file=./vo-2
fast_delete $directory_or_file
I have faced same issue. this is worked for me
rimraf is a Node.js package, which is the UNIX command rm -rf for node, so you will need to install Node.js which includes npm. Then you can run:
npm install -g rimraf
Then you can run rimraf from the command line.
rimraf directoryname
visit https://superuser.com/questions/78434/how-to-delete-directories-with-path-names-too-long-for-normal-delete
I found this solution because npm itself was causing this problem due to the way it nests dependencies.
Late reply, but for those who search a solution, for me the
rm <dirname> -rf
wasn't good, I always get the directory non-empty or path too long on node directories.
A really simple solution :
Move the directory you want to delete to the root of your disk (to shorten your path) and then you can delete it normally.
Related
I downloaded mongoDB and I try to use brew, it didn't work.
I try bunch of commands such as:
$ curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.6.tgz
$ tar -zxvf mongodb-osx-x86_64-3.4.6.tgz
$ mkdir -p mongodb
$ cp -R -n mongodb-osx-x86_64-3.4.6/ mongodb
$ sudo mv mongodb /usr/local
Didn't work
Step 5: it says the directory is not empty or is not exist. I try to empty the directory didn't work and I try to create a different one, it didn't work.
I can't find any solution. Can someone help me, please?
I think your /usr/local folder already contains a non-empty folder named mongodb.
Refer this for details.
You can confirm it by listing out the files in it
ls /usr/local/mongodb
Maybe, you can try removing that directory as a superuser if it doesn't have any important files and continue with the installation
I have 30 folders, each with about 1700 files in them. I'd like to delete 500 files from each of these folders. What is the best way to do this using command prompt?
This question shows how to empty out files and this question shows how to do it in python but otherwise, there doesn't seem to be a way of deleting a specific number of files.
Let me know if you need any further information, thanks!
It's very easy to do in Linux. So you can download Git for Windows and run Linux commands in Windows. Please try this in a test folder/files first. You can not recover files once deleted.
Let's say you have 3 files (my-file-1.txt, my-file-2.txt, my-file-3.txt) in your directory. Then go to the directory and execute commands.
$ rm -rf my-file-1.txt # remove my-file-1.txt only
$ rm -rf my-file-1.txt my-file-3.txt # remove my-file-1 and 3
$ rm -rf my-file-{1,3}.txt # remove my-file-1 and 3
$ rm -rf *.txt # remove all txt files
$ rm -rf my-file-*.txt # remove all txt files begin with my-file
I am working on making an rpm for a small program used within our enterprise. The %build section of the rpm process works. I'm having trouble with the install section. I've referenced this article response and I believe I am properly referring to the target location with respect to %{_buildroot}.
The program I'm making is to be installed as a system service. So, after the rpm actually is generated for this step, I've got to add the next step in my installation process which is to include the script that is installed to the init.d location and run that install. One step at a time though.
The build errors are as follows (omitting everything but %install):
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.eUDaCK
+ umask 022
+ cd /home/packager/rpmbuild/BUILD
+ '[' /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 '!=' / ']'
+ rm -rf /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
++ dirname /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
+ mkdir -p /home/packager/rpmbuild/BUILDROOT
+ mkdir /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64
+ cd o2arbitord-1.0
+ LANG=C
+ export LANG
+ unset DISPLAY
+ install -m 555 /home/packager/rpmbuild/BUILD/o2arbitord-1.0/o2arbitord /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin
install: cannot create regular file `/home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin': No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.eUDaCK (%install)
Now, my rpmbuild directory does not have the directory /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin. While I know that's part of the problem, the rpmbuild process isn't making the directory /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 either. What I don't understand about that one is: why? Looking at the script output above you can clearly see the line: mkdir /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64. So, why isn't the directory made?
How does the line BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) from whatever the definition of %{_buildroot} is? I thought that was the definition, but it appears to be something different.
For reference, my spec file
Name: o2arbitord
Version: 1.0
Release: 1%{?dist}
Summary: a daemon
Group: Applications/System
License: GPL
URL: http://My.site
Source0: %{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: x86_64
BuildRequires: libusb1-devel
#Requires:
%description
%prep
%setup -q
%build
make -f o2arbitord.mk
%install
install -m 555 %{_builddir}/%{name}-%{version}/%{name} %{buildroot}%{_sbindir}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
/usr/sbin/o2arbitord
%changelog
You are attempting to install a file into a directory that doesn't exist (yet).
RPM only creates the %{buildroot} for you automatically. Anything under that you need to create yourself.
So when you run
install -m 555 %{_builddir}/%{name}-%{version}/%{name} %{buildroot}%{_sbindir}
where %{buildroot}%{_sbindir} expands to /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64/usr/sbin RPM has only created /home/packager/rpmbuild/BUILDROOT/o2arbitord-1.0-1.el6.x86_64 for you already.
You need to create the /usr/sbin part of that path and then copy the file into it.
You can do that with either
%{__mkdir_p} '%{buildroot}%{_sbindir}'
or
%{__install} -d '%{buildroot}%{_sbindir}'
Where
$ rpm -E '__mkdir_p = %{__mkdir_p}'
__mkdir_p = /bin/mkdir -p
$ rpm -E '__install = %{__install}'
__install = /usr/bin/install
I am not sure if this belongs to superuser. Please excuse.
Here is what I am trying to do. I need to create a ksh script which will establish an ssh connection to a remote machine and find all ".tar" files in a particular path for a particular date and list them. Next, I will need to perform an scp command to copy all those .tar files to the server I am executing the ksh script on.
Here is what I have so far and it is far from complete... (please bear with me.. I am very new to ksh scripting).
Can someone please advise if I am going in the right direction and provide some pointers as to how I can improve and achieve what I am trying to do?
Many thanks in advance.
SSERVER=server1
SOURCEPATH=/tmp/test
sudo ssh $SSERVER \
find $SOURCEPATH -name "*.tar" -mtime +7 -exec ls {} \;
#will the above two statements work?
#I then need to output the ls results to a temp variable (i believe) and issue an scp on each of the files
#Copy files from SOURCEPATH to PATH
sudo scp "$SSERVER:$SOURCEPATH/$file1" /tftpboot
sudo scp "$SSERVER:$SOURCEPATH/$file2" /tftpboot
SSERVER=server1
SOURCEPATH=/tmp/test
sudo ssh "$SSERVER" "find $SOURCEPATH -name '*.tar' -mtime +7" |
while IFS= read -r; do
sudo scp "$SSERVER:'$REPLY'" /tftpboot
done
It is an odd behaviour seen only on Solaris that when I try to copy a symbolic link with the "cp -R -P" command to some other folder with a different name, it copies the entire directory/file it's pointing to.
For example:
link -> dir
cp -R -P link folder/new_link
I believe the "-d" argument is what you need.
As per the cp man page:
-d same as --no-dereference --preserve=link
Example:
cp -d -R -P link folder/new_link
I was using "cp -d" and that worked for me.
The cp man page seems to say that you want to use an '-H' to preserve symlinks within the source directory.
You might consider copying via tar, like tar -cf - srcdir|(cd somedir;tar -xf -)
Try using cpio (with the -p (pass) option) or the old tar in a pipe trick.