Chapter 3

Managing files from the command line

cd

cd                      # (cd və boşluq) əmri istifadəçinin home qovluğuna gedir
cd ~                    # istifadəçinin home qovluğuna gedir
cd -                    # əvvəl iş görülən qovluğa gedir
cd .                    # hazırki qovluğa gedir
cd ..                   # ierarxiyadakı yuxardakı qovluğa gedir
cd ../qovluq1/          # ierarxiyadakı yuxarıdakı qovluğun içindəki qovluq1-ə gedir
cd ./qovluq1/qovluq2    # hazırkı yerdəki qovluq1 içindəki qovluq2-ə gedir
cd qovluq1/qovluq2      # yuxarıdakı ilə eynidir

mkdir

# create two directories
mkdir dir1 dir2

# create two directories within one directory
mkdir -p dir1/dir2 dir1/dir3
or
mkdir -pv dir1/dir{2..3} # -v for verbose:

# mkdir: created directory 'dir1'
# mkdir: created directory 'dir1/dir2'
# mkdir: created directory 'dir1/dir3'.

rm

To remove empty directory:

rm -d
rmdir
rm -r

To remove files:

rm -i # asks for verification
rm -f # suspress verification

ls

[root@localhost alicenab]# ls ~root
anaconda-ks.cfg

[root@localhost alicenab]# ls ~alicenab
dir1

ls -laiR
# -l list
# -a all (hidden files)
# -i inode numbers
# -R recursive

Aşağıdakı komandanın nəticəsi kimi ilk hərifn nə olması nəyi bildirir?

[root@localhost ~]$ ls -la test
-rw-r--r--. 1 student student 0 Oct  2 00:39 test

# - bu adi fayldır
# d bu qovluqdur
# l bu soft linkdir

Xüsusi fayllar:
# b block xüsusi faylı
# c character xüsusi faylı
# p inter-process communication (IPC) xüsusi faylı
# s socket xüsusi faylı

1) Əgər fayllar müxtəlif filesystemdədirsə hardlink işləməyəcək

2) Fayl sistemlərə baxmaq üçün df komandasını icra etmək lazımdır. Məsələn aşağıdakı / filesystemi ilə /boot filesystemi fərqlidir çünki sol tərəfdə fərqli filesystem yazılmışdır.

Filesystem          1K-blocks    Used Available Use% Mounted on
devtmpfs                 4096       0      4096   0% /dev
tmpfs                 1861120       0   1861120   0% /dev/shm
tmpfs                  744452    9260    735192   2% /run
/dev/mapper/rl-root  47236572 1395140  45841432   3% /
/dev/nvme0n1p1        1038336  225844    812492  22% /boot
tmpfs                  372224       0    372224   0% /run/user/1000
tmpfs                  372224       0    372224   0% /run/user/0

2) Eyni fayldan yaradılmış bütün hard linklər eyni inode number-ə məxsus olur. inode number fayl sistemdə yalnız bir fayla aid ola bilər.

ln /home/alicenab/myfile.txt /tmp/hardlink.txt

Faylın inode number-inə baxmaq üçün aşağıdakı komandanı icra etmək lazımdır:

ls -i faylinadi.txt

Hardlinkdən fərqli olaraq, softlinklər eyni inode numberə aid olmurlar.

ln -s /home/alicenab/myfile.txt /tmp/softlink.txt
  1. Hard Links:

    • Same Inode Number: A hard link has the same inode number as the original file. It's essentially another name for the same file data on the disk.

    • Behaves Like the Original File: Any changes made to the hard link are reflected in the original file, and vice versa, because they are the same file at the disk level.

    • No Link to the Original Filename: Hard links are directly connected to the file data, not to the filename. If you delete or move the original file, the hard link remains valid and continues to access the file data.

    • Limitations: Hard links cannot span across different file systems and cannot be created for directories (to prevent potential issues like loops).

  2. Soft Links (Symbolic Links):

    • Different Inode Number: A soft link has a different inode number and is essentially a separate file that points to the original file's name or path.

    • Behaves Like a Shortcut: It acts like a pointer or a shortcut to the original file. If you edit a file through its symbolic link, you are actually editing the original file, because the symbolic link directs you to it.

    • Dependent on the Original Filename: Since a soft link points to the filename or path, if the original file is moved or deleted, the soft link becomes a "broken link" and cannot access the file data anymore.

    • More Flexible: Soft links can point to files on different file systems and can link to directories.

The choice between hard links and soft links usually depends on the specific needs:

  • Use Hard Links when you want a duplicate reference to the same file data on the same filesystem, which remains valid even if the original file is deleted.

  • Use Soft Links for more flexible linking, especially across filesystems, or for directory linking, but with the understanding that the link is dependent on the existence and location of the target file.

Command-line expansions

PATTERN
MATCHES

*

Any string of zero or more characters.

?

Any single character.

[abc...]

Any one character in the enclosed class (between the square brackets).

[!abc...]

Any one character not in the enclosed class.

[^abc...]

Any one character not in the enclosed class.

[[:alpha:]]

Any alphabetic character.

[[:lower:]]

Any lowercase character.

[[:upper:]]

Any uppercase character.

[[:alnum:]]

Any alphabetic character or digit.

[[:punct:]]

Any printable character not a space or alphanumeric.

[[:digit:]]

Any single digit from 0 to 9.

[[:space:]]

Any single white space character. This may include tabs, newlines, carriage returns, form feeds, or spaces.

Last updated

Was this helpful?