[Copy and paste OK] Basic Linux command collection [18 selections]


Recently, I am building a LAMP environment, but I have had many opportunities to touch Linux commands in it, and I have accumulated a stock of knowledge, so this time I will explain the commands that frequently appear. ..

Prior knowledge

directory

Simply put, it's a folder.

Root directory

All directories on the computer, directories containing files.

Home directory

All directories held by the user, directories that store files.

Current directory

The directory you are currently working on.

Absolute path

File path as seen from the root directory.

Relative path

The file path as seen from the directory you are currently working on.


Reference system

pwd View the file path you are currently working on from your home directory.

[Description example]

$ pwd

[Output example]

/Users/username


ls View a list of saved files and directories in the directory you are currently working on.

[Description example]

<!--Show list-->
$ ls

<!--Hidden files(.start from)Display including-->
$ ls -a

<!--View detailed information such as permissions-->
$ ls -l

<!--Display detailed information such as permissions including hidden files-->
$ ls -la

[Output example]

<!-- ls -->
Desktop				Sinatra
Documents			Sites
...

<!-- ls -a -->
.Trash				Documents
.bundle				Downloads
...

<!-- ls -l -->
drwx------@  5 username  username   160 11 14 16:12 Applications
drwx------@  9 username  username   288 11 24 19:55 Desktop
...

<!-- ls -la -->
drwx------   2 username  username     64 11 21 14:01 .Trash
drwxr-xr-x   4 username  username    128 10 20 23:12 .bundle
...


cat View the contents of the file. Since it cannot be scrolled, it is used when the content is large enough to fit on one screen.

[Description example]

$ cat exampleFile

[Output example]

<!--Description of the contents of exampleFile-->
This is a sample.


less View the contents of the file. Scrollable. Used for content of one screen or more.

[Description example]

$ less exampleFile

[Output example]

<!--Description of the contents of exampleFile-->
This is a sample.
.
.
.


history Display the history of executed commands.

[Description example]

<!--View command history-->
$ history

<!--Show 5 latest commands(Numbers are arbitrary) -->
$ history 5

<!--Execute the command corresponding to the numbering displayed in history(Numbers are arbitrary) -->
$ !5

<!--Delete the command corresponding to the numbering displayed in history from the history(Numbers are arbitrary) -->
$ history -d 5

[Output example]

<!-- history -->
  .
  .
  .
  848  pwd
  849  pwd
  850  ls
  851  ls -a
  852  ls -l
  853  ls -la
  854  cat
  855  ls

<!-- history 5 -->
  851  ls -a
  852  ls -l
  853  ls -la
  854  cat
  855  ls

<!-- !855(If above, run ls) -->
Desktop				Sinatra
Documents			Sites
...

<!-- history -d 853 -->
<!-- 853 ls -delete la-->
  .
  .
  .
  851  ls
  852  ls -a
  853  ls -l
  854  cat
  855  ls



Creation system

mkdir Create a new directory in the current directory.

[Description example]

$ mkdir exampleFile


touch Create a new file in the current directory.

[Description example]

$ touch exampleFile



Deletion system

rm Delete files and directories. Normally, there is no output, but if it is described or saved in a file or directory, execution confirmation is requested with * Y (yes) * or * N (no) *.

[Description example]

<!--Delete file-->
$ rm exampleFile

<!--Forced deletion of files(No confirmation) -->
$ rm -f exampleFile

<!--Delete directory-->
$ rm -r exampleDirectory

<!--Forced deletion of directories-->
$ rm -rf exampleDirectory


Duplication system

cp Make a copy of a file or directory.

[Description example]

<!--Make a copy of exampleFile as exampleFile2-->
$ cp exampleFile exampleFile2

<!--Make a copy of exampleDirectory as exampleDirectory2-->
$ cp -r exampleDirectory exampleDirectory2


Mobile system

cd Move the current directory (the directory you are currently working on). Can be specified as an absolute path or a relative path.

[Description example]

<!--Move to home directory-->
$ cd

<!--Move work location to exampleDirectory-->
$ cd exampleDirectory

<!--Move to a directory one level higher-->
$ cd ..


mv You can move files and rename files. Can be specified as an absolute path or a relative path.

[Description example]

<!--Move exampleFile1 from exampleDirectory1 to exampleDirectory2-->
$ mv exampleDirectory1/exampleFile1 exampleDirectory2

<!--Rename exampleFile2 to exampleFile3-->
$ mv exampleFile2 exampleFile3


Convenient system

clear Refresh the screen.

[Description example]

$ clear

Or you can also use "control" + "L".

shutdown Shut down the OS.

[Description example]

$ shutdown -h now



User system

useradd Add new user. (At this time, a home directory for the user is also created)

[Description example]

<!--Create a new user with the user name example-->
$ useradd example


passwd Newly register the password of the newly created user and change the password of the existing user. (In a production environment, another authentication method called "key authentication" is often used)

[Description example]

<!--Change the password for the username example-->
$ passwd example


userdel Delete user.

[Description example]

<!--example Delete user-->
$ userdel example

<!--example Deleting a user and deleting the deleted user's home directory-->
$ userdel -r example


su User switching.

[Description example]

<!--switch to example user(The current directory is the same) -->
$ su example

<!--switch to example user(Start from that user's home directory) -->
$ su - example


exit User logout. If you are logged in multiple times, return to the original user.

[Description example]

<!--Log out of the user currently in use-->
$ exit



Summary

When building an environment with a Linux distribution (Linux OS), Linux commands are frequently used, so it is useful to familiarize yourself with the basic commands explained to some extent.

"Terminal" for mac "Power Shell" for Windows You can do it with these, so please give it a try.

Thank you for watching until the end!


Author: yuki | First project won on the 10th day of study → Currently studying for full stack engineer career change Qiita:https://qiita.com/yuki4839 Twitter:https://twitter.com/yuki35522891

Recommended Posts

[Copy and paste OK] Basic Linux command collection [18 selections]
Linux command <Basic 2>
[Basic] linux command
Linux command <Basic 1>
Linux command collection
Linux basic command memorandum
[Linux] Basic command summary
linux command error collection 1
CLI and Linux basic terms
[Note] Useful linux command collection
How to copy and paste command line content without mouse in bash on Linux or mac
[Infrastructure] Linux command, shell script collection
Basic knowledge of Linux and basic commands
Permission and ownership change command [Linux]
Linux command (basic in basic) personal memo
Linux operation for beginners Basic command summary
Linux command # 4
Linux command # 3
Linux command # 5
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Combine PDF pages, copy and paste series immediately
Linux (Bash) and Windows (PowerShell) command correspondence table