An in-house study session was held at Ancar Co., Ltd. on February 3, and this article is a review of the study session topic.
Please be aware that the content is "I'll start with the basics of Linux !!!"
Each command is executed using the standard macOS terminal
- Virtual Console - What you can do with the virtual console - Output with tty - file operation - Easy file creation method - How to specify the file name
Normally, you can make multiple connections to one terminal, but each one is assigned a virtual console
.
Each virtual console is named like tty? Number
tty is a word derived from TeleTYpewriter
and seems to refer to an input / output device.
By switching the tty, you can realize the operation like switching to another screen in the terminal.
(Currently, multiple console screens are launched, so switching operations are omitted.)
Let's actually use the tty
command to see which virtual console is currently in use
$ tty
/dev/ttys000
I was using tty000
This time I will launch the console in another window and hit tty
$ tty
/dev/ttys001
Each console has a different tty, I see
Let's see with the who
command
$ who
yungo console Feb 9 22:56
yungo ttys000 Feb 10 10:16
yungo ttys001 Feb 11 13:46
yungo ttys002 Feb 11 13:47
yungo ttys004 Feb 10 20:01
yungo ttys005 Feb 10 21:14
I was currently launching 5 consoles with the username yungo
, but each one was assigned a tty, I see.
(The first console
looks like a kernel, please point out if you make a mistake)
--Log in to the same user with tty1
and tty2
, and work with one while displaying man (manual)
on one.
--Log in to different users with tty1
and tty2
, and work in parallel while using different users.
--When freezing with tty1
, log in with tty2
and kill the frozen application
--When you forgot to add &
with tty1
and executed a large command, but [Ctrl] + [z] could not be used, kill the command with tty2
and execute it again with &
. To do
--Log in as a general user with tty1
and as a root user with tty2
, and use the access rights properly.
etc It's a task that you usually do by launching the console in a separate window without being aware of it (although that is exactly the virtual console).
$ echo hoge
hoge
echo usually returns to my device
$ echo hoge > /dev/tty2
Will output echo to tty2
It looks like this on the console at hand ↓
The echo input with tty000 is output to the cursor position of tty001.
Changing the story, from here on, the second part, file operation
There are several easy ways to create a file without launching the editor
#Creating a one-line file
$ echo hogehogehogehoge > file1.txt
#I will check the contents
$ cat file1.txt
hogehogehogehoge
#Overwrite if redirect
$ echo hoge > file1.txt
$ cat file1.txt
hoge
#Added that it is an additional redirect
$ echo hoge >> file1.txt
$ cat file1.txt
hoge
hoge
cat
and redirectI thought that cat
was just a command to display the contents, but by using redirect, it can be used like a (very) simple editor, I did not know
# [ctrl]+[d]End with
$ cat > file2.txt
hoge
ho
hoge
[ctrl]+[d]
#I will look at the contents
$ cat file2.txt
hoge
ho
hoge
3:touch
You can create an empty 0-byte file
Originally, the touch
command seems to be a command to update the modification date and time of a file ... I didn't know ...
#Check directory
$ ls
file1.txt file2.txt
#Create
$ touch file3.txt
#Check directory
$ ls
file1.txt file2.txt file3.txt
I specified the file name like cat file1.txt
from earlier, but there are several ways to do this as well.
symbol | Description |
---|---|
* |
Any string. It may be an empty string |
? |
Any one character |
[...] |
[ ] Any one character contained within( - You can specify the range with a symbol) |
[!...] |
[ ] Inside. . .Any one character not included in |
{ ~ } |
{ } Any string contained within(Separate with commas) |
(Addition) {~}
does not seem to be included in wildcards
Wildcards such as *
are expanded by path name, {~}
is expanded by brace, and the behavior is different.
(Thanks to @ angel_p_57 for teaching me!)
I will try it in the previous directory
#Arbitrary string (*Anything after that)
$ ls file*
file1.txt file2.txt file3.txt
#2 or 3
$ ls file[23].txt
file2.txt file3.txt
#You can also specify the range
$ ls file[1-3].txt
file1.txt file2.txt file3.txt
#Word matches
$ ls {file,filo}1.txt
file1.txt filo1.txt
It seems that it can be used almost like a regular expression
That's all for this time! !!
There are a lot of basic contents, but I get the impression that there are many tricks that I didn't even know about the commands I use all the time. I always open a lot of windows when working, but I also need to keep the concept of tty in mind.
Any corrections or corrections are welcome, so please leave a comment!
** LINUX Chot Dekill (in the true sense) **
Recommended Posts