Got a VPS without hosting control panel or connected your server with ssh first time? With Linux it is difficult without any first hand experience. Sometimes this is not the case and you need a VPS with cheap price which do not come with hosting control panels.
Whatever the case is, It would be difficult doing anything first time.
Here I have compiled a list of 10 basic command, which will help you in first Linux experience. This list is not only for a Linux OS, it will also you for other Unix-like OS.
The command “ls” stands for “List directory files or folders (from current directory by default)”.
list including hidden files.
long list with extra details.
The cd command is one of the commands you will use the most at the command line in Linux. It allows you to change your working directory.
“cd ~” will change the working directory to user’s home directory, and is very useful if a user finds himself lost in terminal.
“cd ..” will change the working directory to parent directory (of current working directory).
The cp command is used to make copies of files and directories.
In above example “cp” command makes a copy of wp-config.php in /var/www/mindsteller/ directory. It will show error if it found your given path incorrect.
“cp -R” will copy directory with all its files and directories(here ‘R’ stands for recursive).
The mv command is used to move or rename files.
In above example “mv” command move wp-config.php in /var/www/mindsteller/ directory. It will show error if it found your given path incorrect.
“mv -i” will prompt before overwriting any file (here ‘i’ means interactive).
The mkdir (Make directory) command create a new directory with name path.
In above example “mkdir” will create “mindstellar” directory. Will return an error message “cannot create folder, folder already exists” if directory is already created.
chmod is used to change the permissions of files or directories.
On Linux and other Unix-like operating systems, there is a set of rules for each file which defines who can get access to that file, and how they can access it. These rules are called file permissions or file modes. The command name chmod stands for “change mode”, and it is used to define the way a file can be accessed.
There exist 3 types of permission on a file (folder or anything but to keep things simple we will be using file).
Read (r)=4 Write(w)=2 Execute(x)=1
So if you want to give only read permission on a file it will be assigned a value of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only, a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is owner, then usergroup and finally world.
Here the root’s permission is rwx (read, write and execute).
usergroup to which it belongs, is r-x (read and execute only, no write permission) and
for world is –x (only execute).
To change its permission and give read, write and execute permission to owner, group and world.
“chmod” is very frequently used command for sysadmin.
The chown command changes the owner and owning group of files. In Linux every file belongs to a group of user and a owner. It is used Do ‘ls -l‘ into your directory and you will see something like this.
if you want to change “mindstellar” user and owner to www-data (default server user in ubuntu Linux), you need to use this command like this.
“chown -R” will change user/owner of all files and subdirectories in given directory.
The tar program is used to create, maintain, modify, and extract files that are archived in the tar format.
tar -zxvf mindstellar.tar.gz (Remember 'z' for .tar.gz)
tar -jxvf mindstellar.tar.bz2 (Remember 'j' for .tar.bz2)
tar -cvf mindstellar.tar.gz(.bz2) /path/to/folder/example
The first argument to tar should be a function specification: either one of the letters A, c, d, r, t, u, or x, or one of the long function names. A function letter does not need to be prefixed with a dash (“–“), and may be combined with other single-letter options. A long function name must be prefixed with a double dash (“—“). Some options take a parameter; with the single-letter from these must be given as separate arguments. With the long form, they may be given by appending “=value” to the option.
Above example will create ‘mindstellar.tar’ from ‘mindstellar’ directory.
Specifying one of the following functions selects what tar‘s main mode of operation will be:
A, –catenate, –concatenate Append tar files to an archive.
c, –create Create a new archive.
d, –diff, –compare Calculate any differences between the archive and the file system.
–delete Delete from the archive.
r, –append Append files to the end of a tar archive.
t, –list List the contents of an archive.
–test-label Test the archive label, and exit.
u, –update Append files, but only those that are newer than the copy in the archive.
x, –extract, –get Extract files from an archive.
The “sudo” (super user do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy in the sudoers list.
In example if you see we are already logged in as root user, so we do-not need sudo. Although, it is recommended to use ‘sudo’ wherever possible for add security benefits. You can ‘su’ command to logged in as root user.
On Linux and other Unix-like operating systems, man is the interface used to view the system’s reference manuals. It can be a life saver for new Linux user.
You can use “man” to know more info/help about commands in this list(or any other).
Using above example you get more information about “ls” command.
This list may have contain many more useful commands, but in this post I have tried to contain as few as possible but still very useful commands according to my experience. List can go on but that’s not a goal for this post. It is written for new/first Linux users in mind.
What do you think about this post? Please share with your comments.