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)
To switch from a user to another, enter the following:
2- cd Command (Change Directory)
cd stands for change directory, to go into a new directory, we use cd as follows:
To go back one directory, we use cd.., for example:
To go back to the home directory, we just write 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:
or we can use Wget with -c option to resume a file that we previously started downloading it:
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)
Editing a file with Vi or Vim is easy:
5- Man Command (Manual)
and will display the following:
6- Whoami Command (Who Am I)
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.
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).
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:
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.
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:
Pinging an IP version 4
Pinging an IP version 6 (facebook open graph IP in this case)
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:
To unzip the file to the current directory:
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:
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.
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:
Sometimes you want to kill a process without letting it call their signal function, this can be done by using the kill 9 command:
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:
To start, stop, and restart apache server, we can use the following (Works on CentOS)
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: remove regular file `myfile.txt’?
To remove a single file, without confirmation, we use the -f (force) option:
To recursively remove all files and directories from a specific directory called 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 🙂