Linux command <Basic 1>

Describe the basic Linux commands as a memorandum.

Cursor movement command

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

ls command

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/
-F Option type
Type symbol
Normal file None
directory /
Executable file *
Symbolic link @

pwd command

Show current directory

[wataru@localhost ~]$ pwd
/home/wataru

cd command

Change the current directory

[wataru@localhost ~]$ cd ..
[wataru@localhost home]$ pwd
/home
[wataru@localhost home]$ 

mkdir command

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

touch command

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

rm command

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

cat command

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	

cp command

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

mv command

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#

ln command

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

Linux command <Basic 2>
[Basic] linux command
Linux command <Basic 1>
Linux basic command memorandum
[Linux] Basic command summary
Linux command # 4
Linux command # 3
Linux command # 5
Linux command list
linux at command
Linux [directory command]
Linux server command
Linux # Command Memo 1
Linux command [read]
Linux Command Summary
Linux [shell command]
Basic LINUX commands
[Linux] Command / Knowledge
My linux command
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Linux command (basic in basic) personal memo
Linux (command memory)
Linux operation for beginners Basic command summary
[Linux] Volume configuration command
Linux command cheat sheet
Linux command (sequential update)
Linux command [File operation]
Basic knowledge about Linux
Basic Python command memo
Linux command for self-collection
linux command error collection 1
Linux command line shortcut
linux sar command CPU usage
CLI and Linux basic terms
[Linux] tar.gz compression / decompression command
[Copy and paste OK] Basic Linux command collection [18 selections]
virtualenv Basic command usage memo
Easy df command on Linux
Linux
Linux tar xz command memo
Linux Command Dictionary (for myself)
linux: create original Terminal command
[Note] Useful linux command collection
Linux command memorandum [for beginners]
Linux PC spec check command
[Linux] User / group command summary
[Infrastructure] Linux command, shell script collection
Basic knowledge of Linux and basic commands
[Linux convenient command] Try inserting exa
Command to create Linux Live USB
[Linux] OS recovery with restore command
LINUX command [wc edition] Usage example
Linux command [ldconfig] LPIC learning memo
[linux] kill command to kill the process
[Linux convenient command] Try inserting bat
Linux command 16 procedure manual folder (completed)
Linux Basic Education for Front-end Engineer
About Linux commands Super basic edition