Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

default option of rm commad

I have used command rm * and my mac just deleted all files in the current directory silently without asking whether to delete the files or not. This operation seems like rm -f was used to delete.


Is rm -f default behavior ?


BTW, I do not have any aliases for rm command in .bashrc or .tcshrc files.


Ideally the default behavior should not be force removal, unless user specifically uses force option.

MacBook Air, OS X Yosemite (10.10.5)

Posted on Nov 23, 2015 11:05 PM

Reply
5 replies

Nov 24, 2015 7:41 AM in response to prasadk83

.login is for the C-Shell (csh or tcsh) which is one flavor of command line interface.


.bashrc is for the Bash shell (the current default OS X shell), and is another flavor of command line interface. However, when you first start a Terminal session, .bashrc is not run, but rather bash looks for .bash_profile, .bash_login, .profile and uses the first one of those its finds in the order I just listed, and does not bother with any of the others.


The command

dscl . -read $HOME shell

should show which shell you are using


Once you know what shell you are using, you can then choose to modify or create the necessary file to store the alias.


Also the syntax for the alias command is different for csh/tcsh vs bash, so it is important to know what shell for that reason.


csh/tcsh

alias rm 'rm -i'


bash (as shown by VikingOSX)

alias rm='rm -i'


With respect to rm default behavior. While it is not defaulting to -f, its default is very close to -f. The -f option will not complain if you ask to delete a file that does not exist. -f will not complain if the file is marked readonly, as long as you have permission to remove the file name from the directory. But otherwise, from your perspective, the rm default does look very much like -f, since * only provides files that exist, and it is unlikely you will have files that have readonly permissions.


By the way, I have been using the "alias rm='rm -i'" for about 30 years. And I learned the hard way, just like you 🙂

Nov 24, 2015 11:01 PM in response to prasadk83

Please note: the rm -i will not protect you everywhere. I think you can get into trouble with the sudo command.


To see what file you will get with the * do:

mac $ echo *

Applications Applications (Parallels) BlackBerry.mov Desktop Documents Downloads Dropbox

mac $



You will want to do the same thing for cp and mv. Guess what they do? ...

Here are a few of the alias command that I use.


# for bash


alias cp='cp -i'

alias mv='mv -i'

alias rm='rm -i'


alias a='alias '


alias ls='ls -Fh'

# User the letter q to quit

alias more='less'


# Prevent control-d from exit a console session.

# Use exit or logout.

set -o ignoreeof


# Prevent standard redirection > from replacing a file.

# Use >| to replace anyway

set -o noclobber


# Allow editing of retrieved commands

# Use the history command to show past commands

# and !10 to retrieve the

# tenth command

shopt -s histverify


# Print current directory after change directory command cd

alias cd='cdir'



# Define a command to change a directory and list the resulting directory

function cdir ()


{


\cd "$*"

pwd


}

default option of rm commad

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.