The most common basic Linux commands
1. ls
Displays a list of files and folders in the current directory. Example: ls – displays a list of files and directories in the current directory
When you want to display the date and time (2) along with the ownership of the user (3), the permissions that the user can do (read, edit, delete) (4) we can use:
1 2 3 | ls -l |
1 2 3 | ls -lh |
Clearly see the size of the file (for directories may be wrong)
2. cd
Navigate to the desired folders. (used a lot to move)
Before using it, it is necessary to learn how to distinguish specific folders.
cd ~ is where? cd / is where? (if you are still confused, you can watch the youtube video to understand better)
~: is the directory of the user that we are logged in
/: is the root directory of the server
eg:
1 2 | cd /home/user/Documents |
3. mkdir
Create folder
Ex:
1 2 3 4 | cd / mkdir home |
If you want to create a longer path, add the -p option
Vd
mkdir -p /home/download/picture
4. Touch
Create a new file. I still don’t understand why it’s called touch :v, it must be created if you want to touch. I think so
Vd
1 2 3 | cd /home |
1 2 3 | touch test.txt |
5. share
Clone (copy) a folder or a certain file
1 2 3 | `cp test.txt test1.txt` |
If you want to copy a directory, add the -r option
1 2 | cp -r home home_bk` |
6. mv
Move the file or folder somewhere else. In particular, it can also be used to rename a file or a folder
Ex:
1 2 | mv file.txt /home/user` |
Ex:
1 2 3 | `mv file.txt file1.txt` |
7. rm
This command is quite dangerous, knowing why it is dangerous, you can vaguely guess its English, right? That’s remove 😊. When using this command, remember not to drink alcohol. Sometimes a project is lost because of this command!!!
Its syntax is
rm
When pressed it will ask you again if you want to delete or not.
If you find it too annoying, you can add the following option
1 2 | rm -f file |
Removed from needing to ask.
If you want to delete the directory, add the -r . option
1 2 3 | rm -r thư mục |
nice
1 2 3 | rm -rf thư mục |
8. cat
Display the contents of the file on the terminal always.
eg:
1 2 3 | `cat file1.txt`` |
9. grep
This command is very divine if you know how to use it in combination with other commands. Learn it because I think I will use it quite a lot.
It is used to find related keywords if you combine with :
1 2 3 | `ls -l | grep ‘từ khóa ’` |
List out files with keywords in grep.
Used with the command
1 2 3 | `history | grep <từ khóa>` |
List used commands with keyword in grep
10. chmod
When doing DBA or Devops related to the operating system, you may be able to get or thanks to this file’s permission, that directory’s permission, this will be the command to help you.
Usually I use the command
1 2 3 | `chmod 777 file` |
(Full decentralization, anyone can do anything, but only use it when they understand that no one will destroy that file)
If you want to assign such permissions to the directory and the sub-files in that directory, you add the option -R
1 2 3 | chmod -R 777 thư mục |
Conclude.
Wish you familiarize yourself with these basic commands, mastered, the job will be very easy later. Stay tuned for part 2 if you want to know more.