Linux command basics 2.
Find the file
[wataru@localhost testgo]$ find . -name work.08.txt -print
#find <Search start position> <Search conditions> <action>Format
#-print is an action that prints the pathname (if the action is omitted)-It is considered that print is specified)
./work.08.txt
[wataru@localhost testgo]$ find . -name 'work.0*' -print
#-If you use wildcards in name,''(Single quote)Surround with
#""(Double quotation)But yes
./work.02.txt
./work.05.txt
./work.06.txt
./work.07.txt
./work.08.txt
./work.09.txt
[wataru@localhost testgo]$ find . -name "work.0*"
#""(Double quotation)But it is searched without problems
#-If you omit print, it will be automatically-Considered to have specified print
./work.02.txt
./work.05.txt
./work.06.txt
./work.07.txt
./work.08.txt
./2020dir/work.09.txt
[wataru@localhost testgo]$ find . -type d
#-Use type d to search directories
.
./2020dir
[wataru@localhost testgo]$ find . -type f
#-Use type f to search for files
./work.02.txt
./work.05.txt
./work.06.txt
./work.07.txt
./work.08.txt
./testtest.txt
./2020dir/work.09.txt
[wataru@localhost testgo]$ ls
2020dir work.02.txt work.04.xls work.06.txt work.07.xls work.09.xls
testtest.txt work.02.xls work.05.txt work.06.xls work.08.txt work.10.xls
work.01.xls work.03.xls work.05.xls work.07.txt work.08.xls
wataru@localhost testgo]$ find . -type f -name '*xls'
#-type f and-name can be used together
./work.01.xls
./work.02.xls
./work.03.xls
./work.04.xls
./work.05.xls
./work.06.xls
./work.07.xls
./work.08.xls
./work.09.xls
./work.10.xls
Text editor
command | Contents |
---|---|
:q | Quit vi |
:w | Save the file by overwriting |
:w |
Save it after naming it |
:q! | Exit vi without saving the file |
command | Contents |
---|---|
gg | Move to the first line |
G | Move to the last line |
[wataru@localhost testgo]$ vi work.05.txt
ABCDEFG
HIJKLMN
OPQRSTUWwaq
abcdef
123456
345678
7890
~
~
~
~
~
~
~
~
-- INSERT --
#Enter i or a to enter insert mode
#Enter the Esc key to exit insert mode
command | Contents |
---|---|
d$ | Delete to the end of the line |
dgg | Delete up to the first line |
dG | Delete to the last line |
ABCDEFG
HIJKLMN
OPQRSTUWwaq
abcdef
123456
345678
#d$And deleted until the end of the line(7890 Deleted)
~
~
~
"work.05.txt" 9L, 56C
ABCDEFG
HIJKLMN
OPQRSTUWwaq
abcdef
1234562345623456
#d$The character string deleted in can be pasted using p.
345678
You can search by entering / (slash) in normal mode.
HIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMN
HIJKLMN
OPQOPQOPQ
OPQOPQOPQ
HIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMN
HIJKLMN
HIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMN
HIJKLMN
HIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMNHIJKLMN
# /Enter the character you want to search after
/HI
Change file mode
wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
-rw-rw-r--. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
[wataru@localhost testgo]$ chmod u+x testtest.txt
#chmod [ugoa][+-=][rwx] <file name>You can set permissions with
#This time, testtest.Added execute permission to the owner of the txt file
[wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
-rwxrw-r--. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
symbol | meaning |
---|---|
u | Owner |
g | group |
o | Other users |
a | ugo all |
[wataru@localhost testgo]$ chmod u-rx testtest.txt
#testtest.Prohibited read and write permissions on txt file owners
[wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
--w-rw-r--. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
[wataru@localhost testgo]$ chmod a+rwx testtest.txt
#Set read, write, and execute permissions for all users
[wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
-rwxrwxrwx. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
-rw-rw-r--. 1 wataru wataru 0 Jul 11 01:55 work.txt
[wataru@localhost testgo]$ chmod 444 testtest.txt
#Permission can be set even with numerical values
#This time, read only setting
[wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
-r--r--r--. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
-rw-rw-r--. 1 wataru wataru 0 Jul 11 01:55 work.txt
Numerical value | meaning |
---|---|
4 | reading |
2 | writing |
1 | Run |
[wataru@localhost testgo]$ chmod 660 testtest.txt
#Set read and write permissions for owners and groups
[wataru@localhost testgo]$ ls -l
total 0
drwxrwxr-x. 2 wataru wataru 25 Jul 7 16:25 2020dir
-rw-rw----. 1 wataru wataru 0 Jul 5 04:26 testtest.txt
-rw-rw-r--. 1 wataru wataru 0 Jul 11 01:55 work.txt
Recommended Posts