I want to run my script which is ./fc every 5 minutes which the default crontab command is
*/5 * * * * /path/to/script-or-program but how would i merge ./ in with it ?
Your script is not ./fc. It's fc. The ./ is a relative path, and means "current directory". So use the absolute path instead. You can find the absolute path to your current directory with:
pwd
This might print something like:
/home/you
So you'd use this path in your crontab:
/home/you/fc
Another way to get the absolute path is using the realpath command:
realpath fc
This will print the absolute path to the file you pass as argument.
Related
When I use pwd it returns:
/home/ahmad/multifit-pretrain-lm/multifit/datasets
I look for a command so that I get the path relative to the home directory
multifit-pretrain-lm/multifit/datasets
I look for a command so that I get the path relative to the home directory
You can use bash parameter substitution here:
echo "${PWD#"$HOME"/}"
$PWD shell variable returns same value as the command pwd
${PWD#"$HOME"/} strips "$HOME"/ at the start from $PWD
Variable substitution is a good solution but since you asked for a command, here is one:
realpath --relative-base="$HOME" .
I have a question regarding LINUX command line that i don't really understand:
Run the following commands.
$ cd
$ mkdir hw1-test
$ cd hw1-test
$ls /class/home > classlist
$ cd
what does the fourth command do?
Question:
Show the ls command you ran with the absolute path.
Show the ls command you ran with the relative path.
4th command lists out all the file in the directory to filename classlist in the same directory.
What is an absolute path?
An absolute path is defined as the specifying the location of a file or directory from the root directory(/). In other words we can say absolute path is a complete path from start of actual filesystem from / directory
What is the relative path?
Relative path is defined as path related to the present working directory(pwd). Suppose I am located in /var/log and I want to change directory to /var/log/kernel. I can use relative path concept to change directory to kernel.
Examples :
changing directory to /var/log/kernel by using relative path concept.
pwd
/var/log
cd kernel
Note: If you observe there is no / before kernel which indicates it’s a relative directory to present working directory.
Changing directory to /var/log/kernel using absolute path concept.
cd /var/log/kernel
Example 2: Present location is /abc/xyz, I am want to remove /abc/xyz/read/hello.txt file.
Using relative path:
rm read/hello.txt
Using absolute path:
rm /abc/xyz/read/hello.txt
SO ANSWERS TO YOUR QUESTIONS ARE
Show the ls command you ran with the absolute path
so absoulte path means full path.
Just open your terminal and you should know path of the directory you want to visit.
As you said in the question your path is /class/home/ i.e class is in root folder and home is inside it and you want to list out files in it so type
ls /class/home/ > classlist
Show the ls command you ran with the relative path
so now for relative path you will have to ennter into the directory one before the actual directory of home i.e. class
when you open your terminal you are in home directory by default i.e /Username/home
so type
cd .. //it will take you back into class directory
if you want to check you can check it with `pwd`.
and it will show your present working directory.
do
ls home/ > classlist
Request to need a help or information of the two operators . and `` in linux
e.g.
$ cp /home/uddi/root/hello `pwd`
and
$ cp /home/uddi/root/hello .
Please suggest me
A small difference occurs after mkdir /tmp/lost; cd /tmp/lost; rmdir /tmp/lost.
After these stupid commands pwd will be a filename (/tmp/lost) and the current dir . does not exist.
I think you want an error when you try to copy a file in the "current" dir, so I would prefer the .. It will also avoid an extra command.
When you enclose something between back-ticks, the shell will run the contents and use the output from that/those command/s as an argument for the main command being run. In your example, the shell will run the pwd command and use its output as the 2nd argument to the cp call.
In your second example, the . character is a link to the current directory. The reason that both do the same thing is that . links to the current directory and pwd will print out the current working directory, which are the same. In this case, you are using two methods to expand to the same path.
EDIT:
You can see somewhat how . works by running ls -a in any directory. It will show you the . and .. directories, which are filesystem-level links to the current and parent directory, respectively.
I'm having an error while trying to execute a sh in my crontab (or in the normal shell) .
I made an user Xuser, and in his home directory make a symbolic link to /opt/app
/opt/app with this --> drwxrwxr-- Xuser test
In this folder I save serveral sh and jar.
Now in the crontab of this user or even in the shell if I tried to execute this:
./opt/app/bin/ind.sh
-bash: ./opt/app/bin/ind.sh: No such file or directory
The Sh file is
#!/bin/sh
export JAVA_HOME=/usr/java/latest/
export PATH=$PATH:$JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
java -jar /opt/app/bin/ind.jar
If I put a space between . / it works
. /opt/app/bin/ind.sh
: command not found
Error: Unable to access jarfile /opt/app/bin/ind.jar
( Access the SH but seems that the problem pass to the jar hahaha )
Someone notice the problem??
Thanks !!!
There is a big difference, when you put a space between the . and the / the . is no more part of the file path but is an alias of source and means "execute the content of this file in the current shell".
// execute in a subshell
./foo/bar/baz.sh
// execute in this shell
. ./foo/bar/baz.sh
// this is not the same file as previously, unless we are at the root (/)
. /foo/bar/baz.sh
In a bash shell script today I noticed the below command at the end of the script. I know what is cd but I am unaware of the significance of a dash after it.
cd -
What does this mean? Google naively truncates the - so I am unable to find its answer.
If a single dash is specified as the argument, it will be replaced by the value of OLDPWD.
The OLDPWD is set by cd command and it is the previous working directory.
cd - returns to the directory you were previously.
For instance:
marcelo#marcelo:~$ cd /opt
marcelo#marcelo:/opt$ cd /usr/bin
marcelo#marcelo:/usr/bin$ cd -
/opt
marcelo#marcelo:/opt$
I was in /opt, changed to /usr/bin, and then went back to /opt with cd -
cd - brings you back to the last directory.
$ cd ~/Desktop
$ pwd
/Users/daknok/Desktop
$ cd /
$ pwd
/
$ cd -
$ pwd
/Users/daknok/Desktop
cd - returns to the previous directory you were in.
Say I'm in /usr/ and I type cd /var/local/someplace/else
Then I use cd - I'll return to /usr
From the manual
An argument of - is equivalent to $OLDPWD. If a non-empty directory
name from CDPATH is used, or if - is the first argument, and the
directory change is successful, the absolute pathname of the new
working directory is written to the standard output. The return
value is true if the directory was successfully changed; false
otherwise
Therefore the - is equivalent to the $OLDPWD, which holds the last directory which the shell was in, and is set by the previous cd invocation.
From the man found here : http://ss64.com/bash/cd.html
Quickly get back
$ cd -
cd - bring you back to the last directory you were.
e.g.
cd ~/Documents
cd ~
cd /
Now you are in '/', and if you run 'cd -' you will be in '~'. BTW, run 'cd -' once again, you will return to '/' but not '~/Documents'
“ Current Directory “ Is what the bash cd terminal command means. It means “ keep me in this directory “