Basic Linux Commands
Basic Linux Commands
Basic Linux Commands
know
groupadd
This is the command used to create new group. At OS level group is used
to give and take pivillages.
Syntax : groupadd <group name>
Ex : [root@rac5 ~]# groupadd group1
View : [root@rac5 ~]# cat /etc/group -This command used to
view which user belongs to which group.
Output: group1:x:607:
useradd
This is the command used to create a new user in a group.
Syntax : useradd -g <group name> <user name>
Ex : [root@rac5 ~]# useradd -g group1 user1
passwd
This is the command used to give password for create use or to update
the password.
Syntax : passwd <user name>
Ex: [root@rac5 ~]# passwd user1
Output :
[root@rac5 ~]# Changing password for user soufir.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
date
a. This is the command used to view the current system date.
Syntax : date
Output : Wed Oct 27 21:55:36 IST 2010
b. In order to update the date we can give :
Syntax : [root@rac5 ~]# date -s "2 OCT 2010 14:00:00" OR
[root@rac5 ~]# date --set="27 OCT 2010 21:56:00"
Output : Sat Oct 2 14:00:00 IST 2010
cal
This command shows the calender of current year or any.
Ex : [root@rac5 ~]# Cal
Output : [root@rac5 ~]# October 2010
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
pwd
This command is to view the present working directory.
Ex : [root@rac5 ~]# pwd
Output : [root@rac5 ~]# /root.
cd
a.This is the command used to change a directory
Ex : [oracle@rac5 ~]$ ls
authorized_keys file file2 oraInventory stand.ora
authorized-keys file1 file3 soufir
[oracle@rac5 ~]$ cd soufir
[oracle@rac5 soufir]$
b.This is used to go back to parent directory
Ex : cd ..
mkdir
This command is used for make a new directory.
Ex : mkdir dir1
rmdir
This commad is used for remove a directory.
Ex : rmdir dir1
rm -rf
This command is used to forcefully remove a direcory.
Ex : rm -fr dir1
man
This command is used to show the online manual pages of related
commands
Ex : man ls
ls
This command is used to list all contents of directories
Ex : ls
ls -lt
This command is used to list lot of information about contents of
directories
Ex : ls -lt
The permissions are the first 10 characters of the line (-rwxrwx---) and
can be broken down as follows.
touch
This command is used create an empty file
Ex : touch file1
cat
This command is used to create and view files of directories
Ex : cat file1
cat file1 > newfile // owerwrite newfile with file1
cat file1 >> newfile // append newfile the contents with
file1
cp
This command is used to copy a file from one to another
Ex : cp file1 filenew
mv
This command is used to rename the name of a file to other
Ex : mv file1 filenew
su
This command is used to switch one user to other. it doesnot change the
current working directory. so you cant access the /usr/sbin directories.
Ex : su soufir
su -
This command is used to switch one user with changing current working
directory.
Ex : su - soufir
50 Most Frequently Used UNIX /
Linux Commands (With
Examples)
by RAME SH NATARAJAN on NOVEMBER 8, 2010
Print the matched line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
$ grep -r "ramesh" *
$ ssh -V
When you copy a DOS file to Unix, you could find \r\n in the
end of each line. This example converts the DOS file format to
Unix file format using sed command.
Print all lines from /etc/passwd that has the same uid and gid
$ vim -R /etc/passwd
2c2,3
$ sort names.txt
$ sort -r names.txt
declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"
declare -x ORACLE_SID="med"
declare -x ORACLE_TERM="xterm"
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
$ ls -lh
$ ls -ltr
$ ls -F
More ls examples: Unix LS Command: 15 Practical Examples
13. pwd command
$ gzip test.txt
$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
$ bzip2 test.txt
bzip2 -d test.txt.bz2
$ unzip test.zip
$ unzip -l jasper.zip
Archive: jasper.zip
# shutdown -h now
# shutdown -h +10
# shutdown -r now
$ ftp IP/hostname
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html
More ftp examples: FTP and SFTP Beginners Guide with 10
Examples
20. crontab command examples
# crontab -u john -l
*/10 * * * * /home/ramesh/check-disk-space
service --status-all
Restart a service.
$ ps -ef | more
To view current running processes in a tree structure. H
option stands for process hierarchy.
$ ps -efH | more
$ free
$ free -g
Mem: 3 1 1 0 0 0
-/+ buffers/cache: 0 2
Swap: 3 0 3
ramesh@ramesh-laptop:~$ free -t
Select sort field via field letter, type any other key to return
a: PID = Process Id v: nDRT = Dirty Pages count
........
$ top -u oracle
More top examples: Can You Top This? 15 Practical Linux Top
Command Examples
25. df command examples
ramesh@ramesh-laptop:~$ df -h
$ kill -9 7243
More kill examples: 4 Ways to Kill a Process – kill, killall,
pkill, xkill
27. rm command examples
$ rm -i filename.txt
$ rm -i file*
$ rm -r example
28. cp command examples
$ cp -p file1 file2
$ cp -i file1 file2
$ mv -i file1 file2
$ mv -v file1 file2
$ cat -n /etc/logrotate.conf
1 /var/log/btmp {
2 missingok
3 monthly
5 rotate 1
6 }
# mkdir /u01
You can also add this to the fstab for automatic mounting. i.e
Anytime system is restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2
Give full access to user and group (i.e read, write and execute )
on a specific file.
Revoke all access for the group (i.e read, write and execute )
on a specific file.
$ passwd
Super user can use passwd command to reset others
password. This will not prompt for current password of the
user.
# passwd USERNAME
# passwd -d USERNAME
$ mkdir ~/temp
$ ifconfig -a
$ ifconfig eth0 up
$ uname -a
$ whereis ls
/usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other
than the whereis default path, you can use -B option and give
path as argument to it. This searches for the executable lsmk
in the /tmp directory, and displays it, if it is available.
lsmk: /tmp/lsmk
$ whatis ls
$ whatis ifconfig
ifconfig (8) - configure a network interface
Using locate command you can quickly search for the location
of a specific file (or group of files). Locate command uses the
database created by updatedb.
The example below shows all files in the system that contains
the word crontab in it.
$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim
$ man crontab
1. General commands
2. System calls
3. C library functions
4. Special files (usually devices, those found in /dev) and
drivers
5. File formats and conventions
6. Games and screensavers
7. Miscellaneous
8. System administration commands and daemons
$ whatis crontab
$ man 5 crontab
$ tail filename.txt
$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is
useful to view the log files, that keeps growing. The command
can be terminated using CTRL-C.
$ tail -f log-file
One you open a file using less command, following two keys
are very helpful.
$ su - USERNAME
[john@dev-server]$
$ su -s 'SHELLNAME' USERNAME
$ mysql -u root -p
# hwclock –systohc
$ wget
http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-
3.2.1.tar.gz
$ wget -O taglist.zip
http://www.vim.org/scripts/download_script.php?src_id=7701