15 most used linux commands and how to use them

Lately I’ve been using linux commands a lot, to configure servers and to optimize them. So I decided to write about my 15 most used commands linux, a brief explanations about them, and couple of examples of each.

 

15 most used linux commands:

1- su and su- command (Switch User or Super User or Set User)

su  stands for super user, switch user or set user. By default su command will promote the current user to a super user, if the super user has a password, they will have to authenticate first, and if authenticated successfully, they will be granted the permission to access the super user, for example:
su

To switch from a user to another, enter the following:

su etienne

2- cd Command (Change Directory)

cd stands for change directory, to go into a new directory, we use cd as follows:

cd myNewDirectory

To go back one directory, we use cd.., for example:

cd ..

To go back to the home directory, we just write cd

cd

3- Wget Command (World Wide Web and get)

Wget stands for World Wide Web and the word get.

Wget is used to download a file from a http server (or https), and even ftp servers.
Wget can also be used to download an entire directory recursively.

To download a single file with Wget, we use the following command:

wget directUrlForAFile

or we can use Wget with -c option to resume a file that we previously started downloading it:

wget -c directUrlForAFile

More examples about working with Wget can be found in here:  http://www.etiennerached.com/2012/07/working-with-wget-command-to-download.html

 

4- Vi and Vim Commands (Text Editor)

Vi is the Unix text editor originally created for Unix operating system, while Vim is also a text editor extended from Vi. Vim is also known as “Vi Improved” and has additional features over Vi, and helps in editing the text easier.

Editing a file with Vi or Vim is easy:

vi myFile.txt
vi /etc/my.cnf

vim myFile.txt
vi /etc/my.cnf

 

5- Man Command (Manual)

Man stands for manual, and its job is to display the manual of a command, the options for a command and their descriptions. Man is very important in case you forget an option parameter or if you just wish to learn about new commands.
The below example, will display the help of the vi command explained earlier:
man vim

and will display the following:

man vim

6- Whoami Command (Who Am I)

whoami command will display the name of the current logged in user, just type whoami in a command line and your name will appear, for example:

 

[root@changeme ~]# whoami
root

7-  Free Command  (Free Command)

The free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column should be ignored; it is obsolete.
By default, free will show the usage in KB, If you want to check your memory usage in MB, enter the command free -m, in GB free -g , and in Bytes free -b.

free
free -b
free -m
free -g

More information about “free command” can be found in here: http://www.etiennerached.com/2011/11/understanding-current-memory-usage-in.html

 

8- Top Command (Display top CPU processes)

The top command provides a real-time view of the running system or server. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel (tasks running, CPU load, used memory, free memory).

top

9- Yum Command (Yellowdog Updater Modified Command)

Yum Command can be used to install new packages, update existing packages and remove packages. Yum can also include dependency analysis and obsolete processing based on “repository” metadata.

An example of using yum to install php is as follows:

yum install php

If php is already installed, yum will display the version of the installed packages, and if a new version is available, yum will ask if you would like to update it, and update all the dependency and related packages.

yum install php

10- Ping Command (send ICMP ECHO_REQUEST to network hosts)

Ping uses the ICMP protocol to send packets and check if a certain address is reachable. For example:

Pinging a domain name:

ping www.google.com

Pinging an IP version 4

ping  192.168.0.1

Pinging an IP version 6 (facebook open graph IP in this case)

ping 2a03:2880:10:1f02:face:b00c:0:26

11- Zip and Unzip Commands

Zip is usesd to compress and/or package one or more files. Unzip is used to unpack and uncompress the file(s) that were previously zipped.

Zipping several files in a directory can be achieved by using the recursive -r option:

zip -r filename.zip

To unzip the file to the current directory:

unzip filename.zip

You might also be interested in reading this post about zipping files or directories: http://www.etiennerached.com/2012/07/how-to-zip-direcotry-using-ssh-with.html

 

12- ls Command (Listing Directory Content)

ls lists all the files in the current directory, sorted alphabetically, ls can take some arguments, for example:

ls

or ls -l, which will show a long listing format, and the current permission of each file and directory, alongside their size and last modified date.

ls -l

 

13- kill Command (Terminating/Killing a process)

The command kill send a TERM signal to a process. All linux processes can have a signal function where in case a kill command is initiated, this process will first access their signal function and execute whatever code is written in it. In case the process does not have a signal function, the kill command will terminate the process immediately, the following example will kill process number 18020:

kill 18020

Sometimes you want to kill a process without letting it call their signal function, this can be done by using the kill 9 command:

kill 9 18020

In the above example, the process will be terminated immediately.

 

14- Service Command

Service command is used to run the system V init scripts. that is instead of calling the files located in the /etc/init.d/ directory by specifying their full path, you can use the service command. For example to check all the running services, we use the following command:

service –status-all

To start, stop, and restart apache server, we can use the following (Works on CentOS)

service httpd stop
service httpd start
service httpd restart

 

15- rm Command (Remove file(s) and directories)

rm removes each specified file. By default, it does not remove directories.

To remove a single file, you have to confirm before removing:

rm myfile.txt
rm: remove regular file `myfile.txt’?

To remove a single file, without confirmation, we use the -f (force) option:

rm -f myfile.txt

To recursively remove all files and directories from a specific directory called myDir:;

rm -r myDir

There are many more useful commands in linux that can be used often, however I think that the above list contains the most used commands.

In case I missed an important command, please leave a comment and let me know 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *