Using symbolic links on a Linux system and other useful Linux commands for the user.

Posted: October 4, 2012. At: 7:03 PM. This was 5 years ago. Post ID: 4674

What is the difference between a hard link and a symbolic link? The output below shows the process of creating firstly a hard link and then a symbolic link. The hard link appears exactly the same as the original file; but the symbolic link displays as a link from the symlink to the original file. A hard link is the same as the original file. But a symlink is only a link to the file that it links to.

windows95    windows95-2  windows95-3  
[[email protected] Desktop]$ ln windows-95.png win95.png
[[email protected] Desktop]$ ln -s windows-95.png win95-2.png
[[email protected] Desktop]$ ls -hula win*png
lrwxrwxrwx 1 flynn flynn  14  04-10-12 04:53 pm win95-2.png -> windows-95.png
-rw-rw-r-- 2 flynn flynn 69K  21-09-12 12:46 am win95.png
-rw-rw-r-- 2 flynn flynn 69K  21-09-12 12:46 am windows-95.png
[[email protected] Desktop]$

After deleting the file that the two links reference the hard link is still the same size; but the symlink is highlighted in red on a black background. This means that the file it is linking to is gone.

[[email protected] Desktop]$ ls -hula win*png
lrwxrwxrwx 1 flynn flynn  14  04-10-12 04:53 pm win95-2.png -> windows-95.png
-rw-rw-r-- 1 flynn flynn 69K  21-09-12 12:46 am win95.png
[[email protected] Desktop]$

To easily find out what groups your user is a member of use the id command. This will display all of the groups that you are a member of and their GID.

[[email protected] Desktop]$ id
uid=1000(flynn) gid=1000(flynn) groups=1000(flynn),4(adm),24(cdrom),27(sudo),30(dip),44(video),46(plugdev),100(users),109(lpadmin),127(sambashare)

This command will also perform this function with a nice; easily readable output.

[[email protected] Desktop]$ cat /etc/group | grep $LOGNAME
adm:x:4:flynn,swift,hoshi
cdrom:x:24:flynn,hoshi
sudo:x:27:flynn,hoshi
dip:x:30:flynn,hoshi
video:x:44:flynn
plugdev:x:46:flynn,hoshi
users:x:100:flynn,hoshi
lpadmin:x:109:flynn,hoshi
sambashare:x:127:flynn,hoshi
flynn:x:1000:
[[email protected] Desktop]$

To count how many users are logged into a Linux system; use the who command with the -q parameter.

[[email protected] Desktop]$ who -q
flynn
# users=1

This is the command used to view the /etc/passwd entry for a particular user. This is not the user I am using but you are welcome to try and break this password hash if you want.

[[email protected] Desktop]$ sudo cat /etc/shadow | grep hoshi
hoshi:$6$9LBk33Zo$jY3tJmENjLMaawo6eV83C2EWcOBnJME8blVZsan4LHPfMwX4pNMAcwsOkx1oMn.d0UQskNAL5r2f7Rt0gNn6/.:15617:0:99999:7:::
1 responses to “Using symbolic links on a Linux system and other useful Linux commands for the user.

Leave a Reply