R get the logical working directory - r

I have some symlinks on the server I'm deploying my R app and I need to know the logical (symbolic) path to working directory:
16:18 $ ls -alh
total 8
drwxr-xr-x 4 user staff 136B Mar 16 16:18 .
drwxr-xr-x 40 user staff 1.3K Mar 16 16:17 ..
drwxr-xr-x 2 user staff 68B Mar 16 16:17 test1
lrwxr-xr-x 1 user staff 5B Mar 16 16:18 test3 -> test1
16:25 $ pwd -P
/physical/path/to/test/test1
16:25 $ pwd -L
/logical/path/to/test/test3
In R when you use getwd function it returns the physical path. In that case this would be /physical/path/to/test/test1. I'd like to get the symbolic (logical) path to that directory: /logical/path/to/test/test3.
Is it possible to get the logical path using an R function?
I know that there is an option of using system("pwd -L") but I was wondering if there is an R function for that.
EDIT:
I've checked and system("pwd -L") doesn't work either.

Related

How to find file size greater than 200 MB in unix from a directory and its sub directory

Even though I used this command I am still getting output lesser than the 200 MB as well.
Command used:
find . -type f -size +200M -exec ls -lh {} \;
Output example
-rw-r--r-- 1 dummy dummy 101K Jul 27 22:43 ./sub_dir1/sub_dir2_1/file_1
-rw-r--r-- 1 dummy dummy 158M Jul 27 22:44 ./sub_dir1/sub_dir2_1/file_2
-rw-r--r-- 1 dummy dummy 1.1G Jul 27 22:44 ./sub_dir1/sub_dir2_2/file_3
-rw-r--r-- 1 dummy dummy 11M Jul 27 22:45 ./sub_dir1/sub_dir2_2/file_4
I have figured it out.
In some of the unix versions, We can't directly use the size as it is for the find commands.
In this it occupying 512 bytes.
Hence (200000000/512) = 390625
Unix command perfected:
find . -type f -size +390625 -exec ls -lh {} \;
Now it is working as expected.

Reading file mtime in UNIX in particular format (2013-06-25 09:04:32)

hi i have this file on my UNIX box (SunOS 5.10).
-rwxr-xr-x 1 phnxep siebel 917 Feb 1 02:52 crontest.sh
Here date and time are given like Feb1 02:52.Can i just read these values in UNIX for my file ignoring the rest of the details.In the required format-:
2017-02-1 02:52
And convert them to integer values later on???Please help guys i am really stuck on this.
If you are using gnu ls, try
ls -l --time-style=full-iso
E.g.:
$ touch x
$ ls -l --time-style=full-iso x
-rw-r--r-- 1 max max 0 2017-02-06 13:18:56.498920000 +0000 x
If you are using Sun ls, try -E option, e.g. ls -E.

How to compare html files in unix

I have two folders with huge number of HTML files and I want to compare each file and how to get the diff of each file using shell script/unix commands.
Example:
Directory 1:
1.html
2.html
3.html
Directory 2:
1.html
2.html
3.html..
I want to compare 1.html in directory with 1.html in dir2, and 2.html with 2.html, and so on.
try this;
#!/bin/bash
for file in $1/*.html; do
fileName=$(basename "$file")
if [ ! -f $2/$fileName ]; then
echo $fileName " not found! in "$2
else
difLineCount=$(diff $file $2/$fileName | wc -l)
if [ $difLineCount -eq 0 ]; then
echo $file "is same " $2/$fileName;
else
echo $file "is not same " $2/$fileName "." $difLineCount "lines are different";
#diff $file $2/$fileName
fi
fi
done
for file in $2/*.html; do
fileName=$(basename "$file")
if [ ! -f $1/$fileName ]; then
echo $fileName " not found! in "$1
fi
done
Ex :
user#host:/tmp$ ./test.sh Directory_1 Directory_2
Directory_1/1.html is same Directory_2/1.html
Directory_1/2.html is same Directory_2/2.html
Directory_1/3.html is not same Directory_2/3.html . 4 lines are different
4.html not found! in Directory_2
5.html not found! in Directory_1
user#host:/tmp$ ls -alrt Directory_1/
total 20
-rw-rw-r-- 1 user user 6 Ağu 11 13:28 1.html
-rw-rw-r-- 1 user user 6 Ağu 11 13:28 2.html
-rw-rw-r-- 1 user user 6 Ağu 11 13:28 3.html
-rw-rw-r-- 1 user user 0 Ağu 11 13:41 4.html
drwxrwxr-x 2 user user 4096 Ağu 11 13:41 .
drwxrwxr-x 4 user user 4096 Ağu 11 13:48 ..
user#host:/tmp$ ls -alrt Directory_2/
total 20
-rw-rw-r-- 1 user user 7 Ağu 11 13:28 3.html
-rw-rw-r-- 1 user user 6 Ağu 11 13:28 2.html
-rw-rw-r-- 1 user user 6 Ağu 11 13:28 1.html
-rw-rw-r-- 1 user user 0 Ağu 11 13:44 5.html
drwxrwxr-x 2 user user 4096 Ağu 11 13:44 .
drwxrwxr-x 4 user user 4096 Ağu 11 13:48 ..
You can use comm command to compare sorted files. This might be the actual solution you are looking for.
Syntax: comm file1 file2
Compare sorted files FILE1 and FILE2 line-by-line.
With no options, comm produces three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. Each of these columns can be suppressed individually with options.
Keep the comm command in a loop such that it compares all the files in your required directories.
If you want to compare files one by one manually:
You need to use diff command to display line-by-line difference between two files.
Syntax: diff path/FILE1 path/FILE2
You can use --changed-group-format and --unchanged-group-format options to filter required data.
Following three options can use to select the relevant group for each option:
'%<' get lines from FILE1
'%>' get lines from FILE2
'' (empty string) for removing lines from both files.
Example: diff --changed-group-format="%<" --unchanged-group-format="" file1 file2
You can get a clear-cut visual difference between two text files using the command sdiff:
Syntax: sdiff path/file1 path/file2
If you have vim editor installed
use: vim -d file1 file2

How to list the files greater than specific timestamp in its pattern in Unix?

Can you please how I can accomplish the below scenario in Unix Ksh command?
I have a job J1 which is completed by the time HH:MM. I would like to list all the files created by this job J1, The file has the timestamp in its pattern YYYYMMDDHHMMSS_?
where YYYYMMDD is the date, HHMMSS is the system timestamp. I want to list the files if the job's timestamp is less than the file time stamp as the job creates the files, the timestamp of the job would be greater than the file timestamp?
Regards
Ben
You can use something like this: (Assuming the files listed)
$ ls -la
total 44K
drwxr-xr-x 2 gp users 4.0K Oct 27 14:56 .
drwxr-xr-x 11 gp users 4.0K Oct 27 14:57 ..
-rw-r--r-- 1 gp users 0 Oct 23 14:45 logfile
-rw-r--r-- 1 gp users 137 Oct 27 15:09 t2t2
prw-r--r-- 1 gp users 0 Oct 23 12:34 testpipe
-rw-r--r-- 1 gp users 0 Oct 23 14:51 tmpfile
-rw-r--r-- 1 gp users 7 Oct 27 14:58 ttt
# Find newer files
$ find . -newer ttt -print
./t2t2
# Find files that are NOT newer
$ find . ! -newer ttt -print
.
./tmpfile
./testpipe
./logfile
./ttt
# You can eliminate the directories (all of them) from the output this way:
$ find . ! -newer ttt ! -type d -print
./tmpfile
./testpipe
./logfile
./ttt
# or this way
$ find . ! -newer ttt -type f -print
Note that the different forms of the "newer" option (like anewer, cnewer) will not compare the other files against the the same timestamp. You might have to do a few tests to see which version suits you better.
If you must use the timestamp in the file name, and the different options of "find", including "mmin" are not acceptable, then you will have to examine the embedded timestamp of each file name. I suggest checking into these commands:
# You have to escape the < of > signs you use.
$ expr "fabc" \< "cde"
0
$ expr "abc" \< "cde"
1
and this:
FILENAME="ABC_20141026101112.log" ; TIMESTAMP="`expr \"$FILENAME\" : \".*_20\([0-9]\{12\}\).*$\"`";echo $TIMESTAMP
So a "while read" loop, looking at all the file names and comparing their timestamps using the above "expr" compares should do the job. Ideally, I'd try to see if "find" can do the job because reading and examining each file will be slower. If you have thousands of files in that directory, then I would try some other solution. If you are interested in more options, let me know.

What does ^ character mean in grep ^d?

When I do ls -l | grep ^d it lists only directories in the current directory.
What I'd like to know is what does the character ^ in ^d mean?
The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.The grep is matching only lines that start with "d".
To complement the good answer by The New Idiot, I want to point out that this:
ls -l | grep ^d
Shows all directories in the current directory. That's because the ls -l adds a d in the beginning of the directories info.
The format of ls -l is like:
-rwxr-xr-x 1 user group 0 Jun 12 12:25 exec_file
-rw-rw-r-- 1 user group 0 Jun 12 12:25 normal_file
drwxr-xr-x 16 user group 4096 May 24 12:46 dir
^
|___ see the "d"
To make it more clear, you can ls -lF to include a / to the end of the directories info:
-rwxr-xr-x 1 user group 0 Jun 12 12:25 exec_file*
-rw-rw-r-- 1 user group 0 Jun 12 12:25 normal_file
drwxr-xr-x 16 user group 4096 May 24 12:46 dir/
So ls -lF | grep /$ will do the same as ls -l | grep ^d.
It has two meanings. One as 'The New Idiot' above pointed out. The other, equally useful, is within character class expression, where it means negation: grep -E '[^[:digit:]]' accepts any character except a digit. The^` must be the first character within [].

Resources