Posted: . At: 7:03 PM. This was 5 years ago. Post ID: 4674
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



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


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. A hardlink points to the same data that the original file does, so if the hardlink is deleted, the original file still exists. If the original file is deleted, then the hardlink file will still exist, and it contains a pointer to the original file location. When it is deleted, it will be gone for good.

Example.

┌─[jason@darkstar][~/Documents]
└──╼ $ln packages.txt packages2.txt

I have made a hardlink to the file, now I am going to delete the original file.

┌─[jason@darkstar][~/Documents]
└──╼ $rm packages.txt

Now I have deleted the original file, but the hardlink copy still exists.

┌─[jason@darkstar][~/Documents]
└──╼ $ls
ipinfo  KING_OF_THE_HILL_V4.Altis  KING_OF_THE_HILL_V4.Altis.pbo  packages2.txt  random.bin  ssh_time_attack.py  Stuff  userlist.txt  vpnbook-euro2-tcp443.ovpn

So, that is how a hardlink works. Good way to make a copy of a file, it will still exist when the original is deleted.

windows95    windows95-2  windows95-3  
[flynn@flynn-grid-runner Desktop]$ ln windows-95.png win95.png
[flynn@flynn-grid-runner Desktop]$ ln -s windows-95.png win95-2.png
[flynn@flynn-grid-runner 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
[flynn@flynn-grid-runner 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.

[flynn@flynn-grid-runner 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
[flynn@flynn-grid-runner 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.

[flynn@flynn-grid-runner 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.

[flynn@flynn-grid-runner 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:
[flynn@flynn-grid-runner Desktop]$

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

[flynn@flynn-grid-runner 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.

[flynn@flynn-grid-runner Desktop]$ sudo cat /etc/shadow | grep hoshi
hoshi:$6$9LBk33Zo$jY3tJmENjLMaawo6eV83C2EWcOBnJME8blVZsan4LHPfMwX4pNMAcwsOkx1oMn.d0UQskNAL5r2f7Rt0gNn6/.:15617:0:99999:7:::

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.