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. ..
Simply put, it's a folder.
All directories on the computer, directories containing files.
All directories held by the user, directories that store files.
The directory you are currently working on.
File path as seen from the root directory.
The file path as seen from the directory you are currently working on.
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
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
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
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
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
clear Refresh the screen.
[Description example]
$ clear
Or you can also use "control" + "L".
shutdown Shut down the OS.
[Description example]
$ shutdown -h now
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
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