I just found a scenario which i (or someone new to linux) might accidentally rm file because user thought it's duplicated file. Let's say i have this two binary files:
[xiaobai@xiaobai note]$ ls -larthi /bin/seltr2
1054051 -rwxrwxrwx. 1 root root 3.4K Oct 30 22:54 /bin/seltr2*
[xiaobai@xiaobai note]$ ls -larthi /usr/bin/seltr2
1054051 -rwxrwxrwx. 1 root root 3.4K Oct 30 22:54 /usr/bin/seltr2*
Normally i wouldn't look at inode is same, i just look at the right hand side have -> sign or not. So the problem arise if /bin is symlink to /usr/bin:
[xiaobai@xiaobai note]$ ls -larthi /bin
16 lrwxrwxrwx. 1 root root 7 Nov 18 2014 /bin -> usr/bin/
So if user thought the file is not symlink and no different, user might rm it:
[xiaobai@xiaobai note]$ sudo rm /bin/seltr2
And finally realize that /usr/bin/seltr2 is same file and ask the rescue:
[xiaobai@xiaobai note]$ ls /usr/bin/seltr2
/home/xiaobai/ls: cannot access /usr/bin/seltr2: No such file or directory
So is there any simple way make ls take account of parent directory is a symlink, e.g:
[xiaobai@xiaobai note]$ ls -larthi /bin/seltr2
1054051 -rwxrwxrwx. 1 root root 3.4K Oct 30 22:54 /bin/seltr2* -> /usr/bin/seltr2*
I'm not always look at inode number. Is there better way to avoid this kind of potential mistake ?
ls
command is set to colorize file names by file type, however this is only based on the last element in the path. I'm not aware of a version which colorizes each item in the path. Also, you should be doing this kind of activity only in your home directory where you know what's going on.ls -l
. It's potential risks, not tied to root or system directories.