20 Linux Commands
20 Linux Commands
1 ls Find ifconfig
2 lsblk grep netstat
3 md5sum man nslookup
4 dd ps dig
5 uname kill uptime
6 history whereis wall
7 sudo service mesg
8 mkdir alias write
9 touch df talk
10 chmod du w
11 chown rm rename
12 apt echo top
13 tar passwd mkfs.ext4
14 cal lpr vi/emacs/nano
15 date cmp rsync
16 cat wget free
17 cp mount mysqldump
18 mv gcc mkpasswd
19 pwd g++ paste
20 cd java lsof
20 Linux Commands for Newbies
1. ********************************* COMMAND : ls
The command “ls” stands for (List Directory Contents), List the contents of the folder,
be it file or folder, from which it runs.
root@tecmint:~# ls
Android-Games Music
Pictures Public
Desktop Tecmint.com
Documents TecMint-Sync
Downloads Templates
The command “ls -l” list the content of folder, in long listing fashion.
root@tecmint:~# ls -l
total 40588
drwxrwxr-x 2 ravisaive ravisaive 4096 May 8 01:06 Android Games
drwxr-xr-x 2 ravisaive ravisaive 4096 May 15 10:50 Desktop
drwxr-xr-x 2 ravisaive ravisaive 4096 May 16 16:45 Documents
drwxr-xr-x 6 ravisaive ravisaive 4096 May 16 14:34 Downloads
drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Music
drwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Pictures
drwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 Tecmint.com
drwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Templates
Command “ls -a“, list the content of folder, including hidden files starting with ‘.’.
root@tecmint:~# ls -a
. .gnupg .dbus
.goutputstream-PI5VVW .mission-control
.adobe deja-dup .grsync
.mozilla .themes
.gstreamer-0.10 .mtpaint .thumbnails .gtk-
bookmarks .thunderbird
.HotShots .mysql_history .htaccess .apport-
ignore.xml .ICEauthority
.profile .bash_history .icons
.bash_logout .fbmessenger
.jedit .pulse .bashrc
.liferea_1.8 .pulse-cookie
.Xauthority .gconf .local
.Xauthority.HGHVWW .cache
.gftp .macromedia .remmina
.cinnamon .gimp-2.8
.ssh .xsession-errors .compiz .gnome
teamviewer_linux.deb
.xsession-errors.old .config .gnome2
.zoncolor
Note: In Linux file name starting with ‘.‘ is hidden. In Linux every
file/folder/device/command is a file. The output of ls -l is:
For more “ls” command examples read 15 ‘ls’ Command Examples in Linux.
The “lsblk” stands for (List Block Devices), print block devices by their assigned
name (but not RAM) on the standard output in a tree-like fashion.
root@tecmint:~# lsblk
The “lsblk -l” command list block devices in ‘list‘ structure (not tree like fashion).
root@tecmint:~# lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
sda1 8:1 0 46.6G 0 part /
sda2 8:2 0 1K 0 part
sda5 8:5 0 190M 0 part /boot
sda6 8:6 0 3.7G 0 part [SWAP]
sda7 8:7 0 93.1G 0 part /data
sda8 8:8 0 89.2G 0 part /personal
sr0 11:0 1 1024M 0 rom
Note: lsblk is very useful and easiest way to know the name of New Usb Device you
just plugged in, especially when you have to deal with disk/blocks in terminal.
The “md5sum” stands for (Compute and Check MD5 Message Digest), md5
checksum (commonly called hash) is used to match or verify integrity of files that
may have changed as a result of a faulty file transfer, a disk error or non-malicious
interference.
47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb
Note: The user can match the generated md5sum with the one provided officially.
Md5sum is considered less secure than sha1sum, which we will discuss later.
4. ********************************* COMMAND : dd
Command “dd” stands for (Convert and Copy a file), Can be used to convert and copy
a file and most of the times is used to copy a iso file (or any other file) to a usb device
(or any other location), thus can be used to make a ‘Bootlable‘ Usb Stick.
root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M;
sync
Note: In the above example the usb device is supposed to be sdb1 (You should Verify
it using command lsblk, otherwise you will overwrite your disk and OS), use name of
disk very Cautiously!!!.
dd command takes some time ranging from a few seconds to several minutes in
execution, depending on the size and type of file and read and write speed of Usb
stick.
The “uname” command stands for (Unix Name), print detailed information about the
machine name, Operating System and Kernel.
root@tecmint:~# uname -a
Linux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013
i686 i686 i686 GNU/Linux
Note: uname shows type of kernel. uname -a output detailed information. Elaborating
the above output of uname -a.
The “history” command stands for History (Event) Record, it prints the history of long
list of executed commands in terminal.
root@tecmint:~# history
Note: Pressing “Ctrl + R” and then search for already executed commands which lets
your command to be completed with auto completion feature.
(reverse-i-search)`if': ifconfig
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.
Note: sudo allows user to borrow superuser privileged, while a similar command ‘su‘
allows user to actually log in as superuser. Sudo is safer than su.
It is not advised to use sudo or su for day-to-day normal use, as it can result in serious
error if accidentally you did something wrong, that’s why a very popular saying in
Linux community is:
“To err is human, but to really foul up everything, you need root password.”
8. ********************************* COMMAND : mkdir
The “mkdir” (Make directory) command create a new directory with name path.
However is the directory already exists, it will return an error message “cannot create
folder, folder already exists”.
Note: Directory can only be created inside the folder, in which the user has write
permission. mkdir: cannot create directory `tecmint‘: File exists
(Don’t confuse with file in the above output, you might remember what i said at the
beginning – In Linux every file, folder, drive, command, scripts are treated as file).
The “touch” command stands for (Update the access and modification times of each
FILE to the current time). touch command creates the file, only if it doesn’t exist. If
the file already exists it will update the timestamp and not the contents of the file.
Note: touch can be used to create file under directory, on which the user has write
permission, only if the file don’t exist there.
The Linux “chmod” command stands for (change file mode bits). chmod changes the
file mode (permission) of each given file, folder, script, etc.. according to mode asked
for.
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.
rwxr-x--x abc.sh
To change its permission and provide read, write and execute permission to owner,
group and world.
read, write and execute to owner and only execute to group and world.
Note: one of the most important command useful for sysadmin and user both. On a
multi-user environment or on a server, this command comes to rescue, setting wrong
permission will either makes a file inaccessible or provide unauthorized access to
someone.
The Linux “chown” command stands for (change file owner and group). 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.
root@tecmint:~# ls -l
Here the directory Binary is owned by user “server” and it belongs to usergroup
“root” where as directory “Desktop” is owned by user “server” and belongs to user
group “server“.
This “chown” command is used to change the file ownership and thus is useful in
managing and providing file to authorised user and usergroup only.
Note: “chown” changes the user and group ownership of each given FILE to NEW-
OWNER or to the user and group of an existing reference file.
The Debian based “apt” command stands for (Advanced Package Tool). Apt is an
advanced package manager for Debian based system (Ubuntu, Kubuntu, etc.), that
automatically and intelligently search, install, update and resolves dependency of
packages on Gnu/Linux system from command line.
Note: The above commands results into system-wide changes and hence requires root
password (Check ‘#‘ and not ‘$’ as prompt). Apt is considered more advanced and
intelligent as compared to yum command.
As the name suggest, apt-cache search for package containing sub package mpalyer.
apt-get install, update all the packages, that are already installed, to the newest one.
Read more about apt-get and apt-cache commands at 25 APT-GET and APT-CACHE
Commands
Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a better
but slower compression method.
The “cal” (Calendar), it is used to displays calendar of the present month or any other
month of any year that is advancing or passed.
root@tecmint:~# cal
May 2013
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Show calendar of year 1835 for month February, that already has passed.
Shows calendar of year 2145 for the month of July, that will advancing
July 2145
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Note: You need not to turn the calendar of 50 years back, neither you need to make
complex mathematical calculation to know what day you were worn or your coming
birthday will fall on which day.
The “date” (Date) command print the current date and time on the standard output,
and can further be set.
root@tecmint:~# date
The “cat” stands for (Concatenation). Concatenate (join) two or more plain file and/or
print contents of a file on standard output.
Note: “>>” and “>” are called append symbol. They are used to append the output to a
file and not on standard output. “>” symbol will delete a file already existed and
create a new file hence for security reason it is advised to use “>>” that will write the
output without overwriting or deleting the file.
Before Proceeding further, I must let you know about wildcards (you would be aware
of wildcard entry, in most of the Television shows) Wildcards are a shell feature that
makes the command line much more powerful than any GUI file managers. You see,
if you want to select a big group of files in a graphical file manager, you usually have
to select them with your mouse. This may seem simple, but in some cases it can be
very frustrating.
For example, suppose you have a directory with a huge amount of all kinds of files
and subdirectories, and you decide to move all the HTML files, that have the word
“Linux” somewhere in the middle of their names, from that big directory into another
directory. What’s a simple way to do this? If the directory contains a huge amount of
differently named HTML files, your task is everything but simple!
In the Linux CLI that task is just as simple to perform as moving only one HTML file,
and it’s so easy because of the shell wildcards. These are special characters that allow
you to select file names that match certain patterns of characters. This helps you to
select even a big group of files with typing just a few characters, and in most cases it’s
easier than selecting the files with a mouse.
Wildcard Matches
* zero or more characters
? exactly one character
[abcde] exactly one character listed
[a-e] exactly one character in the given range
[!abcde] any character that is not listed
[!a-e] any character that is not in the given range
{debian,linux} exactly one entire word in the options given
! is called not symbol, and the reverse of string attached with ‘!’ is true.
Read more examples of Linux “cat command” at 13 Cat Command Examples in Linux
The “copy” stands for (Copy), it copies a file from one location to another location.
Note: cp is one of the most commonly used command in shell scripting and it can be
used with wildcard characters (Describe in the above block), for customised and
desired file copying.
The “mv” command moves a file from one location to another location.
root@tecmint:~# mv /home/user/Downloads abc.tar.gz /home/user/Desktop (Return
0 when sucess)
Note: mv command can be used with wildcard characters. mv should be used with
caution, as moving of system/unauthorised file may lead to security as well as
breakdown of system.
The command “pwd” (print working directory), prints the current working directory
with full path name from terminal.
root@tecmint:~# pwd
/home/user/Desktop
Note: This command won’t be much frequently used in scripting but it is an absolute
life saver for newbie who gets lost in terminal in their early connection with nux.
(Linux is most commonly referred as nux or nix).
Finally, the frequently used “cd” command stands for (change directory), it change the
working directory to execute, copy, move write, read, etc. from terminal itself.
root@tecmint:~# cd /home/user/Desktop
server@localhost:~$ pwd
/home/user/Desktop
Note: cd comes to rescue when switching between directories from terminal. “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).
21. ********************************* COMMAND : Find
Search for files in the given directory, hierarchically starting at the parent directory
and moving to sub-directories.
./Desktop/load.sh
./Desktop/test.sh
./Desktop/shutdown.sh
./Binary/firefox/run-mozilla.sh
./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh
./Downloads/kdewebdev-3.5.8/admin/doxygen.sh
./Downloads/kdewebdev-3.5.8/admin/cvs.sh
./Downloads/kdewebdev-3.5.8/admin/ltmain.sh
./Downloads/wheezy-nv-install.sh
Note: The `-name‘ option makes the search case sensitive. You can use the `-iname‘
option to find something regardless of case. (* is a wildcard and searches all the file
having extension ‘.sh‘ you can use filename or a part of file name to customise the
output).
root@tecmint:~# find -iname *.SH ( find -iname *.Sh / find -iname *.sH)
./Desktop/load.sh
./Desktop/test.sh
./Desktop/shutdown.sh
./Binary/firefox/run-mozilla.sh
./Downloads/kdewebdev-3.5.8/quanta/scripts/externalpreview.sh
./Downloads/kdewebdev-3.5.8/admin/doxygen.sh
./Downloads/kdewebdev-3.5.8/admin/cvs.sh
./Downloads/kdewebdev-3.5.8/admin/ltmain.sh
./Downloads/wheezy-nv-install.sh
root@tecmint:~# find -name *.tar.gz
/var/www/modules/update/tests/aaa_update_test.tar.gz
./var/cache/flashplugin-nonfree/install_flash_player_11_linux.i386.tar.gz
./home/server/Downloads/drupal-7.22.tar.gz
./home/server/Downloads/smtp-7.x-1.0.tar.gz
./home/server/Downloads/noreqnewpass-7.x-1.2.tar.gz
./usr/share/gettext/archive.git.tar.gz
./usr/share/doc/apg/php.tar.gz
./usr/share/doc/festival/examples/speech_pm_1.0.tar.gz
./usr/share/doc/argyll/examples/spyder2.tar.gz
./usr/share/usb_modeswitch/configPack.tar.gz
Note: The above command searches for all the file having extension ‘tar.gz‘ in root
directory and all the sub-directories including mounted devices.
Read more examples of Linux ‘find‘ command at 35 Find Command Examples in Linux
The ‘grep‘ command searches the given file for lines containing a match to the given
strings or words. Search ‘/etc/passwd‘ for ‘tecmint‘ user.
Ignore word case and all other combination with ‘-i‘ option.
tecmint:x:1000:1000:Tecmint,,,:/home/tecmint:/bin/bash
Search recursively (-r) i.e. read all files under each directory for a string “127.0.0.1“.
/etc/vlc/lua/http/.hosts:127.0.0.1
/etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost "127.0.0.1"
/etc/mysql/my.cnf:bind-address = 127.0.0.1
/etc/apache2/mods-available/status.conf: Allow from 127.0.0.1 ::1
/etc/apache2/mods-available/ldap.conf: Allow from 127.0.0.1 ::1
/etc/apache2/mods-available/info.conf: Allow from 127.0.0.1 ::1
/etc/apache2/mods-available/proxy_balancer.conf:# Allow from 127.0.0.1 ::1
/etc/security/access.conf:#+ : root : 127.0.0.1
/etc/dhcp/dhclient.conf:#prepend domain-name-servers 127.0.0.1;
/etc/dhcp/dhclient.conf:# option domain-name-servers 127.0.0.1;
/etc/init/network-interface.conf: ifconfig lo 127.0.0.1 up || true
/etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1).
/etc/java-6-openjdk/net.properties:# http.nonProxyHosts=localhost|127.0.0.1
/etc/java-6-openjdk/net.properties:# localhost & 127.0.0.1).
/etc/java-6-openjdk/net.properties:# ftp.nonProxyHosts=localhost|127.0.0.1
/etc/hosts:127.0.0.1 localhost
Note: You can use these following options along with grep.
The ‘man‘ is the system’s manual pager. Man provides online documentation for all
the possible options with a command and its usages. Almost all the command comes
with their corresponding manual pages. For example,
MAN(1) Manual
pager utils
MAN(1)
NAME
man - an interface to the on-line reference manuals
SYNOPSIS
man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding]
[-L locale] [-m system[,...]] [-M path] [-S list] [-e extension] [-i|-
I]
[--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P
pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification]
[-p
string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page
...] ...
man -k [apropos options] regexp ...
man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
man -f [whatis options] page ...
man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L
locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-
T[device]]
[-H[browser]] [-X[dpi]] [-Z] file ...
man -w|-W [-C file] [-d] [-D] page ...
man -c [-C file] [-d] [-D] page ...
man [-hV]
Manual page for man page itself, similarly ‘man cat‘ (Manual page for cat command)
and ‘man ls‘ (Manual page for command ls).
ps (Process) gives the status of running processes with a unique Id called PID.
root@tecmint:~# ps
To list status of all the processes along with process id and PID, use option ‘-A‘.
root@tecmint:~# ps -A
Note: This command is very useful when you want to know which processes are
running or may need PID sometimes, for process to be killed. You can use it with
‘grep‘ command to find customised output. For example,
root@tecmint:~# ps -A | grep -i ssh
Here ‘ps‘ is pipelined with ‘grep‘ command to find customised and relevant output of
our need.
OK, you might have understood what this command is for, from the name of the
command. This command is used to kill process which is not relevant now or is not
responding. It is very useful command, rather a very very useful command. You might
be familiar with frequent windows restarting because of the fact that most of the time
a running process can’t be killed, and if killed it needs windows to get restart so that
changes could be taken into effect but in the world of Linux, there is no such things.
Here you can kill a process and start it without restarting the whole system.
Let suppose you want to kill program ‘apache2‘ that might not be responding. Run ‘ps
-A‘ along with grep command.
Find process ‘apache2‘, note its pid and kill it. For example, in my case ‘apache2‘ pid
is ‘1285‘.
Note: Every time you re-run a process or start a system, a new pid is generated for
each process and you can know about the current running processes and its pid using
command ‘ps‘.
Another way to kill the same process is.
Note: Kill requires job id / process id for sending signals, where as in pkill, you have
an option of using pattern, specifying process owner, etc.
The ‘whereis‘ command is used to locate the Binary, Sources and Manual Pages of
the command. For example, to locate the Binary, Sources and Manual Pages of the
command ‘ls‘ and ‘kill‘.
root@tecmint:~# whereis ls
Note: This is useful to know where the binaries are installed for manual editing
sometimes.
Note: All the process script lies in ‘/etc/init.d‘, and the path might needs to be
included on certain system, i.e., in spite of running “service apache2 start” you would
be asked to run “/etc/init.d/apache2 start”.
alias is a built in shell command that lets you assign name for a long command or
frequently used command.
I uses ‘ls -l‘ command frequently, which includes 5 characters including space. Hence
I created an alias for this to ‘l‘.
root@tecmint:~# l
total 36
drwxr-xr-x 3 tecmint tecmint 4096 May 10 11:14 Binary
drwxr-xr-x 3 tecmint tecmint 4096 May 21 11:21 Desktop
drwxr-xr-x 2 tecmint tecmint 4096 May 21 15:23 Documents
drwxr-xr-x 8 tecmint tecmint 4096 May 20 14:56 Downloads
drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Music
drwxr-xr-x 2 tecmint tecmint 4096 May 20 16:17 Pictures
drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Public
drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Templates
drwxr-xr-x 2 tecmint tecmint 4096 May 7 16:58 Videos
root@tecmint:~# unalias l
root@tecmint:~# l
Making a little fun out of this command. Make alias of certain important command to
some other important command.
Report disk usages of file system. Useful for user as well as System Administrator to
keep track of their disk usages. ‘df‘ works by examining directory entries, which
generally are updated only when a file is closed.
root@tecmint:~# df
For more examples of ‘df‘ command, read the article 12 df Command Examples in Linux.
Estimate file space usage. Output the summary of disk usages by ever file
hierarchically, i.e., in recursive manner.
root@tecmint:~# du
8 ./Daily Pics/wp-polls/images/default_gradient
8 ./Daily Pics/wp-polls/images/default
32 ./Daily Pics/wp-polls/images
8 ./Daily Pics/wp-polls/tinymce/plugins/polls/langs
8 ./Daily Pics/wp-polls/tinymce/plugins/polls/img
28 ./Daily Pics/wp-polls/tinymce/plugins/polls
32 ./Daily Pics/wp-polls/tinymce/plugins
36 ./Daily Pics/wp-polls/tinymce
580 ./Daily Pics/wp-polls
1456 ./Daily Pics
36 ./Plugins/wordpress-author-box
16180 ./Plugins
12 ./May Articles 2013/Xtreme Download Manager
4632 ./May Articles 2013/XCache
Note: ‘df‘ only reports usage statistics on file systems, while ‘du‘, on the other hand,
measures directory contents. For more ‘du‘ command examples and usage, read 10 du
(Disk Usage) Commands.
The command ‘rm‘ stands for remove. rm is used to remove files (s) and directories.
Removing a directory
root@tecmint:~# rm PassportApplicationForm_Main_English_V1.0
The directory can’t be removed simply by ‘rm‘ command, you have to use ‘-rf‘ switch
along with ‘rm‘.
echo as the name suggest echoes a text on the standard output. It has nothing to do
with shell, nor does shell reads the output of echo command. However in an
interactive script, echo passes the message to the user through terminal. It is one of the
command that is commonly used in scripting, interactive scripting.
#!/bin/bash
echo "Please enter your name:"
read name
echo "Welcome to Linux $name"
This is an important command that is useful for changing own password in terminal.
Obviously you need to know your current passowrd for Security reason.
root@tecmint:~# passwd
Note: The ‘lpq‘ command lets you view the status of a printer (whether it’s up or not),
and the jobs (files) waiting to be printed.
compare two files of any type and writes the results to the standard output. By default,
‘cmp‘ Returns 0 if the files are the same; if they differ, the byte and line number at
which the first difference occurred is reported.
Hi My name is Tecmint
file2.txt
Now, let’s compare two files and see output of the command.
Wget is a free utility for non-interactive (i.e., can work in background) download of
files from the Web. It supports HTTP, HTTPS, FTP protocols and HTTP proxies.
100%[========================================================================
===>] 2,75,557 67.8KB/s in 4.0s
Mount is an important command which is used to mount a filesystem that don’t mount
itself. You need root permission to mount a device.
First run ‘lsblk‘ after plugging-in your filesystem and identify your device and note
down you device assigned name.
root@tecmint:~# lsblk
From this screen it was clear that I plugged in a 4 GB pendrive thus ‘sdb1‘ is my
filesystem to be mounted. Become a root to perform this operation and change to /dev
directory where all the file system is mounted.
root@tecmint:~# su
Password:
root@tecmint:~# cd /dev
Now you can navigate to /dev/usb from terminal or X-windows system and acess file
from the mounted directory.
gcc is the in-built compiler for ‘c‘ language in Linux Environment. A simple c
program, save it on ur desktop as Hello.c (remember ‘.c‘ extension is must).
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
Compile it
root@tecmint:~# ./a.out
Hello world
Here ‘-o‘ sends the output to ‘Hello‘ file and not ‘a.out‘. Run it again.
root@tecmint:~# ./Hello
Hello world
g++ is the in-built compiler for ‘C++‘ , the first object oriented programming
language. A simple c++ program, save it on ur desktop as Add.cpp (remember ‘.cpp‘
extension is must).
#include <iostream>
int main()
{
int a;
int b;
cout<<"Enter first number:\n";
cin >> a;
cout <<"Enter the second number:\n";
cin>> b;
cin.ignore();
int result = a + b;
cout<<"Result is"<<" "<<result<<endl;
cin.get();
return 0;
}
Compile it
Run it
root@tecmint:~# ./a.out
Note: On compiling a c++ program the output is automatically generated to a new file
“a.out” and everytime you compile a c++ program same file “a.out” gets modified.
Hence it is a good advice to define a output file during compile and thus there is no
risk of overwrite to output file.
Run it
root@tecmint:~# ./Add
Java is one of the world’s highly used programming language and is considered fast,
secure, and reliable. Most of the the web based service of today runs on java.
Create a simple java program by pasting the below test to a file, named tecmint.java
(remember ‘.java‘ extension is must).
class tecmint {
public static void main(String[] arguments) {
System.out.println("Tecmint ");
}
}
Run it
Note: Almost every distribution comes packed with gcc compiler, major number of
distros have inbuilt g++ and java compiler, while some may not have. You can apt or
yum the required package.
In this article I will be explaining those commands required for administrating the
Linux Server.
Display details of All interfaces including disabled interfaces using “-a” argument.
Disable an Interface
Enable an Interface
Note: If using a wireless network you need to use command “iwconfig“. For more
“ifconfig” command examples and usage, read 15 Useful “ifconfig” Commands.
Ip:
4994239 total packets received
0 forwarded
0 incoming packets discarded
4165741 incoming packets delivered
3248924 requests sent out
8 outgoing packets dropped
Icmp:
29460 ICMP messages received
566 input ICMP message failed.
ICMP input histogram:
destination unreachable: 98
redirects: 29362
2918 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 2918
IcmpMsg:
InType3: 98
InType5: 29362
OutType3: 2918
Tcp:
94533 active connections openings
23 passive connection openings
5870 failed connection attempts
7194 connection resets received
....
OK! For some reason if you want not to resolve host, port and user name as a output
of netstat.
Fine, you may need to get the output of netstat continuously till interrupt instruction is
passed (ctrl+c).
For more “netstat” command examples and usage, see the article 20 Netstat Command
Examples.
A network utility program used to obtain information about Internet servers. As its
name suggests, the utility finds name server information for domains by querying
DNS.
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: tecmint.com
Address: 50.16.67.239
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
tecmint.com mail exchanger = 0 smtp.secureserver.net.
tecmint.com mail exchanger = 10 mailstore1.secureserver.net.
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
tecmint.com nameserver = ns3404.com.
tecmint.com nameserver = ns3403.com.
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
tecmint.com mail exchanger = 10 mailstore1.secureserver.net.
tecmint.com mail exchanger = 0 smtp.secureserver.net.
tecmint.com nameserver = ns06.domaincontrol.com.
tecmint.com nameserver = ns3404.com.
tecmint.com nameserver = ns3403.com.
tecmint.com nameserver = ns05.domaincontrol.com.
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
tecmint.com
origin = ns3403.hostgator.com
mail addr = dnsadmin.gator1702.hostgator.com
serial = 2012081102
refresh = 86400
retry = 7200
expire = 3600000
minimum = 86400
Server: tecmint.com
Address: 50.16.76.239#53
Name: 56
Address: 14.13.253.12
one of the most important command for administrator, wall sends a message to
everybody logged in with their mesg permission set to “yes“. The message can be
given as an argument to wall, or it can be sent to wall’s standard input.
[avishek@tecmint ~]$ wall "we will be going down for maintenance for one hour
sharply at 03:30 pm"
we will be going down for maintenance for one hour sharply at 03:30 pm
Lets you control if people can use the “write” command, to send text to you over the
screen.
mesg [n|y]
n - prevents the message from others popping up on the screen.
y – Allows messages to appear on your screen.
Let you send text directly to the screen of another Linux machine if ‘mesg’ is ‘y’.
An enhancement to write command, talk command lets you talk to the logged in users.
Note: If talk command is not installed, you can always apt or yum the required
packages.
what command ‘w’ seems you funny? But actually it is not. t’s a command, even if
it’s just one letter long! The command “w” is a combination of uptime and who
commands given one immediately after the other, in that order.
[avishek@tecmint ~]$ w
As the name suggests, this command rename files. rename will rename the specified
files by replacing the first occurrence from the file name.
rename a1 a0 a?
rename a1 a0 a??
Displays the processes of CPU. This command refresh automatically, by default and
continues to show CPU processes unless interrupt-instruction is given.
top - 14:06:45 up 10 days, 20:57, 2 users, load average: 0.10, 0.16, 0.21
Tasks: 240 total, 1 running, 235 sleeping, 0 stopped, 4 zombie
%Cpu(s): 2.0 us, 0.5 sy, 0.0 ni, 97.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0
st
KiB Mem: 2028240 total, 1777848 used, 250392 free, 81804 buffers
KiB Swap: 3905532 total, 156748 used, 3748784 free, 381456 cached
This command create a new ext4 file system on the specified device, if wrong device
is followed after this command, the whole block will be wiped and formatted, hence it
is suggested not to run this command unless and until you understand what you are
doing.
vi (visual), emacs, nano are some of the most commonly used editors in Linux. They
are used oftenly to edit text, configuration,… files. A quick guide to work around vi
and nano is, emacs is a.
vi-editor
1. alt+x (exit insert mode, remember to keep some space between the last letter.
2. ctrl+x command or your last word will be deleted).
3. :wq! (saves the file, with the current text, remember ‘!’ is to override).
nano editor
[avishek@tecmint ~]$ nano a.txt (open a.txt file to be edited with nano)
edit, with the content, required
Click ‘y’ to yes and enter file name, and you are done.
Rsync copies files and has a -P switch for a progress bar. So if you have rsync
installed, you could use a simple alias.
Now try to copy a large file in terminal and see the output with remaining items,
similar to a progress bar.
Moreover, Keeping and Maintaining backup is one of the most important and boring
work a system administrator, needs to perform. Rsync is a very nice tool (there exists,
several other) to create and maintain backup, in terminal.
Keeping track of memory and resources is as much important, as any other task
performed by an administrator, and ‘free‘ command comes to rescue here.
Ok till now you would have understood what this command actually stands for, from
the name of this command.mysqldump commands dumps (backups) all or a particular
database data into a given a file.For example,
zI4+Ybqfx9
[avishek@tecmint ~]$ mkpasswd -l 20
w0Pr7aqKk&hmbmqdrlmk
Merge two or more text files on lines using. Example. If the content of file1 was:
1
2
3
a
b
c
d
the resulting file3 would be:
1 a
2 b
3 c
d
lsof stands for “list open files” and displays all the files that your system has currently
opened. It’s very useful to figure out which processes uses a certain file, or to display
all the files for a single process. Some useful 10 lsof Command examples, you might be
interested in reading.
This is not the end, a System Administrator does a lot of stuff, to provide you such a
nice interface, upon which you work. System Administration is actually an art of
learning and implementing in a very much perfect way. We will try to get you with all
other necessary stuff which a linux professional must learn, linux in its basic actually
itself, is a process of learning and learning. Your good words are always sought,
which encourages us to put in more effort to give you a knowledgeable article. “Like
and share Us, to help Us Spread”.