Describe the basic Linux commands as a memorandum.
command | Contents |
---|---|
Ctrl + b | Move backward by 1 character |
Ctrl + f | Move one character forward |
Ctrl + a | Move to the beginning of the line |
Ctrl + e | Move to the end of line |
Command to list files and directories
[wataru@localhost ~]$ ls
#If there is no argument, only files and directories are output.
123.gz diary.sh Downloads head.txt Pictures tmp wc.txt
case.sh dir1 echo.sh homesize.sh Public tree.sh
Desktop dir1.tar for.sh if.sh Templates Videos
diary Documents func.sh Music test.sh
[wataru@localhost ~]$ ls -l
#-When the l option is used, detailed information such as file attributes is also output.
total 64
-rw-rw-r--. 1 wataru wataru 97 Jul 3 20:39 123.gz
-rwxrwxr-x. 1 wataru wataru 71 Jun 22 04:52 case.sh
drwxr-xr-x. 2 wataru wataru 6 Jun 6 17:30 Desktop
drwxrwxr-x. 2 wataru wataru 28 Jun 24 04:46 diary
-rwxrwxr-x. 1 wataru wataru 174 Jun 24 04:45 diary.sh
drwxrwxr-x. 2 wataru wataru 60 Jul 3 04:28 dir1
-rw-rw-r--. 1 wataru wataru 10240 Jul 3 21:25 dir1.tar
#-The meaning of the detailed information output by the l option is as follows.
drwxrwxr-x. 2 wataru wataru 60 Jul 3 04:28 dir1
---------------------------------------------------
d :File type
rwxrwxr-x. :File mode
2 :Number of links
wataru :Owner
wataru :group
60 :file size
Jul 3 04:28 :Time stamp
[wataru@localhost ~]$ ls -a
#-If you use the a option, hidden files are also output.
#The file name is ".(Dot)Files starting with "are hidden files
. .cache dir1.tar head.txt Pictures Videos
.. case.sh Documents homesize.sh .pki .viminfo
123.gz .config Downloads .ICEauthority Public wc.tar.gz
[wataru@localhost ~]$ ls -F
#-If you use the F option, the file type will be output.
123.gz diary.sh* Downloads/ head.txt Pictures/ tmp/ wc.txt
case.sh* dir1/ echo.sh* homesize.sh* Public/ tree.sh*
Desktop/ dir1.tar for.sh* if.sh* Templates/
Type | symbol |
---|---|
Normal file | None |
directory | / |
Executable file | * |
Symbolic link | @ |
Show current directory
[wataru@localhost ~]$ pwd
/home/wataru
Change the current directory
[wataru@localhost ~]$ cd ..
[wataru@localhost home]$ pwd
/home
[wataru@localhost home]$
Create a directory
[wataru@localhost tmp]$ ls -l
total 0
[wataru@localhost tmp]$ mkdir testdir
#Enter the name of the directory to be created after the mkdir command
[wataru@localhost tmp]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 6 Jul 3 22:12 testdir
[wataru@localhost tmp]$ mkdir -p work/2020/07
#-Deep directories can be created at once using the p option
#In this case, it is created as work ⇒ 2020 ⇒ 07
[wataru@localhost tmp]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 6 Jul 3 22:12 testdir
drwxrwxr-x. 3 wataru wataru 18 Jul 3 22:16 work
[wataru@localhost tmp]$ cd work
[wataru@localhost work]$ ls -l
total 0
drwxrwxr-x. 3 wataru wataru 16 Jul 3 22:16 2020
[wataru@localhost work]$ cd 2020
[wataru@localhost 2020]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 6 Jul 3 22:16 07
Create a file
[wataru@localhost tmp]$ touch ./testdir/work2020.txt
#work2020 with touch.Created txt
[wataru@localhost tmp]$ ls -lF ./testdir/work2020.txt
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:21 ./testdir/work2020.txt
[wataru@localhost testdir]$ touch test.{01..10}
#You can create multiple files at once
#{01..10}Is a function called brace deployment
#You can create a serial number list
[wataru@localhost testdir]$ ls -l
total 0
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.01
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.02
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.03
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.04
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.05
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.06
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.07
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.08
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.09
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.10
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:21 work2020.txt
Delete files and directories
[wataru@localhost testdir]$ ls -l
total 0
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.01
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.02
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.03
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.04
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.05
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.06
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.07
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.08
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.09
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.10
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:21 work2020.txt
[wataru@localhost testdir]$ rm test.01 test.10
#Multiple files can be deleted
#In this example, test.01 test.Removed 10
[wataru@localhost testdir]$ ls -l
total 0
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.02
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.03
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.04
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.05
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.06
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.07
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.08
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:24 test.09
-rw-rw-r--. 1 wataru wataru 0 Jul 3 22:21 work2020.txt
[wataru@localhost tmp]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 146 Jul 5 03:59 testdir
drwxrwxr-x. 3 wataru wataru 18 Jul 3 22:16 work
[wataru@localhost tmp]$ rm testdir
#I get an error when deleting a directory with the rm command
#However,-You can delete a directory using the r option
#Files and directories in the directory to be deleted are also deleted at once.
rm: cannot remove 'testdir': Is a directory
[wataru@localhost tmp]$ rm -r testdir/
[wataru@localhost tmp]$ ls -l
total 0
drwxrwxr-x. 3 wataru wataru 18 Jul 3 22:16 work
[wataru@localhost work]$ rm -i work.01.txt
#-You can use the i option to check before deletion
rm: remove regular empty file 'work.01.txt'? y
[wataru@localhost work]$ ls
2020 work.03.txt work.05.txt work.07.txt work.09.txt
work.02.txt work.04.txt work.06.txt work.08.txt
wataru@localhost tmp]$ ls
testGo work
[wataru@localhost tmp]$ rmdir testGo/
#The rmdir command deletes an empty directory
[wataru@localhost tmp]$ ls
work
View file
[wataru@localhost work]$ cat work.02.txt
#The contents of the file are displayed
2020/07/05
test?cat
123445
[wataru@localhost work]$ cat -n work.02.txt
#-Use the n option to display the contents with line numbers
1 2020/07/05
2 test?cat
3 123445
4
Copy files and directories
[wataru@localhost work]$ ls
testgo work.03.txt work.05.txt work.07.txt work.09.txt
work.02.txt work.04.txt work.06.txt work.08.txt
[wataru@localhost work]$ cp work.0* testgo
#cp <Original> <Copy to>You can copy the file with
#「work.0*"like"*If you specify, you can copy multiple files at once.
[wataru@localhost work]$ cd testgo/
[wataru@localhost testgo]$ ls
work.02.txt work.04.txt work.06.txt work.08.txt
work.03.txt work.05.txt work.07.txt work.09.txt
[wataru@localhost work]$ cp -i work.0* testgo
#-If you use the i option, you can check it before executing it like the rm command.
wataru@localhost work]$ cp gogodur testgo
#Copying a directory results in an error
cp: -r not specified; omitting directory 'gogodur'
[wataru@localhost work]$ cp -r gogodur testgo
#-Can be copied using the r option
[wataru@localhost testgo]$ ls
gogodur work.03.txt work.05.txt work.07.txt work.09.txt
work.02.txt work.04.txt work.06.txt work.08.txt
Move files
[wataru@localhost testgo]$ mv work.03.txt gogodur
[wataru@localhost testgo]$ ls gogodur/
work.03.txt
[wataru@localhost testgo]$ ls
#Files moved by the mv command will disappear from the source
gogodur work.04.txt work.06.txt work.08.txt
work.02.txt work.05.txt work.07.txt work.09.txt
wataru@localhost testgo]$ ls
gogodur work.04.txt work.06.txt work.08.txt
work.02.txt work.05.txt work.07.txt work.09.txt
[wataru@localhost testgo]$ mv work.04.txt mvfile.txt
#If you specify a file as the move source and move destination with the mv command,
#File name is rewritten
[wataru@localhost testgo]$ ls
gogodur work.02.txt work.06.txt work.08.txt
mvfile.txt work.05.txt work.07.txt work.09.txt#
Create a link (give a different name to the file) You can omit long path names
wataru@localhost testgo]$ ln -s gogodur go
#-Use the s option to make a symbolic link
[wataru@localhost testgo]$ ls -l
total 4
lrwxrwxrwx. 1 wataru wataru 7 Jul 6 05:01 go -> gogodur
#You can see which file is specified by the arrow
drwxrwxr-x. 2 wataru wataru 25 Jul 6 04:46 gogodur
-rw-rw-r--. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
-rw-rw-r--. 1 wataru wataru 28 Jul 5 04:26 work.02.txt
Recommended Posts