The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sourcing the .bashrc Nusy UNIX for Dummies Questions & Answers 3 05-27-2008 05:23 PM
alias rm = 'rm -i' in .bashrc and vnc cy163 UNIX for Dummies Questions & Answers 0 05-23-2007 09:57 AM
history -c in my .bashrc yankee428 UNIX for Dummies Questions & Answers 1 06-23-2005 04:13 PM
xterm font colors - configuration question? ripley Linux 3 04-14-2005 11:11 AM
from bashrc to sh..?? moxxx68 Shell Programming and Scripting 3 09-13-2004 05:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2008
kthatch kthatch is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 28
.bashrc question re: rm -i & ls --colors

QUESTION #1:

I have this in my .bashrc file:

alias rm='rm -i'

Problem is, there are 3 files that I remove many times a day and would like this command to ignore these 3 files. In other words, prompt me on everything EXCEPT these 3 files.

Is this possible?

QUESTION #2:

Also in my .bashrc file is this:

alias ls='/usr/local/bin/ls --color'

My colors will not work if I have just 'ls --color'. My colors only work if referenced to /usr/local/bin/ls --color.

Can I modify the color scheme? So that it only affects me, not everyone else?
  #2 (permalink)  
Old 04-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Q1. Some possiblities:

Quote:
- change the permission of these files
- preface the filename with a dot to make them hidden
- use a script to remove the desired files
Q2. set your alias as follow:

Code:
alias ls='ls --color=auto'
Regards
  #3 (permalink)  
Old 04-21-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Quote:
Originally Posted by kthatch View Post
alias rm='rm -i'

Problem is, there are 3 files that I remove many times a day and would like this command to ignore these 3 files. In other words, prompt me on everything EXCEPT these 3 files.
Yes, it's possible. It's not exactly trivial to get right, because you could be passing in both files from the excluded set and other files at the same time. But let's just figure you usually delete only one file at a time.

Code:
rm () {
  local ask
  ask="-i"
  case $# in 1)
     case $1 in your|excluded|files) ask= ;; esac ;;
  esac
  /bin/rm $ask "$@"
}
This declares a function (instead of an alias) which assumes your regular rm is in /bin/rm -- if it's in /usr/bin/rm or elsewhere, you need to adapt the command. The variable ask is set to "-i" and then conditionally, if there is exactly one argument, and if that one argument is one of your three files (change the list to hold your exceptions) then set ask to the empty string. Then, unconditionally run the regular rm, with whatever value $ask has now, on the arguments.

Quote:
Can I modify the color scheme? So that it only affects me, not everyone else?
The ls manual page mentions a variable LS_COLORS which you can set or modify in your own .bashrc. It won't affect anybody else; everybody have their own .bashrc. GNU file utilities has detailed documentation (for some version of GNU ls). It seems the regular documentation is what dircolors -p prints, and the manual doesn't explain it in too much detail.

Last edited by era; 04-21-2008 at 01:21 PM.. Reason: Actually, look at dircolors -p output
  #4 (permalink)  
Old 04-21-2008
kthatch kthatch is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 28
Thanks for your response, but ....

Q1.
- change the permission of these files --> Our application creates these files on startup. Prior to restarting our application, these files must be deleted. Ideally, my request needs to go through our development team to modify the application start/stop --- but until then, I need to do it manually.
- preface the filename with a dot to make them hidden --> same as above
- use a script to remove the desired files --> agreed, this would work, but ...

I still want to know if it's possible to use rm -i (or an alternate rm option) to prompt on all files EXCEPT for 3 specific files (work log tmp).

Q2.
alias ls='ls --color=auto' --> maybe I should clarify: my colors do not work at all if I use ls --color OR ls --color=auto. My colors ONLY work if referenced to /usr/local/bin/ls --color.

So, my question remains: Can I modify the color scheme? So that it only affects me, not everyone else?
  #5 (permalink)  
Old 04-21-2008
pupp's Avatar
pupp pupp is offline Forum Staff  
cap_10hdx 1
  
 

Join Date: Feb 2008
Location: Jersey Shore
Posts: 548
set up an alias within your profile so that it does not have the options you do not want

alias rm2='rm <options>'

everytime you want to remove a file with the specified options... just run rm2.
  #6 (permalink)  
Old 04-21-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Create a wrapper script which removes the files, then starts the application.

Code:
#!/bin/sh
rm -f work log tmp
exec /path/to/application
Scroll back to my earlier reply regarding the possibility to modify rm to not prompt for these tree files.

Earlier you said the ls alias pointed specifically to /usr/local/bin/ls. If it doesn't then it's likely that another version of ls is in your PATH before /usr/local/bin/ls -- one which doesn't understand, or ignores the --color option. (What does "which ls" or "type -all ls" print for you?). If so, just put in the entire path /usr/local/bin/ls in the alias.

Last edited by era; 04-21-2008 at 01:37 PM.. Reason: Suggest which ls or type -all ls; pointer back to earlier comment
  #7 (permalink)  
Old 04-21-2008
kthatch kthatch is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 28
Sorry -- I did not see the response from era -- i must have been posting at the same time ... I will review and respond shortly.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0