Linux Dev Basic commands List

Command Use case Examples
cd / Prompts you to the root  directory i.e parent directory for all users. web(ecrbatch)  DIR…> /
$
web(ecrbatch)  DIR…> /
$ cd ..
web(ecrbatch)  DIR…> /
cd /home Prompts you to the users directory under the root directory. $ cd home
web(ecrbatch)  DIR…> /home
$ ls -ltr
total 6
drwxr-xr-x   2 n0199771 techserv     512 May 17  2013 n0199771
drwxr-xr-x   2 20510    techserv     512 Jan 19  2014 n0171821
drwxr-xr-x   2 zabbix   zabbix       512 Sep 14 00:29 zabbix
web(ecrbatch)  DIR…> /home
ls $home Tell us the first user created so far.. web(ecrbatch)  DIR…> /home
$ ls $home
n0171821  n0199771  zabbix
web(ecrbatch)  DIR…> /home
cd ~ Prompts you to the your home directory web(ecrbatch)  DIR…> /export/home/ecrbatch
$ cd ~
web(ecrbatch)  DIR…> /export/home/ecrbatch
cd – Prompts you to the previous directory $
web(ecrbatch)  DIR…> /export/home/ecrbatch
$ cd –
/export/home/ecrbatch
web(ecrbatch)  DIR…> /export/home/ecrbatch
$ cd /opt/ecmon
web(ecrbatch)  DIR…> /opt/ecmon
$ cd –
/export/home/ecrbatch
web(ecrbatch)  DIR…> /export/home/ecrbatch
cd .. Prompts you to the parent directory of current directory i.e tree web(ecrbatch)  DIR…> /export/home/ecrbatch
$
web(ecrbatch)  DIR…> /export/home/ecrbatch
$ cd ..
web(ecrbatch)  DIR…> /export/home
pwd tells you the present directory that you’re in $ pwd
/export/home
web(ecrbatch)  DIR…> /export/home
ls -d*/ List you the all sub-directories of cureent directory web(ecrbatch)  DIR…> /export/home
$ cd /
web(ecrbatch)  DIR…> /
$ ls -d */
CA/               devices/          lib/              sbin/
VXVM-CFG-BAK/     etc/              loss_prevention/  tmp/
autoupdate/       export/           lost+found/       usr/
bin/              extra_swap/       mnt/              ust/
bladelogic/       forensic/         net/              util/
cdrom/            home/             netegrity/        var/
database/         intranet_test/    opt/              vol/
datasrvc/         kernel/           platform/         webdocs/
dev/              ldap/             proc/             xfn/
ls -l | grep ‘^d’ Sub directories with the names and dates ,permisiions all verbose web(ecrbatch)  DIR…> /
$  ls -l | grep ‘^d’
drwxrwxr-x   3 root     other        512 May 10  2011 CA
drwxr-xr-x   3 root     other        512 Jun 29  2010 VXVM-CFG-BAK
drwxr-xr-x   7 updater  web_admin     512 Nov  8  2001 autoupdate
drwxr-xr-x   3 root     root         512 Jun 13  2013 bladelogic
drwxr-xr-x   3 root     nobody       512 Aug 26  2003 cdrom
find . esd_6084 ‘*.pl’ find the file in all subdirectories
ls -a list the files of directory $ ls -a
.                            ECRSpecialPrograms
..                           IdDeletions
CleanUpServiceIds            Level2Admin
EC                           PLIQ
ECRBuildSerializedResources  UserCount
ECRReports                   srch.ksh
ls -l,ls-A,ls-ltr,ls-n,ls -lh,ls -r.ls_R.ls-ltr List the files of current directory or parent/child or sum of any possible 3 combinations depends on the I/p web(ecrbatch)  DIR…> /opt/ecmon/batchjobs
$ ls -l
total 18
drwsrws—   2 ecrbatch ec           512 Jul 11  2013 CleanUpServiceIds
-rw-rw-r–   1 ecrbatch ec             0 Oct 25 10:28 EC
drws——   3 ecrbatch ec          1024 Sep  1 13:42 ECRBuildSerializedResources
drwsrws—  15 ecrbatch ec           512 Nov 28 02:19 ECRReports
drwsrws—  23 ecrbatch ec          1024 Jul 15  2014 ECRSpecialPrograms
drwsrws—   3 ecrbatch ec           512 Dec  9 02:39 IdDeletions
drwsrws—  12 ecrbatch ec           512 Oct  3 15:13 Level2Admin
drwsrws—   2 ecrbatch ec           512 Sep  8  2006 PLIQ
drwsrws—   3 ecrbatch ec           512 May 30  2007 UserCount
-rw-rw-r–   1 ecrbatch ec           261 Jul  6  2009 srch.ksh
mkdir <name> To make a  new directory web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ mkdir ecr_newdir
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
total 86
drwxrwxr-x   2 ecrbatch web_admin     512 Dec 10 03:05 ecr_newdir
rmdir To remove the directory web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ rmdir ecr_newdir
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
total 84
file Tells us which type of file web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ file n0290635.txt
n0290635.txt:   ascii text
web(ecrbatch)  DIR…> /opt/ecmon/tmp
touch <filenamame> Creates a new file web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ touch mynewfile.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
rm <filename> removes the file web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ rm mynewfile.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
stty columns 120 limit the coulmns web(ecrbatch)  DIR…> /opt/ecmon/tmp
$
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ vi hiii.txt
Terminal too wide
:q
1 more file to edit:q
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ stty columns 120
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$
vi creates and open vi editor
vi j-k-l-m-I -esc used to add text in insert or some other mode
vi esc+:+wq save and exit
vi esc+:+q quit without save
vi esc+:!Q quit without save
less fileanme shows the file content in unedit mode web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ less hii.txt
nhjerserse
fsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdhjnfjkd

hdhhhhhhhhhhhhhhfk

view fileaname shows in the editor nhjerserse
fsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdhjnfjkd

hdhhhhhhhhhhhhhhfk

tail filename shows the file content in unedit mode $ tail hii.txt
nhjerserse
fsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdhjnfjkd

hdhhhhhhhhhhhhhhfk
web(ecrbatch)  DIR…> /opt/ecmon/tmp

mv source destination(new) creates the dest file and copies the content of source to dest and deletes the source file web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ mv hi2.txt hii.txt
mv: cannot access hi2.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ mv hii.txt hii2.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
mv source destination(existed)  copies the content of source to dest and deletes the source file i.e old content is ovverided with new $ mv hii2.txt hiii1.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
total 86
cp one two Keep both files but copies the content only web(ecrbatch)  DIR…> /opt/ecmon/tmp
$
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ cp hiii1.txt messi.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
mv file1 file2 rename the file web(ecrbatch)  DIR…> /opt/ecmon/tmp
$
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ mv messi.txt madhu.txt
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
file * / file -s /file <dirname> etc….. List all the files based on i/p  file *
ESD-8960:       directory
crontab.txt:    ascii text
esd-9058-1:     empty file
esd_6084.attribute.properties:  c
file[m-y]* List the files from alphabet to alphabet $ file[m-y]*
bash: file[m-y]*: command not found
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ file [m-y]*
madhu.txt:      ascii text
monthlyReport.pl:       executable /usr/bin/perl script
monthlyReportTrigger.pl:        executable /bin/perl script
n0290635.txt:   ascii text
risk.ksh:       c program text
riskquery.ksh:  executable /bin/ksh script
rm <string>* / rm -I / rm -rf Removes the multiple files based on I/p  here it removes all files with madhu——all files web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ rm madhu*
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
cp backup keps the back up fo file1 and then copies the content web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ cp backup hiii1.txt dd.txt
cp: Target dd.txt must be a directory
Usage: cp [-f] [-i] [-p] f1 f2
cp [-f] [-i] [-p] f1 … fn d1
cp -r|R [-f] [-i] [-p] d1 … dn-1 dn
web(ecrbatch)  DIR…> /opt/ecmon/tmp
$ ls -ltr
Advertisements