There might be several ways to remove files starting with first character as - minus. But i am providing 3 solutions below.
1. $ rm ./-filename
2. $ rm -- -filename
3. Find the inode number by using ls -i and then use the below command
find . -inum 45678 -exec rm {} \;
Saturday, December 4, 2010
Monday, January 25, 2010
Difference between Unix Internal & External Commands
Internal Unix commands are built with the shell and hence it will run in the same shell.
eg: cd
External Unix commands will start a new shell and then it gets executed
eg: ls
Note: If you execute a shell script, it will create or fork a new shell and then execute the commands present in the script file. You can also execute the shell script in the same shell by using source or . infront of the shell script.
eg:
sujay@laptop:~/scripts$ cat test.sh
cd /
echo "Current dir is `pwd`"
sujay@laptop:~/scripts$ test.sh
Current dir is /
sujay@laptop:~/scripts$ pwd
/home/sujay/scripts
sujay@laptop:~/scripts$ source test.sh
Current dir is /
sujay@laptop:/$ pwd
/
eg: cd
External Unix commands will start a new shell and then it gets executed
eg: ls
Note: If you execute a shell script, it will create or fork a new shell and then execute the commands present in the script file. You can also execute the shell script in the same shell by using source or . infront of the shell script.
eg:
sujay@laptop:~/scripts$ cat test.sh
cd /
echo "Current dir is `pwd`"
sujay@laptop:~/scripts$ test.sh
Current dir is /
sujay@laptop:~/scripts$ pwd
/home/sujay/scripts
sujay@laptop:~/scripts$ source test.sh
Current dir is /
sujay@laptop:/$ pwd
/
Saturday, January 23, 2010
How to run a unix shell script from any directory
To run a script from anywhere inside UNIX directory, you need to include the script absolute directory in the PATH variable. After that without using the pathname we can execute the script successfully.
eg:
In .profile, update PATH=$PATH:/home/sujay/scripts and source the .profile
Script Loc: /home/sujay/scripts/
Script Name; anywhere
sujay@laptop:~$ anywhere
++ pwd
+ echo 'Executed from /home/sujay'
Executed from /home/sujay
eg:
In .profile, update PATH=$PATH:/home/sujay/scripts and source the .profile
Script Loc: /home/sujay/scripts/
Script Name; anywhere
sujay@laptop:~$ anywhere
++ pwd
+ echo 'Executed from /home/sujay'
Executed from /home/sujay
Subscribe to:
Posts (Atom)