I'm learning some shell commands on ubuntu 12.04. But I had a hard time unaliasing something I have set before. For example,
$ alias dir ls
$ dir
[some files and directories]
$ unalias dir
- no such command.
Does Ubuntu not support dir command? How can I de-aliasing dir using shell command?
First you ahve to define your alias using this syntax:
alias dir=ls
Then you can check if it worked out:
me#foo:~alias
alias dir='ls'
alias l.='ls -d .* --color=auto'
...
After this works you can simply unalias with:
unalias dir
I think the dir command is a binary in Ubuntu, you can check this using:
which dir
If it gives you a path to an executable you know that dir is no alias.
Related
I launch bash scripts normally with the ./ command.
But if I try to launch the script with the full path I get an error
No such file or directory
I am so confused, I made a search to be sure to get the right path.
$ pwd
/home/pi/server/
$ ls
start_scan
$ sudo chmod 777 start_scan
$ sudo find / -xdev -name start_scan
/home/pi/server/start_scan
$ ./home/pi/server/start_scan
-bash: ./home/pi/server/start_scan: No such file or directory
Do you have any idea what could the problem be? I am using a macbook to use SSH and connect to a Rapsberry Pi under Raspbian and execute the script there.
./ is no command, but a path that means the current working directory.
Your line is almost correct, just remove the dot at the beginning:
/home/pi/server/start_scan
When you type any path starting with a dot, the shell expands it to the current working directory, effectively searching in
/home/pi/server/home/pi/server/start_scan
which is obviously wrong.
I'm new to shell programming and I'm trying to create a simple script that gives me some infos on the status of the machine (i.e date, time, users logged in etc) on Scientific Linux 6 (I know it's old, but the department of my university runs on it so there's no escaping)
Basically I've created my script "sysinfo.sh"
#!/bin/sh
....
exit 0
as root user I want to move it so that I can be able to execute it anywhere and I thought the right way to do it was
sudo mv sysinfo.sh usr/local/bin
but I get the error message
mv: cannot move `sysinfo.sh' to `usr/local/bin': No such file or directory
then I looked for the PATH and it gives me
$ echo $PATH
/u/geo2/sw//System/tools/bin:/usr/bin:/bin
What is the right place to move my script?
Best practice for these kind of manipulation or learning is to have scripts in your $HOME/bin directory.
mkdir $HOME/bin
export PATH=$PATH:$HOME/bin
mv sysinfo.sh $HOME/bin
chmod +x $HOME/bin/sysinfo.sh
If you anyway want to move it to /usr/local/bin, why not do that with:
sudo mv sysinfo.sh /usr/local/bin
chmod +x /usr/local/bin/sysinfo.sh
chmod command will make the script executable.
from chmod man:
x -- The execute/search bits.
The command that you posted indicates that you were trying to use the absolute path for copying, but you missed a leading slash --
the directory should be /usr instead of usr.
Try
sudo mv sysinfo.sh /usr/local/bin
Note that unless an absolute path is specified, the shell looks for the path relative to the current working directory.
In this case, the shell was looking for the subdirectory usr under the current directory which was not found;
hence the error message.
Thank you very much!
In the end, I didn't realize that the directory /usr/local/bin wasn't in the PATH
So i just needed to
export PATH=$PATH:/usr/local/bin
sudo mv sysinfo.sh /usr/local/bin
:D
command line shell
echo %PIG_HOME%
C:\cygwin\usr\lib\pig
cygwin
echo $PIG_HOME
C:\cygwin\usr\lib\pig
echo $( cygpath -u "$PIG_HOME" )
/usr/lib/pig
cd $( cygpath -u "$PIG_HOME" )
-bash: cd: /usr/lib/pig: No such file or directory
Question: why is cygpath not converting it to /cygdrive/c/cygwin/usr/lib/pig?
UPDATE:
The path to the pig folder is correct.
command line shell
C:\Users\john.doe> cd %PIG_HOME%
C:\cygwin\usr\lib\pig>
cygwin
john.doe#COMPUTER ~
$ cd /cygdrive/c/cygwin/usr/lib/pig/
john.doe#COMPUTER /cygdrive/c/cygwin/usr/lib/pig
$
With Cygwin,
C:\cygwin\lib\pig = /usr/lib/pig
and
C:\cygwin\usr\lib\pig = /cygdrive/c/cygwin/usr/lib/pig
This setup is by design.
The C:\cygwin\usr\lib folder is not created by any packages and should not be created by you either.
Type mount in your terminal window.
My c:\cygwin\bin and c:\cygwin\lib\ are mounted at /usr/bin and /usr/lib respectively. I suspect that your c:\cygwin\usr\lib is mounted at /usr/lib.
Therefore, the "unix" path to c:\cygwin\usr\lib\pig would be /usr/lib/pig.
Did you try option "-m, --mixed : like --windows, but with regular slashes (C:/WINNT)"
$ cd /cygdrive/c/cygwin64/home
$ cygpath -m $(pwd)
C:/cygwin64/home
I tried running a script file using bash but it showed an error
bash-3.2$ example.sh : command not found
I also tried
ls -l example.sh
I found that it was not executable, so I used
sudo chmod 777 example.sh
I again tried running it but same error was coming. I double checked that I am in the same folder as the file using ls. But still I am not able to execute the script file.
I finally tried making a dummy script file and running it , and found the same error
I think there is some problem with BASH. Can some one help me with what is the problem?
I am working on redhat, bash was already installed in my system
Since I am newbie on linux any help would be appreciated
bash search for commands in your $PATH. Apparently the current directory, ., is not in your $PATH. (This is a good thing; having . in your $PATH is insecure.)
You'll need to specify a directory name. Just type:
./example.sh
Incidentally, doing:
sudo chmod 777 example.sh
is two kinds of overkill. First, you don't need to use sudo; use sudo only when you actually need to. Presumably your personal account owns the file, so you can just use chmod directly.
Second, 777 is way too permissive. It allows anyone on the system to read, execute, or modify example.sh. (If you're the only person on the system it may not matter much, but it's still a bad habit.) Typically you should use 755 for directories and for files that need to be executable, and 644 for files that don't need to be executable.
Or just use
chmod +x example.sh
to set execute permission (your umask will prevent that from setting the permissions too loosely).
. (the current directory) is probably not on your path. Try ./example.sh or bash example.sh. You could also add . to your PATH environment variable, but that's generally frowned upon.
Your bash PATH probably doesn't include ., try running it by typing:
./example.sh
When you type a command, your shell searches your path to try to find the command, if the current directory (e.g. .) isn't part of the path, the script that you are trying to run won't be found. You'd have to explicitly give it the path to where this command is. And since it's in your current directory, you can just add ./ in front of the command.
first confirm the bash path
to check the path of bash use:
which bash
if you get "/bin/bash"
then add
#!/bin/bash
...
...
or whatever is the path on first line of your bash script
I write a simple shell script to clean log files in redhat:
Filename: clean.sh
#!/bin/bash
rm -f *.log core.*
But when I typed clean or clean.sh, it always prompt
-bash: clean: command not found
-bash: clean.sh: command not found
What's the problem?
You probably don't have . (the current directory) in your $PATH (and that's a good thing; having . in your $PATH can be dangerous.)
Try this:
./clean.sh
And if the script file's name is clean.sh you can't run it as just clean, with or without a directory. The file name is clean.sh, and that's how you need to execute it.
Or you can change the name from clean.sh to just clean. Unix-like systems (that includes Linux) don't depend on file extensions the way Windows does.
problem 1: maybe the execute permission on clean.sh is not set. Do this:
chmod +x ./clean.sh
problem 2: RH Linux does not include CWD on the path by default. So, when you are in the same directory as clean.sh, type:
./clean.sh
That should execute it.