CentOS Command
CentOS Command
[root@techbrown~]# pwd
Files can be created by using any of the three methods given below:
Cat command
Touch command
Vi editor
Touch Command
1
Linux Useful Command Soe Thurein Tun
Vi Editor
To create file
[root@techbrown~]# vi <filename>
Creating Directories
To create a directory
[root@techbrown~]# mkdir <directory name>
To create multiple directories
[root@techbrown~]# mkdir <first dir> <second dir> <third dir>
To create nested directories
[root@techbrown~]# mkdir –p <first dir>/<second dir>/<third dir>
Navigation of Directories
Copying
2
Linux Useful Command Soe Thurein Tun
Deleting
VI editor modes
Command Mode
Insert mode
Ex Mode (Extended Command Mode)
Insert Mode
3
Linux Useful Command Soe Thurein Tun
Ex mode
Command Mode
dd – Deletes a line
ndd – Deletes ‘n’ lines (eg. 20dd)
yy – Copies a line
nyy – Copies ‘n’ lines
p – Put (pastes the deleted or copied text)
u – Undo(you can undo 1000 times)
G – Moves the cursor to the last line of the file
Uptime Command
In Linux uptime command shows since how long your system is running and the number of
users are currently logged in and also displays load average for 1,5 and 15 minutes intervals.
# uptime
08:16:26 up 22 min, 1 user, load average: 0.00, 0.03, 0.22
Uptime command don’t have other options other than uptime and version. It gives
information only in hours:mins if it less than 1 day.
W Command
It will displays users currently logged in and their process along-with shows load averages.
also shows the login name, tty name, remote host, login time, idle time, JCPU, PCPU,
command and processes.
#w
08:27:44 up 34 min, 1 user, load average: 0.00, 0.00, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecmint pts/0 192.168.50.1 07:59 0.00s 0.29s 0.09s w
4
Linux Useful Command Soe Thurein Tun
Users Command
Users command displays currently logged in users. This command don’t have other
parameters other than help and version.
# users
tecmint
Who Command
who command simply return user name, date, time and host information. who command is
similar to w command. Unlike w command who doesn’t print what users are doing. Lets
illustrate and see the different between who and w commands.
# who
tecmint pts/0 2012-09-18 07:59 (192.168.50.1)
#w
08:43:58 up 50 min, 1 user, load average: 0.64, 0.18, 0.06
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tecmint pts/0 192.168.50.1 07:59 0.00s 0.43s 0.10s w
Whoami Command
whoami command print the name of current user. You can also use “who am i” command to
display the current user. If you are logged in as a root using sudo command “whoami”
command return root as current user. Use “who am i” command if you want to know the
exact user logged in.
# whoami
tecmint
ls Command
# ls -l
total 114
dr-xr-xr-x. 2 root root 4096 Sep 18 08:46 bin
dr-xr-xr-x. 5 root root 1024 Sep 8 15:49 boot
# ls -ltr
total 40
-rw-r--r--. 1 root root 6546 Sep 17 18:42 install.log.syslog
-rw-r--r--. 1 root root 22435 Sep 17 18:45 install.log
-rw-------. 1 root root 1003 Sep 17 18:45 anaconda-ks.cfg
5
Linux Useful Command Soe Thurein Tun
Less Command
less command allows quickly view file. You can page up and down. Press ‘q‘ to quit from
less window.
# less install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
More Command
more command allows quickly view file and shows details in percentage. You can page up
and down. Press ‘q‘ to quit out from more window.
# more install.log
Installing setup-2.8.14-10.el6.noarch
warning: setup-2.8.14-10.el6.noarch: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Installing filesystem-2.4.30-2.1.el6.i686
Installing ca-certificates-2010.63-3.el6.noarch
Installing xml-common-0.6.3-32.el6.noarch
Installing tzdata-2010l-1.el6.noarch
Installing iso-codes-3.16-2.el6.noarch
--More--(10%)
CP Command
# cp -p fileA fileB
MV Command
Rename fileA to fileB. -i options prompt before overwrite. Ask for confirmation if exist
already.
# mv -i fileA fileB