Sie sind auf Seite 1von 12

operating system your system is running on in UNIX?

By using command "uname -a"in UNIX


How do you check how much space left in current drive ?
By using "df" command in UNIX. For example "df -h ." will list how full your
current drive is.
Swapping:
Whole process is moved from the swap device to the main memory for
execution. Process size must be less than or equal to the available main
memory. It is easier to implementation and overhead to the system. Swapping
systems does not handle the memory more flexibly as compared to the paging
systems.
Paging:
Only the required memory pages are moved to main memory from the swap
device for execution. Process size does not matter. Gives the concept of the
virtual memory. It provides greater flexibility in mapping the virtual address
space into the physical memory of the machine. Allows more number of
processes to fit in the main memory simultaneously. Allows the greater process
size than the available physical memory. Demand paging systems handle the
memory more flexibly.
arch - print machine hardware name (same as uname -m)
lsof - list open files
What is nohup in UNIX?
nohup is a special command which is used to run process in background, but it
is slightly different than & which is normally used for putting a process in
background. An UNIX process started with nohupwill not stop even if the user
who has stared log off from system. While background process started with &
will stop as soon as user logoff.

How will you find which directory is taking how much space?
By using disk usage (DU) command in Unix for example du sh . | grep G
will list down all the directory which has GIGS in Size.
Whatarethefourfundamentalcomponentsofeveryfilesystemonlinux?
bootblock,superblock,inodeblockanddatablock
Whatisabootblock?
ThisblockcontainsasmallprogramcalledMasterBootrecord(MBR)whichloadsthe
kernelduringsystembootup.
Whatisthedifferencebetween$$and$!?

$$givestheprocessidofthecurrentlyexecutingprocesswhereas$!showstheprocess
idoftheprocessthatrecentlywentintobackground.
Whatarezombieprocesses?
Thesearetheprocesseswhichhavediedbutwhoseexitstatusisstillnotpickedbythe
parentprocess.Theseprocessesevenifnotfunctionalstillhaveitsprocessidentryinthe
processtable.
Iwanttoconnecttoaremoteserverandexecutesomecommands,howcanI
achievethis?
Wecanusetelnettodothis:
telnethostnameluser
>Enterpassword
>Writethecommandtoexecute
>quit
Ihave2filesandIwanttoprinttherecordswhicharecommontoboth.
Wecanusecommcommandasfollows:
comm12file1file212willsuppressthecontentwhichare
uniqueto1stand2ndfilerespectively.
Writeascripttoprintthefirst10elemenstofFibonacciseries.
a=1
b=1
echo$a
echo$b
forIin12345678
do
c=a
b=$a
b=$(($a+$c))
echo$b

done
Iwanttoreadallinputtothecommandfromfile1directalloutputtofile2anderror
tofile3,howcanIachievethis?
command<file11>file22>file3
WhatwillhappentomycurrentprocesswhenIexecuteacommandusingexec?
execoverlaysthenewlyforkedprocessonthecurrentprocess;sowhenIexecutethe
commandusingexec,thecommandgetsexecutedonthecurrentshellwithoutcreating
anynewprocesses.
Eg:Executingexeclsoncommandpromptwillexecutelsandoncelsexits,theprocess
willshutdown
Whatisthedifferencebetweengrepandegrep?
egrepisExtendedgrepthatsupportsaddedgrepfeatureslike+(1ormoreoccurrence
ofpreviouscharacter),?(0or1occurrenceofpreviouscharacter)and|(alternate
matching)
:Howwillyoufindthetotaldiskspaceusedbyaspecificuser?
dus/home/user1.whereuser1istheuserforwhomthetotaldisk
spaceneedstobefound.
HowcanIsetthedefaultrwxpermissiontoallusersoneveryfilewhichiscreated
inthecurrentshell?
1

umask777

Howdowecreatecommandaliasesinshell?
aliasAliasname=Commandwhosealiasistobecreated

Whatisasuperblock?
Superblockcontainsalltheinformationaboutthefilesystemlikesizeoffilesystem,block
sizeusedbyit,numberoffreedatablocksandlistoffreeinodesanddatablocks.
Whatisaninodeblock?
Thisblockcontainstheinodeforeveryfileofthefilesystemalongwithallthefileattributes
exceptitsname.
Whatarecandbpermissionfieldsofafile?

candbpermissionfieldsaregenerallyassociatedwithadevicefile.Itspecifies
whetherafileisacharacterspecialfileorablockspecialfile.

How do I find out what shell Im using?


Psp$$
explainswhere.and..comefrom.
NOTE:The.and..mayappearatanypointwithinapath.Theymean"thecurrent
directoryatthispointinthepath"and"theparentofthecurrentdirectoryatthispointinthe
path."
reversetheorderoffilecontent
$tacfile
Note:tacisnotavailableinallUnixflavors.
$sedn'1!G;h;$p'thegeekstuff.txt
$sedn'1{h;T;};G;h;$p;'file
AIX
Solaris
Linux
Manycommandsofsedareusedhere.Fornow,wewilldiscussitbriefly.seduses2
things:patternspace&holdspace.Patternspaceiswherealinefromtheinputfileisread
into.Holdspacecanbeusedtotemporarilyholddata.Thelogicissimple:Everytimea
lineisreadintothepatternspace,concatenatetheholdspacetothepatternspace,and
keepitbackintheholdspace.Oncethelastlineisprocessed,printthecontentsinthe
holdspace.
h:Copypatternspacecontentstoholdspace.
G:Appendholdspacecontenttopatternspace.
T:Toskiptheremainingpart.
Whenthefirstline(1)isread,itisjustcopiedtoholdspace(h).Fromthenextline,thehold
spacecontentisappended(G)tothecurrentpatternspace,andthecontentinpattern
spaceisnowmovedtoholdspace.Whenthelastline($)isencountered,thecontentsin
thepatternspacearesimplyprinted.
reverseastringinLinux
$echowelcome|rev
awk,usingthesubstringfunction,canreverseastring:

$echowelcome|awk'{for(i=length;i!=0;i)x=xsubstr($0,i,1);}END{printx}'
Findallemptyfilesinhomedirectory
#find~empty
Iftheuserwantstoredirectboththeoutputanderrortothesamefile:
#./StartScript.sh>f12>&1
Twothingstobenotedintheaboveexample:
First,theoutputgotredirectedtothefilef1
2>&1Thismeansredirecttheerror(2)tothesameterminalastheoutput(&1).
Sinceoutputisredirectedtof1,theerrorisalsoredirectedtof1
NetworkingCommands
findinghost/domainnameandIPaddresshostname
testnetworkconnectionping
gettingnetworkconfigurationifconfig
Networkconnections,routingtables,interfacestatisticsnetstat
queryDNSlookupnamenslookup
communicatewithotherhostnametelnet
outingstepsthatpacketstaketogettonetworkhosttraceroute
viewuserinformationfinger
checkingstatusofdestinationhosttelnet
hostname
hostnamewithnooptionsdisplaysthemachineshostname
hostnameddisplaysthedomainnamethemachinebelongsto
hostnamefdisplaysthefullyqualifiedhostanddomainname
hostnameidisplaystheIPaddressforthecurrentmachine
ping
Itsendspacketsofinformationtotheuserdefinedsource.Ifthepacketsarereceived,the
destinationdevicesendspacketsback.Pingcanbeusedfortwopurposes
1.Toensurethatanetworkconnectioncanbeestablished.
2.Timinginformationastothespeedoftheconnection.
Ifyoudopingwww.yahoo.comitwilldisplayitsIPaddress.Usectrl+Ctostopthetest.
ifconfig
Viewnetworkconfiguration,itdisplaysthecurrentnetworkadapterconfiguration.Itis
handytodetermineifyouaregettingtransmit(TX)orreceive(RX)errors.

netstat
Mostusefulandveryversatileforfindingconnectiontoandfromthehost.Youcanfindout
allthemulticastgroups(network)subscribedbythishostbyissuing"netstatg"
netstatnap|grepportwilldisplayprocessidofapplicationwhichisusingthatport
netstataornetstatallwilldisplayallconnectionsincludingTCPandUDP
netstattcpornetstattwilldisplayonlyTCPconnection
netstatudpornetstatuwilldisplayonlyUDPconnection
netstatgwilldisplayallmulticastnetworksubscribedbythishost.
nslookup
IfyouknowtheIPaddressitwilldisplayhostname.TofindalltheIPaddressesforagiven
domainname,thecommandnslookupisused.Youmusthaveaconnectiontotheinternet
forthisutilitytobeuseful.
E.g.nslookupblogger.com
traceroute
Ahandyutilitytoviewthenumberofhopsandresponsetimetogettoaremotesystemor
websiteistraceroute.Againyouneedaninternetconnectiontomakeuseofthistool.
finger
Viewuserinformation,displaysausersloginname,realname,terminalnameandwrite
status.thisisprettyoldunixcommandandrarelyusednowdays.
telnet
Connectsdestinationhostviatelnetprotocol,iftelnetconnectionestablishonanyport
meansconnectivitybetweentwohostsisworkingfine.
telnethostnameportwilltelnethostnamewiththeportspecified.Normallyitisusedtosee
whetherhostisaliveandnetworkconnectionisfineornot.

du==DiskUsage.Itwalksthroughdirectorytreeandcountsthesumsizeofallfiles
therein.Itmaynotoutputexactinformationduetothepossibilityofunreadablefiles,
hardlinksindirectorytree,etc.Itwillshowinformationaboutthespecificdirectory
requested.Think,"Howmuchdiskspaceisbeingusedbythesefiles?"
df==DiskFree.Looksatdiskusedblocksdirectlyinfilesystemmetadata.Becauseof
thisitreturnsmuchfasterthatdubutcanonlyshowinfoabouttheentiredisk/partition.
Think,"HowmuchfreediskspacedoIhave?"

basic'findfile'commands

find/namefoo.txttypefprint#fullcommand
find/namefoo.txttypef#printisn'tnecessary

find/namefoo.txt#don'thavetospecify"type==file"
find.namefoo.txt#searchunderthecurrentdir
find.name"foo.*"#wildcard
find.name"*.txt"#wildcard
find/users/alnameCookbooktyped#search'/users/al'
searchmultipledirs

find/opt/usr/varnamefoo.scalatypef#searchmultipledirs
caseinsensitivesearching

find.inamefoo#findfoo,Foo,FOo,FOO,etc.
find.inamefootyped#samething,butonlydirs
find.inamefootypef#samething,butonlyfiles
findfileswithdifferentextensions

find.typef\(name"*.c"oname"*.sh"\)#*.cand*.shfiles
find.typef\(name"*cache"oname"*xml"oname"*html"\)#threepatterns
findfilesthatdon'tmatchapattern(not)

find.typefnotname"*.html"#findallfilesnotendingin".html"
findfilesbytextinthefile(find+grep)

find.typefname"*.java"execgreplStringBuffer{}\;#findStringBufferinall*.java
files
find.typefname"*.java"execgrepilstring{}\;#ignorecasewithioption
find.typefname"*.gz"execzgrep'GET/foo'{}\;#searchforastringingzip'd
files
5linesbefore,10linesaftergrepmatches

find.typefname"*.scala"execgrepB5A10'null'{}\;
(seehttp://alvinalexander.com/linuxunix/findgrepprintlinesbeforeafter...)
findfilesandactonthem(find+exec)

find/usr/localname"*.html"typefexecchmod644{}\;#changehtmlfilestomode
644
findhtdocscgibinname"*.cgi"typefexecchmod755{}\;#changecgifilestomode
755
find.name"*.pl"execlsld{}\;#runlscommandonfilesfound
findandcopy

find.typefname"*.mp3"execcp{}/tmp/MusicFiles\;#cp*.mp3filesto

/tmp/MusicFiles
copyonefiletomanydirs

finddir1dir2dir3dir4typedexeccpheader.shtml{}\;#copythefileheader.shtmlto
thosedirs
findanddelete

find.typefname"Foo*"execrm{}\;#removeall"Foo*"filesunder
currentdir
find.typednameCVSexecrmr{}\;#removeallsubdirectoriesnamed
"CVS"undercurrentdir
findfilesbymodificationtime

find.mtime1#24hours
find.mtime7#last7days
find.mtime7typef#justfiles
find.mtime7typed#justdirs
findfilesbymodificationtimeusingatempfile

touch09301330poop#1)createatempfilewithaspecifictimestamp
find.mnewerpoop#2)returnsalistofnewfiles
rmpoop#3)rmthetempfile
findwithtime:thisworksonmacosx

find/newerct'1minuteago'print
findandtar

find.typefname"*.java"|xargstarcvfmyfile.tar
find.typefname"*.java"|xargstarrvfmyfile.tar
(seehttp://alvinalexander.com/blog/post/linuxunix/usingfindxargstarcrea...
formoreinformation)
find,tar,andxargs

find.nametypef'*.mp3'mtime180print0|xargs0tarrvfmusic.tar
(print0helpshandlespacesinfilenames)
(seehttp://alvinalexander.com/macosx/macbackupfilenamedirectoriesspace...)
findandpax(insteadofxargsandtar)

find.typefname"*html"|xargstarcvfjwhtmlfiles.tar
find.typefname"*html"|paxwfjwhtmlfiles.tar
(seehttp://alvinalexander.com/blog/post/linuxunix/usingpaxinsteadoftar)

Deletetheemptylinesofafile
sed'/^$/d'/tmp/detail.txt
currentshell
echo$SHELL
Thereisanimportantdifferencebetweensingleanddoublequotes.Singlequoteslimit
substitution.youcanplacevariablesindoublequotedtextandtheshellstillperforms
substitution.
Doublequotesdonotsuppressthesubstitutionofwordsthatbeginwith"$"buttheydo
suppresstheexpansionofwildcardcharacters.
Xargsandexec
$find.name"t*"
./temp2
./temp1
./temp3
$find.name"t*"|xargsls
./temp1./temp2./temp3
$find.name"t*"execls{}\;
./temp2
./temp1
./temp3
$
find/home/ganeshtypefexecchmod644{}\;
Andtoaccomplishsteps#2and#4togather.
find/home/ganeshtypedexecchmod755{}\;
ALittleexplaination
findcommandsdoesthefollowing:
1.
2.
3.
4.

findsthefilesoftypef,thatmeansitfindsregularfiles.
Thenitchangesthefilepermissionsbyexecutingchmod.
exectellsfindcommandthatyouwanttorunchmodonthefilesfoundout.
{}actsasaplaceholderforthefilefoundout.Letmetellyouhow.Letssayitfinds
filesemployees,designationsandfewothers.So,thisstepactsas:
chmod644employees

\;actsastheendofthecommandforthatparticularfile.
Thatallmeans,whenitfindsafile,itrunsachmodcommandforeveryfileinthehome
directory.

Sameappliestodirectorypermissionsaswell.
Nowletssayyouvegotabout10000filesand2000directories.Inthatcaseabove
methodrunschmodcommand10000timesforfilesand2000timesfordirectories.So,
chmodrunsintotal10000+2000=12000times.
Veryinefficient.Isntit?
Nowletsmakeitefficient.Herexargscomestoourrescue.
Letmeshowyouhowthisacts.
find/home/ganeshtypef|xargschmod644
Thismeansnowfirstfindfindsallfilesthen,attheendxargschangespermissionsofall
filesatonce.Thatmeans,itrunsonlyonetime.10,000timesfaster!!!Great.
Similarlyfordirectorypermissionchanges.
find/home/ganeshtyped|xargschmod755
Thishelpstochangepermissionsofalldirectoriesfoundinasinglestep.2000times
faster!!!goodtosee.

Differences between xargs and exec commands


1. xargscommandisfasterthanexec.
2. xargsneedstobeusedwith|(piped)[checkexamplebelow]whereasexec
commanddoesntneedbepiped.
3. xargscommandfailsifthefilenameorfilenameshassomeweirdcharacterinit
whereasexecworks
4. execcommandcanbeusedtoexecutecommandswithoutreturningandopening
andclosingfileswhereasxargsusespipes
5. xargssupportslargefilecountsthususesmemorycomparedtoexec

How to effectively work with multiple files in Vim?


I'vestartedusingVimtodevelopPerlscriptsandamstartingtofindit
verypowerful.
OnethingIlikeistobeabletoopenmultiplefilesatoncewithe.g.vi
main.pl maintenance.plandthenhopbetweenthemwith:
:n
:prev
andseewhichfileareopenwith
:args

Andtoaddafile,Icansay:
:n test.pl

Das könnte Ihnen auch gefallen