Home Linux Linux Basics

Linux Basics

by Editorial Staff

Basic Commands

ls ???:  to view three characters of files

[root@localhost redhat]# ls ???
bi1  bi2

ls ????: to find four character files

[root@localhost redhat]# ls ????
shop

ls ?????: to view five characters file

[root@localhost redhat]# ls ?????
file1  kiran  movie  music

ls ?????e:  to view six character file here sixth character should be e

[root@localhost redhat]# ls ?????e
myfile

ls k????:  to find the files which is start the first character 

example:

here k is the character

[root@localhost redhat]# ls k????
kiran
[root@localhost redhat]# ls b??
bi1  bi2

rm –ri ???: to remove the character files

[root@localhost redhat]# rm -ri ???
rm: remove regular empty file 'bi1'

cp –ri ??? folder1: to copy the files into the directory

[root@localhost redhat]# cp -ri ??? folder1
[root@localhost redhat]#

mv ???? folder1: to move the filer into the directory

[root@localhost redhat]# mv ???? folder1
[root@localhost redhat]#

[ ]*: it matches the given characters from the files

[root@localhost redhat]# ls [kms]*
kiran  movie  music  myfile  subhan

ls [b-m]*: to find files between b to m character files from the directory

examples:

[root@localhost redhat]# ls [b-m]
[root@localhost redhat]# ls [a-k]
[root@localhost redhat]# ls [a-k]

ls [ !b-z ]: to find  only a character list from the directory

[root@localhost redhat]# ls [!b-z]
3

Links

Links are a connection between a file and the data on the disc. It is a shortcut file in Windows Operating System. Links allow more than one file name to refer to the same file.

In Linux there are two types of links

  1. Soft link (symbolic links)
  2. Hard link

What is the soft link?

Solf link is called as a Symbolic link. Each soft linked file contains a separate Inode value that points to the original file. soft links work across the different filesystems.it can be used to link to directories. if deleted the original file the soft link renders as useless. A symbolic link file is identified by the  “I” in the file system ($ls –I ).

Example :

$ln –s <source file> <linkfile>

How to create a Soft links?

ls -s /home/redhat/myfile /tmp/myfile

[root@localhost redhat]# ls -s /home/redhat/myfile /tmp/myfile
0 /home/redhat/myfile  0 /tmp/myfile
[root@localhost redhat]# cd /tmp/
[root@localhost tmp]# ls -l
total 20
-rw-r--r--. 1 root   root   2733 Aug  8 21:20 anaconda.log
-rw-r--r--. 1 root   root   2286 Aug  8 21:20 dbus.log
-rw-r--r--. 1 root   root      0 Aug  8 21:19 dnf.librepo.log
-rwx------. 1 root   root    291 Aug  8 21:18 ks-script-bglw4qr1
-rwx------. 1 root   root    701 Aug  8 21:17 ks-script-l7terbqp
-rw-r--r--. 1 root   root      0 Aug  9 17:08 myfile
-rw-r--r--. 1 root   root      0 Aug  8 21:19 packaging.log
-rw-r--r--. 1 root   root    131 Aug  8 21:19 program.log
drwxr-xr-x. 3 root   root    154 Apr 28 22:15 selfgz313918580
-rw-r--r--. 1 root   root      0 Aug  8 21:19 sensitive-info.log
drwx------. 3 root   root     17 Aug  9 17:03 systemd-private-e06e67fc2de645738b186eeb9f255f80-colord.service-7mkflh
drwx------. 3 root   root     17 Aug  9 17:05 systemd-private-e06e67fc2de645738b186eeb9f255f80-fwupd.service-zfYz6f
drwx------. 3 root   root     17 Aug  9 17:04 systemd-private-e06e67fc2de645738b186eeb9f255f80-geoclue.service-4gSxPf
drwx------. 3 root   root     17 Aug  9 17:02 systemd-private-e06e67fc2de645738b186eeb9f255f80-ModemManager.service-r8Pnqj
drwx------. 3 root   root     17 Aug  9 17:02 systemd-private-e06e67fc2de645738b186eeb9f255f80-rtkit-daemon.service-tE41mg
drwx------. 2 root   root      6 Aug  9 11:50 tracker-extract-files.0
drwx------. 2 redhat redhat    6 Aug  9 14:07 tracker-extract-files.1000

How to find the source and link file inode numbers area different?

The first file is /home/redhat/myfile

[root@localhost tmp]# ls -i /home/redhat/myfile
2707317 /home/redhat/myfile

The other file is /tmp/myfile

[root@localhost tmp]# ls -i /tmp/myfile
9248009 /tmp/myfile

Here you can see both Inod numbers are different

Something if you have done in the source file everything updated in the link file.

Source file:

Cat>>/home/redhat/myfile

[root@localhost tmp]# Cat>>/home/redhat/myfile
Hi..
goodmorning

Link File:

Cat /tmp/myfile

[root@localhost tmp]# Cat>>/tmp/myfile

If you want to remove source file

rm –i /home/redhat/myfile

if you delete original the file the link rended as useless 

 cat /tmp/myfile

Hard Likns:

A Hard link is a mirror copy of the original file. In the Linux filesystem, every file starts with a single hard link. If you create a new hard link to this file, the link counts increments by ‘1’ value. The source link. The source and link file inode numbers are the same. You cannot create across in the file system. If the original file is removed then the link will still show the content of the file.

Example:

$In <source file> <linkfile>

To find hard links:

$find / -inum inumber

To make a hard link into a soft link , use the –P flag:

$In –P <source file> <link file>

How to create a text file ?

[root@localhost redhat]# cat>>jay
hii
hello...
team

How to create hard link?

[root@localhost redhat]# ln /home/redhat/jay /home/redhat/myfile/jay

How to find incremental number?

[root@localhost redhat]# ls -l /home/redhat/jay
-rw-r--r--. 2 root root 20 Aug  9 22:19 /home/redhat/jay

‘2’ here the link file incremented by another ‘1’ value.

How to find the content is created or not?

[root@localhost redhat]# cat /home/redhat/myfile/jay
hii
hello...
team

How to find source file inode number?

[root@localhost redhat]# ls -i /home/redhat/jay
2590312 /home/redhat/jay

How to find link file inode number?

[root@localhost redhat]# ls -i /home/redhat/myfile/jay
2590312 /home/redhat/jay

You may also like

Leave a Comment

Contact US

Phone Number

+91 XXXXX XXXXX

Location

2nd floor, # 85, SGR Dental College Rd, Marathahalli, Bengaluru, Karnataka 560037

Email Address

contact@dbacentre.com

    dbacentre.com is a website that publishes practical and helpful out-of-the-box articles for aspirants like you and me. In addition, we seek to present exceptional, remarkable tutorials and tips that modern cloud professionals will appreciate.

     

    Subscribe now

    Edtior's Picks

    by mukilan
    Sql
    by mukilan

    ©2023 Mr DBA CENTRE. All Right Reserved. Designed and Developed by Begintech.in