Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a directory named "--table" that i'd like to remove. I tried rmdir --table, rmdir --table and still it wouldnt work. What is the correct method ?..
rmdir -- --table
The -- in the middle signals the end of options.
The rm man page states
To remove a file whose name starts with a '-', for example '-foo', use
one of these commands:
rm -- -foo
rm ./-foo
Although it does not state it, the double-hyphen is used by many unix commands (e.g. rmdir) to separate options from the rest of the arguments.
You can use -- alone to signal that what follows are file names, not switches. So, the correct method would be rmdir -- --table.
rm -rf ./--table
or simply, but with great care, rm -rfi * and answer y only for --table
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I've been reading how running rm -rf to delete files and directories isn't a good idea because of how dangerous it can be, but can't seem to find a consensus on how to safely delete files and directories through the terminal. Is there another command built into Linux that does this safely?
Consider using the -i or -I options, ie.
$ rm -i foo
$ rm -I foo
Those tell rm to be interactive, prompting you to confirm deletion of files.
From the rm(1) manpage:
-i prompt before every removal
-I prompt once before removing more than three files, or when
removing recursively; less intrusive than -i, while still giving
protection against most mistakes
For example:
$ mkdir -p ~/foo/{bar,baz} # make some dirs
$ touch ~/foo/{bar,baz}/{1,2,3} # add some empty files
$ rm -ir ~/ foo # note the "accidental" space between `~/` and `foo`
rm: descend into directory '/home/uz0r/'? y # haven't noticed yet...
rm: remove regular file '/home/uz0r/.bashrc'? # ...wait, what?
"Hold on... I told you to delete $HOME/foo, not $HOME! Or did I...?"
So you made a typo, but -i saved you from an accident. Now you can tell rm to stop, then try again after correcting the typo.
Be careful using -f! It counteracts the above safety nets by telling rm to "never prompt":
-f, --force
ignore nonexistent files and arguments, never prompt
Create yourself a trash bin for your deleted objects.
mkdir ~/trash
mv xyz ~/trash
You can recover, just be aware that some privileges may change on the files.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am trying to delete all files in my directory "XYZ" without using find command in bash on Linux.
Use the following command:
rm -f XYZ/*
If you want to delete also subdirectories, use:
rm -fr XYZ/*
If you also want to delete the directory, use
rm -fr XYZ
If you want to delete all files in a directory, go into the directory and execute: rm -f *
Why would find even enter into it? use rm -r XYZ to recursively remove the directory XYZ.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Guys What is a more efficient way of doing the following using auto-complete?
cd
ls
cd bar
ls
cd baz
ls
cd basilio
Try ls -R from the outermost folder, that will recursively list all content.
You haven't specified in which SHELL. In BASH you can do double-tab to see what are your options:
cd [TAB] [TAB] type first few letters [TAB] to complete.
Similar - but better - completion is implemented in ZSH.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
i created a soft link from my home folder to /etc/ by using
"ln -s /etc/ foo"
then i changed directory to foo
"cd foo"
now i executed the following two commands
"pwd" and "/bin/pwd"
Both gave me different outputs.
The output of "pwd" was /home/myhome/foo and of "/bin/pwd" was /etc.
I am not able to understand the difference in the outputs although both commands are the same.
Possibly a bit oversimplified, but the bash builtin pwd tracks cd commands, so when you cd through a symbolic link, it remembers that. On the other hand, /bin/pwd walks the directory tree back to the root, and, as such, has no idea what symbolic links you might have walked through to get where you are.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm making a script in bash that requires files to be copied. I tried using the cp command with the -n flag set but I found out that on some systems the -n flag is not available.
cp: invalid option -- n
I want this script to be portable enough so that users won't be required to update their cp.
What the -n flag does is copy only files from the source that are not already in the destination without prompting.
Is there an alternative to this?
If the -i flag is available, yes n | cp -i ... should achieve the same as cp -n ....
Try rsync -u. Although is not exactly equivalent to cp -n, it may be what you actually want...