0

1) How to check if the final destination file of a soft link actually exists or not ?

2) ls –ltr shows permission, user, group, size, date time, name etc. what command would you use if you want to see only the name column (nothing else, without grep or awk command)

jww
  • 97,681
  • 90
  • 411
  • 885
  • 4
    This should be on superuser stack exchange. Also, this is two separate questions. – Colin Emonds Jan 05 '16 at 14:52
  • For #2 please read the manual page for `ls`. For #1 you can use a `test` command. See the documentation. – lurker Jan 05 '16 at 15:01
  • `test -f` works. returns `0` on regular files and nondangling links to regular files and `1` otherwise. And it's quick cuz it's a builtin. Alternatively there's `test -r` which checks for readability by you, in addition to existence. I think that should match your request more closely. See `help test` for more information. – Petr Skocik Jan 05 '16 at 15:08

1 Answers1

2

1) How to check if the final destination file of a soft link actually exists or not ?

To achieve this with simple linux commands you can use stat -L, this will throw an error if the destination file does not exists. Also this command will return 0 if the destination file exists or >0 if it doesn't. So you can use echo $? after using it and check if it is not 0.

2) ls –ltr shows permission, user, group, size, date time, name etc. what command would you use if you want to see only the name column (nothing else, without grep or awk command)

You can just type ls -1 to get file names alone.

marian0
  • 664
  • 6
  • 15
Durga Viswanath Gadiraju
  • 3,896
  • 2
  • 14
  • 21