|
||||||||||||||||||||||||||||||||||||||||||||||||||
06-14-2024 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Video recording –
open in new tab |
||||||||||||||||||||||||||||||||||||||||||||||||||
Command line |
||||||||||||||||||||||||||||||||||||||||||||||||||
Input and output |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ pwd /home/zafar01 pwd – print working directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
clear - Clears the screen |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ touch file1 touch - Creates a file |
||||||||||||||||||||||||||||||||||||||||||||||||||
ls - List the content of the directory [zafar01@zmpt00 ~]$ ls file1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
ls -l - -l is considered flag, it is used in combination of with ls - Ls -l – this will show you long list information [zafar01@zmpt00 ~]$ ls -l total 0 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ touch file3 file4 file5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ ls file1 file2 file3 file4 file5 [zafar01@zmpt00 ~]$ ls -l total 0 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ touch x1 x2 x3 x4 x5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ touch y1 y2 y3 y4 y5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ ls -l total 0 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Use * to for filtering the files [zafar01@zmpt00 ~]$ ls -l x* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ ls -l f* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ls -l *5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ls -l *i* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ ls -l *il* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Hidden files - -a brings up hidden files [zafar01@zmpt00 ~]$ ls -la total 32 drwx------. 6 zafar01 zafar01 4096
Jun 14 09:02 . drwxr-xr-x. 20 root root 4096 Jun 14 08:31 .. -rw-------. 1 zafar01 zafar01 290 Jun 11 18:04 .bash_history -rw-r--r--. 1 zafar01 zafar01 18 Nov 1 2022 .bash_logout -rw-r--r--. 1 zafar01 zafar01 141 Nov 1 2022 .bash_profile -rw-r--r--. 1 zafar01 zafar01 492 Nov 1 2022 .bashrc |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ls -la .x* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:10 .xfile [zafar01@zmpt00 ~]$ ls -la total 32 drwx------. 6 zafar01 zafar01 4096
Jun 14 09:10 . drwxr-xr-x. 20 root root 4096 Jun 14 08:31 .. -rw-------. 1 zafar01 zafar01 290 Jun 11 18:04 .bash_history -rw-r--r--. 1 zafar01 zafar01 18 Nov 1 2022 .bash_logout -rw-r--r--. 1 zafar01 zafar01 141 Nov 1 2022 .bash_profile -rw-r--r--. 1 zafar01 zafar01 492 Nov 1 2022 .bashrc drwxr-xr-x. 10 zafar01 zafar01 4096 Jun 11 17:35 .cache drwxr-xr-x. 9 zafar01 zafar01 4096 Jun 11 17:30 .config -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:52 file1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 drwx------. 4 zafar01 zafar01 32 Jun 11 17:24 .local drwxr-xr-x. 4 zafar01 zafar01 39 Jun 11 16:51 .mozilla -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x5 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:10 .xfile -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
History 37 touch x1 x2 x3 x4 x5 38 touch y1 y2 y3 y4 y5 39 ls -l 40 clear 41 ls -l x* 42 ls -l 43 ls -l x* 44 ls -l f* 45 ls -l *5 46 ls -l *i* 47 ls -l *il* 48 clear 49 ls -la 50 clear 51 touch .xfile 52 ls 53 ls -a 54 ls -la .x* 55 ls -la 56 clear 57 history 58 clear 59 history [zafar01@zmpt00 ~]$ !43 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ !43 ls -l x* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x5 |
||||||||||||||||||||||||||||||||||||||||||||||||||
rm - Remove files [zafar01@zmpt00 ~]$ rm file1 [zafar01@zmpt00 ~]$ ls -l f* -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:57 file2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 08:59 file5 [zafar01@zmpt00 ~]$ rm f* < --- # Removes all files starting with f [zafar01@zmpt00 ~]$ ls -l f* ls: cannot access 'f*': No such file or directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ rm *5 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ ls -l total 0 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ mkdir redh-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
. < --- print working directory [present working directory] ├── redh-hat ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ls -al total 32 drwx------. 7 zafar01 zafar01 4096 Jun 14 09:20 . drwxr-xr-x. 20 root root
4096 Jun 14 08:31 .. . Single dot is present working directory .. two dot is the parent directory of present working directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ tree . < --- # parent directory of redh-hat [/home/zafar01] ├── redh-hat < --- # parent directory of black-hat │ └── black-hat < --- # directory ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 2 directories, 8 files [zafar01@zmpt00 ~]$ pwd /home/zafar01 |
||||||||||||||||||||||||||||||||||||||||||||||||||
cd - cd is used to change the directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
Path /home/zafar01/redh-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 black-hat]$ pwd /home/zafar01/redh-hat/black-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
Absolute path /home/zafar01/redh-hat/black-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 black-hat]$ pwd /home/zafar01/redh-hat/black-hat [zafar01@zmpt00 black-hat]$ [zafar01@zmpt00 black-hat]$ cd .. < -- # takes you one level to parent of directory [zafar01@zmpt00 redh-hat]$ cd .. < -- # takes you one level to parent of directory [zafar01@zmpt00 ~]$ pwd /home/zafar01 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Relative path for black-hat directory redh-hat/black-hat/ |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ cd redh-hat/black-hat/ [zafar01@zmpt00 black-hat]$ pwd /home/zafar01/redh-hat/black-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
cd - simply typing cd make you jump to your home directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
Changing directory using absolute path [zafar01@zmpt00 ~]$ cd /home/zafar01/redh-hat/black-hat [zafar01@zmpt00 black-hat]$ pwd /home/zafar01/redh-hat/black-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
cp - this is copy command |
||||||||||||||||||||||||||||||||||||||||||||||||||
Copy using relative path
[zafar01@zmpt00 ~]$ cp x1 redh-hat/black-hat/ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ └── black-hat │ └──
x1 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 2 directories, 9 files |
||||||||||||||||||||||||||||||||||||||||||||||||||
Copy using absolute path
cp x2 /home/zafar01/redh-hat/black-hat/ [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ └── black-hat │ ├── x1 │ └── x2 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 2 directories, 10 files |
||||||||||||||||||||||||||||||||||||||||||||||||||
Copying multiple files [zafar01@zmpt00 ~]$ cp x* /home/zafar01/redh-hat [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ └── x4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
mv -
this
is move command -
files
physically get moved |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ mv y* /home/zafar01/redh-hat/black-hat/ [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ ├── x4 │ │ ├── y1 │ │ ├── y2 │ │ ├── y3 │ │ └── y4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 └── x4 2 directories, 16 files [zafar01@zmpt00 ~]$ |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ mv /home/zafar01/redh-hat/black-hat/y* . [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ └── x4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ mkdir white-hat [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ └── x4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── white-hat < --- new directory in my home directory ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Move entire directory
[zafar01@zmpt00 ~]$ mv redh-hat/black-hat/ white-hat/ [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── white-hat │ └── black-hat │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 3 directories, 16 files |
||||||||||||||||||||||||||||||||||||||||||||||||||
Relative path
Absolute path
[zafar01@zmpt00 ~]$ cp -r white-hat/black-hat/ redh-hat/ [zafar01@zmpt00 ~]$ tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ └── x4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── white-hat │ └── black-hat │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 4 directories, 20 files |
||||||||||||||||||||||||||||||||||||||||||||||||||
06-21-2025 Video recording – open in new tab
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Ccho - this command repeats the text as output [zafar01@zmpt00 ~]$ echo [zafar01@zmpt00 ~]$ echo this is linux course this is linux course |
||||||||||||||||||||||||||||||||||||||||||||||||||
Running multiple commands |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ echo this is pwd;pwd;echo this is ls -l;echo;ls -l;echo this is tree;echo;tree this is pwd /home/zafar01 this is ls -l total 0 drwxr-xr-x. 3 zafar01 zafar01 63 Jun 14 10:40 redh-hat drwxr-xr-x. 3 zafar01 zafar01 23 Jun 14 10:38 white-hat -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y4 this is tree . ├── redh-hat │ ├── black-hat │ │ ├── x1 │ │ ├── x2 │ │ ├── x3 │ │ └── x4 │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── white-hat │ └── black-hat │ ├── x1 │ ├── x2 │ ├── x3 │ └── x4 ├── x1 ├── x2 ├── x3 ├── x4 ├── y1 ├── y2 ├── y3 └── y4 4 directories, 20 files |
||||||||||||||||||||||||||||||||||||||||||||||||||
Alias - you can create your own command - This is good for running multiple commands |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ alias zafar="ls -l; pwd;" [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ zafar total 0 drwxr-xr-x. 3 zafar01 zafar01 63 Jun 14 10:40 redh-hat drwxr-xr-x. 3 zafar01 zafar01 23 Jun 14 10:38 white-hat -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0
Jun 14 09:02 y4 /home/zafar01 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ alias alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias xzegrep='xzegrep --color=auto' alias xzfgrep='xzfgrep --color=auto' alias xzgrep='xzgrep --color=auto' alias zafar='ls -l; pwd;' alias zegrep='zegrep --color=auto' alias zfgrep='zfgrep --color=auto' alias zgrep='zgrep --color=auto' |
||||||||||||||||||||||||||||||||||||||||||||||||||
To remove alias [zafar01@zmpt00 ~]$ unalias zafar |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
vi text-file |
||||||||||||||||||||||||||||||||||||||||||||||||||
- i #< -- to enter the edit mode |
||||||||||||||||||||||||||||||||||||||||||||||||||
- esc #< -- this will exit edit mode and put you in command mode |
||||||||||||||||||||||||||||||||||||||||||||||||||
esc : x save and exit the file |
||||||||||||||||||||||||||||||||||||||||||||||||||
cat - this command reads the content of the file [zafar01@zmpt00 ~]$ cat text-file this is linux this is vi editor today is saturday |
||||||||||||||||||||||||||||||||||||||||||||||||||
Commonly used vi editor commands |
||||||||||||||||||||||||||||||||||||||||||||||||||
- dd deletes the line where the cursor is located |
||||||||||||||||||||||||||||||||||||||||||||||||||
- o opens new line in insert mode |
||||||||||||||||||||||||||||||||||||||||||||||||||
- esc #< ------ this will exit edit mode and put you in command mode - q #< --------- quits the file, when no changes were made - q! #< --------- quits discarding changes, if you have edited the file - yy #< ---------- copies the line where the cursor is - u #< --------- undo your last action - x #< --------- deletes the letter where ever is present - /linux #< --------- searches for the pattern in the file - :%s/linux/RED-HAT #< --- %s invokes search /linux - pattern - /RED-HAT replaced word - :set number #< --- enables the line number |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
cat - Concatenate – it reads the file and display the output |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ cat text-file this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT |
||||||||||||||||||||||||||||||||||||||||||||||||||
Three important redirectors
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Standard
input 0< [zafar01@zmpt00 ~]$ cat text-file this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT [zafar01@zmpt00 ~]$ cat 0< text-file this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT |
||||||||||||||||||||||||||||||||||||||||||||||||||
Standard
output 1> [zafar01@zmpt00 ~]$ cat text-file this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT [zafar01@zmpt00 ~]$ cat text-file 1> x1 [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ cat x1 this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT [zafar01@zmpt00 ~]$ cat text-file >> x1 #< --- this double >> adds to the end of the file [zafar01@zmpt00 ~]$ cat x1 this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT [zafar01@zmpt00 ~]$ cat text-file > x1 #< -- this single > overwrites the file [zafar01@zmpt00 ~]$ cat x1 this is RED-HAT this is vi editor today is saturday this is RED-HAT this is RED-HAT |
||||||||||||||||||||||||||||||||||||||||||||||||||
Standard
error 2> [zafar01@zmpt00 ~]$ ls -l /home/* ls: cannot open directory
'/home/abdul01': Permission denied ls: cannot open directory
'/home/abrar01': Permission denied ls: cannot open directory
'/home/ahmed01': Permission denied ls: cannot open directory
'/home/akram01': Permission denied ls: cannot open directory '/home/bit01':
Permission denied ls: cannot open directory
'/home/bruce01': Permission denied ls: cannot open directory
'/home/gregory01': Permission denied ls: cannot open directory
'/home/jony01': Permission denied ls: cannot open directory
'/home/khader01': Permission denied ls: cannot open directory
'/home/kumar01': Permission denied ls: cannot open directory
'/home/luis01': Permission denied ls: cannot open directory
'/home/mohamed01': Permission denied ls: cannot open directory
'/home/mubashir01': Permission denied ls: cannot open directory
'/home/muhamadou01': Permission denied ls: cannot open directory
'/home/rexford01': Permission denied ls: cannot open directory
'/home/samuel01': Permission denied ls: cannot open directory
'/home/sarmila01': Permission denied ls: cannot open directory '/home/sidney01': Permission denied /home/zafar01: total 12 drwxr-xr-x. 3 zafar01 zafar01 63 Jun 14 10:40 redh-hat -rw-r--r--. 1 zafar01 zafar01 85 Jun 21 09:29 text-file drwxr-xr-x. 3 zafar01 zafar01 23 Jun 14 10:38 white-hat -rw-r--r--. 1 zafar01 zafar01 85 Jun 21 10:09 x1 -rw-r--r--. 1 zafar01 zafar01 2224 Jun 21 10:14 x2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y1 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y3 |
||||||||||||||||||||||||||||||||||||||||||||||||||
What 2> sing does is, it filters out any errors and show you good out put For this to be working, you have send it to a file or /dev/null File – if you need to analyze the errors output /dev/null – if you don’t care about error output |
||||||||||||||||||||||||||||||||||||||||||||||||||
find - Find command file you looking in a directory |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ find . -name text-file ./text-file |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ find /home -name text-file /home/zafar01/text-file find: ‘/home/bit01’: Permission denied find: ‘/home/bruce01’: Permission denied find: ‘/home/sidney01’: Permission denied find: ‘/home/muhamadou01’: Permission denied find: ‘/home/sarmila01’: Permission denied find: ‘/home/luis01’: Permission denied find: ‘/home/gregory01’: Permission denied find: ‘/home/jony01’: Permission denied find: ‘/home/mubashir01’: Permission denied find: ‘/home/abdul01’: Permission denied find: ‘/home/rexford01’: Permission denied find: ‘/home/samuel01’: Permission denied find: ‘/home/abrar01’: Permission denied find: ‘/home/khader01’: Permission denied find: ‘/home/ahmed01’: Permission denied find: ‘/home/akram01’: Permission denied find: ‘/home/mohamed01’: Permission denied find: ‘/home/kumar01’: Permission denied [zafar01@zmpt00 ~]$ find /home -name text-file 2> /dev/null /home/zafar01/text-file |
||||||||||||||||||||||||||||||||||||||||||||||||||
File is a file Folder is also a file |
||||||||||||||||||||||||||||||||||||||||||||||||||
Find using inode |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ls -i text-file 35416378 text-file [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ find /home -inum 35416378 2> /dev/null /home/zafar01/text-file [zafar01@zmpt00 ~]$ [zafar01@zmpt00 ~]$ find / -inum 35416378 2> /dev/null /home/zafar01/text-file |
||||||||||||||||||||||||||||||||||||||||||||||||||
grep - Use to search the specific word in the file - Use it as filter to give you output - It matches the pattern |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ cat text-file total 24 drwx------. 3 abdul01 abdul01 78 Jun 14 07:05 abdul01 drwx------. 3 abrar01 abrar01 78 Jun 14 07:05 abrar01 drwx------. 3 ahmed01 ahmed01 78 Jun 14 07:05 ahmed01 drwx------. 3 akram01 akram01 78 Jun 14 07:24 akram01 drwx------. 5 bit01 bit01 191 Jun 21 10:16 bit01 drwx------. 3 bruce01 bruce01 78 Jun 14 07:05 bruce01 drwx------. 6 gregory01 gregory01 4096 Jun 21 10:38 gregory01 drwx------. 6 jony01 jony01 4096 Jun 21 10:10 jony01 drwx------. 5 khader01 khader01 4096 Jun 14 10:44 khader01 drwx------. 3 kumar01 kumar01 78 Jun 21 08:17 kumar01 drwx------. 3 luis01 luis01 78 Jun 14 07:05 luis01 drwx------. 5 mohamed01 mohamed01 134 Jun 14 08:50 mohamed01 drwx------. 3 mubashir01 mubashir01 78 Jun 14 07:05 mubashir01 drwx------. 7 muhamadou01 muhamadou01 4096 Jun
20 21:48 muhamadou01 drwx------. 3 rexford01 rexford01 113 Jun 21 10:05 rexford01 drwx------. 3 samuel01 samuel01 190 Jun 21 10:37 samuel01 drwx------. 9 sarmila01 sarmila01
4096 Jun 14 10:44 sarmila01 drwx------. 3 sidney01 sidney01 78 Jun 14 07:05 sidney01 drwx------. 8 zafar01 zafar01 4096 Jun 21 09:29 zafar01 [zafar01@zmpt00 ~]$ cat text-file | grep greg drwx------. 6 gregory01 gregory01 4096 Jun 21 10:38 gregory01 |
||||||||||||||||||||||||||||||||||||||||||||||||||
-i – Ignores case [zafar01@zmpt00 ~]$ cat text-file | grep -i greg drwx------. 6 gregory01 gregory01 4096 Jun 21 10:38 gregory01 GREGORY [zafar01@zmpt00 ~]$ |
||||||||||||||||||||||||||||||||||||||||||||||||||
wc - Wod count [zafar01@zmpt00 ~]$ wc text-file 23 176 1260 text-file
|
||||||||||||||||||||||||||||||||||||||||||||||||||
06-29-2025 Video Recording – open in new tab |
||||||||||||||||||||||||||||||||||||||||||||||||||
Head - This command will read the file, but output will by default be 10 lines - You can use head to many lines as possible - But will start from first line |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ head -15 text-file # < -- show top 15 lines [zafar01@zmpt00 ~]$ head -5 text-file # < -- show top 5 lines |
||||||||||||||||||||||||||||||||||||||||||||||||||
Tail - Reads the bottom 10 lines by default - You can add switch for the desired number of lines - Tail -5 – display bottom 5 lines - Tail –f to view the real-time activity of the file - Example /var/log/secure |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ tail -5 text-file # < -- show bottom 5 lines [zafar01@zmpt00 ~]$ tail -15 text-file # < -- show bottom 15 lines |
||||||||||||||||||||||||||||||||||||||||||||||||||
To see the live activity of a file use tail -f [zafar01@zmpt00 ~]$ sudo tail -f /var/log/secure |
||||||||||||||||||||||||||||||||||||||||||||||||||
sort - This command will sor the output in alphabetical order
|
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ sort sort-file a b c c d d d f i m p q q r z [zafar01@zmpt00 ~]$ sort -r sort-file # < --- sorts in reverse order |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ awk '{print $3, $4}' sort-file column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 column3 column4 [zafar01@zmpt00 ~]$ awk '{print $3, $4,$1,$2,$1}' sort-file column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 column3 column4 column1 column2 column1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ awk '{print $3," " $4}' sort-file # < -- use quote and space to add space to output column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 column3
column4 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ uniq sort-file column1 column2 column3 column4 column2 column2 column3 column4 column1 column2 column3 column4 column4 column3 column2 column1 column3 column3 column2 column1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ date Sat Jun 28 08:57:05 AM CDT 2025 |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ cal June 2025 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [zafar01@zmpt00 ~]$ cal 09 2025 September 2025 Su Mo Tu We Th Fr Sa 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
||||||||||||||||||||||||||||||||||||||||||||||||||
W or who - Displays who is logged in |
||||||||||||||||||||||||||||||||||||||||||||||||||
Last - Displays the login activity of users |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ free -h total used free shared buff/cache available Mem:
1.7Gi 809Mi 427Mi 46Mi 747Mi 961Mi Swap: 2.0Gi 0B 2.0Gi [zafar01@zmpt00 ~]$ |
||||||||||||||||||||||||||||||||||||||||||||||||||
du - Disk usage - Displays the size of the file or folder |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ du -hx . --max-depth=1 0 ./black-hat 0 ./white-hat 4.4M . [zafar01@zmpt00 redh-hat]$ ls -ltrh total 4.3M -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 x3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y4 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y3 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y2 -rw-r--r--. 1 zafar01 zafar01 0 Jun 14 09:02 y1 drwxr-xr-x. 3 zafar01 zafar01 23 Jun 14 10:38 white-hat drwxr-xr-x. 2 zafar01 zafar01 46 Jun 14 10:40 black-hat -rw-r--r--. 1 zafar01 zafar01 85 Jun 21 10:09 x1 -rw-r--r--. 1 zafar01 zafar01 2.2K Jun 21 10:14 x2 -rw-r--r--. 1 zafar01 zafar01 1.3K Jun 21 10:51 text-file -rw-r--r--. 1 zafar01 zafar01 388 Jun 28 09:03 sort-file -rw-r--r--. 1 zafar01 zafar01 121 Jun 28 09:05 new-sort-file -rwxr-xr-x. 1 root root 365K Jun 28 09:10 messages -rw-r--r--. 1 zafar01 zafar01 4.0M Jun 28 09:13 messages1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ top top - 09:17:31 up 14 days, 17:17, 7 users, load average: 0.00, 0.00, 0.00 Tasks: 196 total, 1 running, 194 sleeping, 1 stopped, 0 zombie %Cpu(s): 0.7 us, 1.7 sy, 0.0 ni, 97.4 id, 0.0 wa, 0.3 hi, 0.0 si, 0.0 st MiB Mem : 1771.1 total, 192.9 free, 899.7 used, 907.2 buff/cache MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 871.4 avail Mem |
||||||||||||||||||||||||||||||||||||||||||||||||||
97.4 id – this means that 97% of the CPU is idle [not busy] %Cpu(s): 2.7 us, 1.7 sy, 0.0 ni, 95.3 id, 0.0 wa, 0.3 hi, 0.0 si, 0.0 st |
||||||||||||||||||||||||||||||||||||||||||||||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 189703 root 20 0 19352 11308 9288 S 1.7 0.6 0:00.05 sshd 189713 bit01 20 0 229632 9436 6212 S 1.7 0.5 0:00.05 vim 189516 zafar01 20 0 225900 4128 3500 R 0.7 0.2 0:01.69 top 189526 gregory+ 20 0 226032 4216 3356 S 0.7 0.2 0:01.51 top 189614 samuel01 20 0 225900 4004 3376 S 0.7 0.2 0:03.19 top 16 root 20 0 0 0 0 R 0.3 0.0 0:18.13 rcu_preempt 791 root 20 0 193320 18264 10856 S 0.3 1.0 3:03.97 rsyslogd 187454 bit01 20 0 224224 6000 3884 S 0.3 0.3 0:00.96 bash 187562 gregory+ 20 0 19520 7408 5112 S 0.3 0.4 0:01.16 sshd 189113 samuel01 20 0 19520 7364 5068 S 0.3 0.4 0:00.93 sshd 1 root 20 0 106588 16348 10420 S 0.0 0.9 1:36.16 systemd |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 36 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Which - this command will show you the location of the command or package - also a good indication if a command or package is installed
|
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ which pwd /usr/bin/pwd [zafar01@zmpt00 ~]$ which firefox /usr/bin/which: no firefox in (/home/zafar01/.local/bin:/home/zafar01/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin) |
||||||||||||||||||||||||||||||||||||||||||||||||||
Pipe - | this is a pipe key - Pipe is used for run multiple commands
Primary command | secondary command | thrid commands |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ cat furits | grep apple apple apple pineapple pineapple pineapple [zafar01@zmpt00 redh-hat]$ cat furits | grep apple | grep pine pineapple pineapple pineapple [zafar01@zmpt00 redh-hat]$ cat furits | grep Apple [zafar01@zmpt00 redh-hat]$ cat furits | grep -i Apple apple apple pineapple pineapple pineapple |
||||||||||||||||||||||||||||||||||||||||||||||||||
gzip - Gzip is used for zipping file and compressing[reducing size] it - It adds the extension .gz |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ ls -ltrh messages1 -rw-r--r--. 1 zafar01 zafar01 11M Jun 28 10:01 messages1 [zafar01@zmpt00 redh-hat]$ gzip messages1 -rw-r--r--. 1 zafar01 zafar01 748K Jun 28 10:01 messages1.gz #< -- adds extension .gz Messages1 is now at under 1MB from being 11 MB |
||||||||||||||||||||||||||||||||||||||||||||||||||
Gunzip - Unzips and uncompresses the file - Removes .gz extension - Restores to original form |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 redh-hat]$ ls -ltrh messages1 -rw-r--r--. 1 zafar01 zafar01 11M Jun 28 10:01 messages1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
tar - It convers the folder to a single file and adds .tar extension - It does not compressess or reduce the size of a folder - Its keeps the origiznal folder as is but creates another file with .tar extension |
||||||||||||||||||||||||||||||||||||||||||||||||||
C – create V – verbose [show you on screen what is being tar] F - folder
[zafar01@zmpt00 ~]$ tar -cvf redh-hat.tar redh-hat/ redh-hat/ redh-hat/x1 redh-hat/x2 redh-hat/x3 redh-hat/x4 redh-hat/black-hat/ redh-hat/black-hat/x1 redh-hat/black-hat/x2 redh-hat/black-hat/x3 redh-hat/black-hat/x4 redh-hat/new-sort-file redh-hat/sort-file redh-hat/text-file redh-hat/white-hat/ redh-hat/white-hat/black-hat/ redh-hat/white-hat/black-hat/x1 redh-hat/white-hat/black-hat/x2 redh-hat/white-hat/black-hat/x3 redh-hat/white-hat/black-hat/x4 redh-hat/y1 redh-hat/y2 redh-hat/y3 redh-hat/y4 redh-hat/messages redh-hat/furits redh-hat/messages1 |
||||||||||||||||||||||||||||||||||||||||||||||||||
total 780K drwxr-xr-x. 4 zafar01 zafar01 4.0K Jun 28 10:04 redh-hat -rw-r--r--. 1 zafar01 zafar01 774K Jun 28 10:07 redh-hat.tar.gz |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ rm -rf redh-hat |
||||||||||||||||||||||||||||||||||||||||||||||||||
X – extract V – verbose F - folder [zafar01@zmpt00 ~]$ tar -xvf redh-hat.tar.gz |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ tar -xvf redh-hat.tar.gz redh-hat/ redh-hat/x1 redh-hat/x2 redh-hat/x3 redh-hat/x4 redh-hat/black-hat/ redh-hat/black-hat/x1 redh-hat/black-hat/x2 redh-hat/black-hat/x3 redh-hat/black-hat/x4 redh-hat/new-sort-file redh-hat/sort-file redh-hat/text-file redh-hat/white-hat/ redh-hat/white-hat/black-hat/ redh-hat/white-hat/black-hat/x1 redh-hat/white-hat/black-hat/x2 redh-hat/white-hat/black-hat/x3 redh-hat/white-hat/black-hat/x4 redh-hat/y1 redh-hat/y2 redh-hat/y3 redh-hat/y4 redh-hat/messages redh-hat/furits redh-hat/messages1 [zafar01@zmpt00 ~]$ ls -l total 780 drwxr-xr-x. 4 zafar01 zafar01 4096 Jun 28 10:04 redh-hat -rw-r--r--. 1 zafar01 zafar01 792039 Jun 28 10:07 redh-hat.tar.gz |
||||||||||||||||||||||||||||||||||||||||||||||||||
Stat - Displays detailed informaiton regarding file or folder - Important informaiton to consider is inode |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ stat redh-hat.tar.gz File: redh-hat.tar.gz Size: 792039 Blocks: 1552 IO Block: 4096 regular file Device: fd00h/64768d Inode: 35657439 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ zafar01) Gid: ( 1000/ zafar01) Context: unconfined_u:object_r:user_home_t:s0 [selinux] Access: 2025-06-28 10:14:14.885562820 -0500 Modify: 2025-06-28 10:07:36.311768694 -0500 Change: 2025-06-28 10:11:29.581403990 -0500 Birth: 2025-06-28 10:11:29.134400851 -0500 |
||||||||||||||||||||||||||||||||||||||||||||||||||
Inode Inode: 35657439
Owner of the file Group of the file Type of the file – file or directory Permissions Date and time of the file modified, created, accessed etc., Number of links Block information |
||||||||||||||||||||||||||||||||||||||||||||||||||
Links |
||||||||||||||||||||||||||||||||||||||||||||||||||
Ln - Two types of links for a file - Hard link and soft link |
||||||||||||||||||||||||||||||||||||||||||||||||||
Hard link - It has same inode number - You have to provide source and destination absolute paths - Any change to content of the file will be updated on both files - Hard linke files are essentially duplicates fo each other - If the original fiel si deleted, then hard linked file will survive - Hard link for directories are not allowed |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ ln redh-hat/furits furits-1
Location and name can have variation |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
Hard linked files have same inode They are essentially duplicate of each other Any updates on either side, updates both If one is deleted, other survives with data [zafar01@zmpt00 ~]$ ls -i furits-1 822965 furits-1 [zafar01@zmpt00 ~]$ ls -i redh-hat/furits 822965 redh-hat/furits |
||||||||||||||||||||||||||||||||||||||||||||||||||
[zafar01@zmpt00 ~]$ rm -rf redh-hat/furits #< --- delete original file [zafar01@zmpt00 ~]$ ls -i redh-hat/furits ls: cannot access 'redh-hat/furits': No such file or directory [zafar01@zmpt00 ~]$ ls -i furits-1 822965 furits-1 [zafar01@zmpt00 ~]$ cat furits-1 #< --- hard linked file survived apple apple buleberry blueberry orange is citrus orange is citrus orange is citrus strawberry pineapple pineapple pineapple I am adding this line from hard link this is test |
||||||||||||||||||||||||||||||||||||||||||||||||||
Softlink
- Referred to as symbolic link or sym link - You have to provide ABSOLUTE path for the soruce and destination - Soft link has different inode number - Most of the time soft link is used to grant read access to user or application to a restricted file - Updating soft link – updates origianl file - Delting original file will render soft link useless - Soft is allowd for directories |