Good evening. This is the 5th in-house study session. Due to the influence of Corona, it became a remote study session, but let's do it again this time without losing! !!
--Directory operation --Move and view working directory (cd, pwd) --Go back and forth between directories (pushd, popd) --Check disk usage (du) --Display disk capacity information (df) --Links and inodes --Link setting (ln)
[2nd](https://qiita.com/onukid007/items/149dd210bd96cd43bb21#%E7%89%B9%E6%AE%8A%E3%81%AA%E3%83%87%E3%82%A3 % E3% 83% AC% E3% 82% AF% E3% 83% 88% E3% 83% AA% E8% A8% 98% E5% 8F% B7), but it is a review. cd command (Change working Directory): Command to change the position of the current directory pwd command (Print Working Directory): Command to display the name of the current directory
#Move by absolute specification $ cd /home/una/hoge/fuga #View current directory $ pwd /home/una/hoge/fuga #Go to the piyo directory $ cd piyo $ pwd /home/una/hoge/fuga/piyo
Special directory symbols are present to facilitate path specification.
~- is convenient, I often use it after learning.
You don't have to do
cd ../../ anymore ... !!
#Return to the previous directory cd ~- #One level up(parent)Move to the directory of cd .. #Move to your home directory cd ~ #Same as above cd
pushed command: A command to save the history of the working directory in a stacking expression and move to the specified directory. popd command: move folders according to recorded history
$ pwd /home/una/hoge #When stacking directories in a stack format.... $ pushd fuga/ ~/hoge/fuga ~ #It was piled up under hoge $ pwd /home/una/hoge/fuga #When popping.... $ popd ~/hoge ~ #fuga is now the retrieved stack contents $ pwd /home/una/hoge
I'm ashamed to say that this was the first command I knew. I thought it was an ancient command, but it played an important role as the basis of the computer as follows.
A stack is one of the basic data structures used in computers, and holds data in a last in first out (LIFO: Last In First Out; FILO: First In Last Out) structure. https://ja.wikipedia.org/wiki/%E3%82%B9%E3%82%BF%E3%83%83%E3%82%AF
df command (Disk Free): A command to display the free disk space I think that there are many opportunities to use it as a set with the du command introduced later.
For example, suppose your server is nearly full. When investigating the cause, you can use df to check the disk usage status and du to find out which file is squeezing the disk.
$ df Filesys 1K-Block can be used can be used%Mount position devtmpfs 485712 0 485712 0% /dev tmpfs 503664 0 503664 0% /dev/shm tmpfs 503664 624 503040 1% /run tmpfs 503664 0 503664 0% /sys/fs/cgroup /dev/xvda1 8376300 1724520 6651780 21% / tmpfs 100736 0 100736 0% /run/user/1000 #The h option makes the unit easy to see. $ df -h File system size used Remaining used%Mount position devtmpfs 475M 0 475M 0% /dev tmpfs 492M 0 492M 0% /dev/shm tmpfs 492M 656K 492M 1% /run tmpfs 492M 0 492M 0% /sys/fs/cgroup /dev/xvda1 8.0G 1.7G 6.4G 21% / tmpfs 99M 0 99M 0% /run/user/1000
du command (Disk Usage): A command that displays the size of disk usage.
|-a||Also shows the usage of each file in the directory|
|-b||Display in bytes|
|-k||Display in kilobytes(Default)|
|-s||Display only total size|
$ du 304 ./dir1 #Total size of dir1 used(Unit kilo) 656 ./dir2 #Total size of dir2 used 960 . #Total size #Kilobytes $ du -k 152 ./dir1 328 ./dir2 480 . #All directories $ du -a 304 ./dir1 656 ./dir2 ~abridgement~ 960 . #Total size $ du -s 960 .
ln command (LiNk): Command to set the link
There are two types of links: hard links and symbolic links.
Symbolic link: sample_s points to sample1. sample1 points to the file entity Hard link: sample_h and sample2 point to the same file entity
The superficial features are the same, but flexible symlinks are now the mainstream. The reason is as follows.
--Symbol links can also link directories --Symlinks can also link to files on another file system
This time I will touch on symbolic links.
|-s||Make it a symbolic link(
|-i||Confirm and execute when "Alias path name" already exists|
|-f||Force execution when "Alias path name" already exists|
#sample file creation $ echo This is sample1 > sample1 #Set a symbolic link $ ln -s sample1 sample_s #View files using symbolic links $ cat sample_s This is sample1
#View list $ ls -F sample1 sample_s@ #@Is a symbolic link mark #See list details $ ls -l total 8 -rw-r--r-- 1 una staff 16 3 10 06:45 sample1 lrwxr-xr-x 1 una staff 7 3 10 06:45 sample_s -> sample1 #Symbolic links are displayed as pointers
$ cat hoge/fuga This is sample3 #Make piyo which is a link of hoge $ ln -s hoge piyo #Display fuga using piyo $ cat piyo/fuga This is sample3
#Make a link with the same name $ ln -s hoge/sample1 . #Make a link called sample2 $ ln -s hoge/sample1 sample2 #Link content $ ls -l lrwxrwxrwx 1 una staff 12 March 10 06:55 sample1 -> hoge/sample1 lrwxrwxrwx 1 una staff 12 March 10 06:56 sample2 -> hoge/sample1 #Display specification with a link with the same name $ cat sample1 This is sample1. # hoge/Displaying sample1 #Display specification with the link name sample2 $ cat dfile2 This is sample1. #This is also the same
$ cat sample3 This is sample3 #Make piyo $ mkdir piyo #Specify with a relative path (no problem with an absolute path) $ ln -sf ../sample3 piyo/sample4 #Link destination $ ls -l piyo Total 0 lrwxrwxrwx 1 una staff 9 March 10 07:01 sample4 -> ../sample3 #Can be displayed..!! $ cat piyo/sample4 This is sample3
Link setting is a must-have command to become a linux chat deck. I used it somehow, but when I learned it again, I noticed a lot of new things ....
I think that the commands taken up this time are also basic commands. However, it was very interesting because there were options and backgrounds that I didn't know even with the commands I use every day. Even if you don't know the ancient commands, there may be some convenient ways to use them. In order not to forget, I would like to actively use it and let it soak into my body! !!
-Linux study session 1st: Virtual console and file operation -Linux study session 2nd: File operation -Linux study session 3rd: File deletion prohibition setting and search function -Linux study session 4th: File operation and directory operation