Linux commands. The very short description

I will describe the basic linux commands, because they are necessary to control Linux Server. То же по-русски.

In the post “A few words about Linux» I described the idea of access rights to the objects of the Linux file system and how to control Linux services. Therefore, the basic Linux commands description will be a little clearer now.

To manage our Linux server, create and manage websites through secure SSH connection is necessary to know a few basic Linux commands:

Linux commands

The most useable Linux commands are:

  • ls – display the contents of a folder;
  • cd – go to the folder;
  • mkdir – create a folder;
  • chown – change the owner of the file/folder;
  • chmod – change the access rights of the file/folder;
  • su – become superuser (root);
  • sudo – execute a command as another user;
  • useradd – add a user to the system;
  • passwd – set/change a user’s password;
  • cp – copy files and folders;
  • mv – move files and folders;
  • rm – remove files or folders.

1. ls name

displays the folder’s name contents or file’s name description. If one omits the name , command “ls” displays the contents of the current folder. Without any options, it displays a list of file names only, and hidden files (which begin with a dot, for example, .my.cnf) are not displayed at all. With option -la (ls -la name) displays a table with more details, as shown in Fig. 1.

Linux commands. The very short description

Fig. 1. Linux command ls

For each file, in addition to its name, it displays the creation date, size, owner, group and access rights (right to left). Hidden files and folders are displayed in this list along with usual.

2. cd foldername

change current folder to folder foldername.

  • cd ~ change to the home folder of the current user;
  • cd – returns back to the folder, which was made the transition to the current.

3. mkdir foldername

creates a folder named foldername owned by the current user and group, current user belongs to with default access rights (usually 755).

Two options may be useful:

  • mkdir -m access foldername – creates a folder with name foldername and the access rights access in the form XXX, where X – the number of three bits (described in the post “A few words about Linux»). For example, -m 700 – that means that the folder is allowed to read, write, and execute for the owner only (and, of course, for the superuser).
  • mkdir -p foldername – creates parent folders if they do not exist.

4. chown owner,group name

changes the owner and group of the file/folder name to the owner,group. Option -R applies to the command to change recursively all files in the specified folder and all it’s subfolders.

5. chmod access name

changes the access rights to a file/folder name to the code access. Values are the same as in the command mkdir with an option -m (see. 3. mkdir). Option -R applies to the command to change access rights recursively to all files in the specified folder (name) and all it’s subfolders.

6. cp name name1

copies a file/folder name to name1. If the goal is not to rename the copied object, name1 must be the name of the folder where the copied item is will be placed. If the object is copied to the current folder, then instead name1 is used of a dot “.” This is the symbol of the current folder.

Can be useful following options:

  • Option -R applies the command recursively to all included in the copied folder name files and subfolders.
  • Option -p (small) saves the owner and group of objects to be copied, otherwise the file’s and folder’s owner will be assigned to the current user and the group to which the current user belongs.
  • if one use option -i, copy program will ask user’s permission to replace existing file with copying in their names are the same.

7. mv name name1

moves file/folder name to name1. Object name does not exist any more, when operation is completed. This is the easiest way to rename file/folder in Linux.

If one use option -i, move program will ask user’s permission to replace existing file with copying in their names are the same.

8. rm name

removes (erases) file/folder name. One should use it with caution. The OPERATION is ABSOLUTELY irreversibly !

Can be useful following options:

  • using option  -r allows to delete folders and more complex hierarchical file system objects recursively.
  • option -f  suppresses user confirmation request to delete an object. Useful for removing complex hierarchical file system objects.
  • if one uses option -i, delete program will ask user’s permission to erase each object in name. I recommend to use always a remove command in the form:

rm -i name

9. useradd username

adds a new Linux user with user name username, creates (RedHat/CentOS Linux) a new group with name username and adds there the newly created user, creates for this user a home directory /home/username, and creates there user’s configuration files by default. The command is available only for the superuser.

Attention!! One should use the passwd command to set the password to a new user immediately after the creation of a new user.

10. passwd username

Sets/Changes the password for the user username. The program asks password twice, and if both answers match, saves the value entered as the user “username” password.

The superuser can change the password for any user. All the others – only their’s own.

It is clear that with simple passwords life from one hand is easier – less headache, but from the other hand – you can get the other troubles, if your server will work for some other people. Therefore, I highly recommend coming up with good passwords. I described what is a good password in the post “What is SSH/SFTP and what is it for?”.

11. su username

replaces the current user with the user username. It is necessary to enter the password for the user username. If one omits the username, one becomes superuser. Working under superuser, please be careful! You can make a serious harm to the system.

12. exit

terminates the user’s session. If it was used the command su, the exit ends the session and return to the original user.

The article briefly describes the basic Linux commands, which is necessary to manage the server, built on the basis of our virtual machine template.

No comments yet.

Leave a Reply