I ran the maven test and it's ended in a terminal. In another terminal, I ls target/surefire-reports and just find no report here. So I cd .. and enter the directory second times, my file is here! So, Bash need refresh for accessing new file? But when I doing something like head file0 > file1 in a terminal, I can find my file instantly with ls in another terminal.
My instruction here:
In the first terminal:
[me#host1 /home/me/interest/target/surefire-reports]
$mvn test
.....
[me#host1 /home/me/interest/target/surefire-reports]
$
(ended)
In the second terminal:
[me#host1 /home/me/interest/target/surefire-reports]
$ls
[me#host1 /home/me/interest/target/surefire-reports]
$ll -al
total 0
[me#host1 /home/me/interest/target/surefire-reports]
$cd ..
[me#host1 /home/me/interest/target]
$cd surefire-reports/
[me#host1 /home/me/interest/target/surefire-reports]
$ls
mycode.txt TEST-mycode.xml
[me#host1 /home/me/interest/target/surefire-reports]
$
It looks like the current directory is being deleted and re-created. This would explain why you can't see anything until you enter the same directory again--the director you're in is actually gone, and a new one by the same name has been created.
This happens because the directory surefire-report you were in has been removed and re-created, so when you run "ls" you try to get the listing of the current directory, which no longer exists. Try having the parent directory as current directory and run ls like this:
[me#host1 /home/me/interest/target]
$ ls surefire-reports
I think this will give the correct listing
Related
I'm using Ubuntu 20.4.05 LTS. It is not locating any directory as you can see in the image. For example, cd ~/Downloads doesn't take me to the directory.No such file or directory image What should I do?
as a first step you must know the position of the directory by writing the command pwd
pwd
then you can write the ls command to see the contents of the list of folders or directories
ls
if the file you need is in that directory, you can enter that file by writing the command cd
cd
access folder
Is it possible to suppress deleting default target directory during mvn clean? Current process deletes entire directory with all its content while I need to keep empty dir on delete.
I guess I will be able to set such configiration by using <artifactId>maven-clean-plugin</artifactId>, but still there remains the implicit process of the mvn clean which deletes entire directory anyway.
I assume you can make use of excludeDefaultDirectories: set it to true and manually list the subdirectories you want to purge via filesets. I haven't tested this but it should work. Let me know how it goes.
A symbolic link on Linux (as for other Unix-variants) uses its name, not the actual directory to resolve where it points. You can then use ls -P on BSD-variants like MacOS or ls -L on GNU variants (untested) to see what is pointed to.
The information stored in a symbolic link does not get invalidated when target is deleted, so when the directory is created again the symbolic link will work again.
On my Mac:
ravn#freewifi demo % mkdir target; ln -s target t
ravn#freewifi demo % ls -lP t
lrwxr-xr-x 1 ravn staff 6 30 Jun 18:40 t -> target
ravn#freewifi demo % ls -l t/
total 0
ravn#freewifi demo % rmdir target; ls -l t/
ls: t/: No such file or directory
ravn#freewifi demo % mkdir target; ls -l t/
total 0
ravn#freewifi demo %
The trailing slash is to ensure that the symbolic link is followed (or at least tried to).
I have a bash script located in /home/http/mywebsite/bin/download.sh
I have a config file in /home/http/mywebsite/config/config.yaml
Now I want to read the yaml file no matter where I execute my script.
The problem:
When I cd into /home/http/mywebsite/bin/ and run ./download.sh everything works.
When I cd into /home/ and run http/mywebsite/bin/download.sh it can not find the config file because of the relative path.
How do I make sure I can always read the config file no matter where I execute the script. It is always located 4 directories up from the script in config/config.yaml
The script looks like this:
#!/bin/bash
# This will give me the root directory of my project which is /home/http/mywebsite/
fullpath="$( cd ../"$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cat ${fullpath}config/config.yaml
This works if I execute it inside the directory where the script is.
If I execute the script from another directory such as /home/ I get the following error:
cd: ../http/mywebsite/bin: No such file or directory
cat: config/config.yaml: No such file or directory
Solution?
If it is possible it would be great with a code snippet that can traverse up a path N amount of times, this would solve my problem. But it is too advanced for me.
For example you can set a variable "cd_up=1" how many times to go up. The run the loop/sed or whatever magic.
And it would turn the absolute string from:
/home/http/mywebsite/bin/
into:
/home/http/mywebsite/
And changing it to 2 it would change the string to:
/home/http/
Managed to solve it finally by using:
#!/bin/bash
cd "$(dirname "$0")"
BASE_DIR=$PWD
# Root directory to the project
ROOT_DIR=${BASE_DIR}/../
cat ${ROOT_DIR}config/config.yaml
This allows me to execute the script no matter where I am.
You can use which command to determine absolute path of the executing script no matter where you are running
BASE_DIR=$(which $0 | xargs dirname)
ROOT_DIR=${BASE_DIR}/../..
cat ${ROOT_DIR}/config/config.yaml
Lets try printing the path from different locations.
-bash-4.1$ /tmp/dir.sh
$0 - /tmp/dir.sh. Absolute path - /tmp
-bash-4.1$ cd /tmp
-bash-4.1$ ./dir.sh
$0 - ./dir.sh. Absolute path - /tmp
-bash-4.1$
-bash-4.1$ cd /usr/bin
-bash-4.1$ ../../tmp/dir.sh
$0 - ../../tmp/dir.sh. Absolute path - /tmp
I'm learning command line using osx terminal. I tried to remove an empty directory but it says Directory not empty. here's what I did:
$pwd
/desktop/temp/stuff/things/frank/joe/alex
$ls
$(shows nothing)
$cd ..
$pwd
/desktop/temp/stuff/things/frank/joe
$rmdir alex
rmdir: alex: Directory not empty
Can you help me with this? thank you
Try ls -a instead of ls to show all files in the directory. There may be invisible files (starting with a .) in that directory.
I am beginning to learn ruby and was following the instructions of one video to access the desktop through the -ls command in the terminal. Now, I would like to get out of the desktop in the terminal and don't know how. I know, I know I am a total noob... but can someone please help. Thanks. BTW the command I wrote was:
my-iMac~ me$ cd Desktop/
my-iMac:Desktop samuel$ ls
Where would you like to go?
Go home: cd or cd ~
Go to the previous working directory: cd $OLDPWD
Go to parent of the current directory: cd ..
Go to any directory you want: cd /path/to/directory
cd .. will take you back up 1 level.
for windows, you can open up the file explorer copy path then in your command prompt type "cd" then paste path. Your command prompt should now default to that path. (you can also type the entire path)
cd C:\Users\username\Documents\Folder