m E x. N o. 3 F I L E M A N A G E M E N T Aim To manag ils and dirctoris using Linux commands. I. F i l M a n a g m n t 1. il Examins th typ o th givn il or dirctory i l i l n a m > ( o r ) < d i r c t o r y n a m. > < 2. pwd Displays th currnt working dirctory p w d 3.cat Displays a il. It can tak ilnams or its argumnts. It outputs th contnts o thos ils dirctly to th standard output, which, by dault, is dirctd to th scrn. c a t < i l n a m > 4. mor Displays a il scrn by scrn. th SPACEBAR is prssd to continu to th nxt scrn and q to quit. o r i l n a m > < 5.lss Displays a il scrn by scrn. Prss th SPACEBAR to continu to th nxt scrn and q to quit. l s s < i l n a m s > 6.cmp
Compar two ils byt by byt c m p [ O P T I O N ]... F I L E 1 [ F I L E 2 [ S K I P 1 [ S K I P 2 ] ] ] - b - - p r i n t - b y t s - i S K I P - - i g n o r - i n i t i a l = S K I P Print diring byts. - i S K I P 1 : S K I P 2 - - i g n o r - i n i t i a l = S K I P 1 : S K I P 2 Skip th irst SKIP byts o input. Skip th irst SKIP1 byts o FILE1 and th irst SKIP2 byts o FILE2. - l - - v r b o s Output byt numbrs and valus o all diring byts. - n L I M I T - - b y t s = L I M I T Compar at most LIMIT byts. 7. cut Prints slctd parts o lins rom ach FILE to standard output. c u t [ O P T I O N ]... [ F I L E ]... - b, - - b y t s = L I S T - c, - - c h a r a c t r s = L I S T - d, - - d l i m i t r = D E L I M dlimitr Slcts only ths byts Slcts only ths charactrs Us DELIM instad o TAB or ild 8.di Shows th dirncs btwn ils.
d i [ O P T I O N ]... F I L E S Options - i - - i g n o r - c a s - - i g n o r - i l - n a m - c a s - - n o - i g n o r - i l - n a m - c a s Ignor cas dirncs in il contnts. Ignor cas whn comparing il nams. - E - - i g n o r - t a b - x p a n s i o n - b - - i g n o r - s p a c - c h a n g - w - - i g n o r - a l l - s p a c - B - - i g n o r - b l a n k - l i n s - I R E - - i g n o r - m a t c h i n g - l i n s = R E Considr cas whn comparing il nams. Ignor changs du to tab xpansion. whit spac. Ignor changs in th amount o Ignor all whit spac. blank. Ignor changs whos lins ar all - - s t r i p - t r a i l i n g - c r - a - - t x t - q - - b r i - - n o r m a l Ignor changs whos lins all match RE. Strip trailing carriag rturn on input. Trat all ils as txt. Output only whthr ils dir. Output a normal di. 9.slp Paus or NUMBER sconds. SUFFIX may b s or sconds (th dault), m or minuts, h or hours or d or days. Unlik most implmntations that rquir NUMBER b an intgr, hr NUMBER may b an arbitrary loating point numbr
E s l p N U M B E R [ S U F F I X ]... 10. sort Writ sortd concatnation o all FILE(s) to standard output s o r t [ O P T I O N ]... [ F I L E ]... Ordring options: - b, - - i g n o r - l a d i n g - b l a n k s - d, - - d i c t i o n a r y - o r d r alphanumric charactrs -, - - i g n o r - c a s charactrs - g, - - g n r a l - n u m r i c - s o r t ignor lading blanks considr only blanks and old lowr cas to uppr cas compar according to gnral numrical valu - i, - - i g n o r - n o n p r i n t i n g considr only printabl charactrs - M, - - m o n t h - s o r t compar (unknown) < JAN <... < DEC - n, - - n u m r i c - s o r t compar according to string numrical valu - r, - - r v r s rvrs th rsult o comparisons Othr options: - c, - - c h c k chck whthr input is sortd; do not sort - k, - - k y = P O S 1 [, P O S 2 ] start a ky at POS1, nd it at POS2 (origin 1) - m, - - m r g mrg alrady sortd ils; do not sort - o, - - o u t p u t = F I L E writ rsult to FILE instad o standard output - s, - - s t a b l stabiliz sort by disabling last-rsort comparison - S, - - b u r - s i z = S I Z us SIZE or main mmory bur - t, - - i l d - s p a r a t o r = S E P us SEP instad o non-blank to blank transition - T, - - t m p o r a r y - d i r c t o r y = D I R us DIR or tmporaris, not $TMPDIR or /tmp; multipl options spciy multipl dirctoris - u, - - u n i q u with -c, chck or strict ordring; without -c, output only th irst o an qual run
- z, - - z r o - t r m i n a t d nd lins with 0 byt, not nwlin 11.uniq Rports or omits rpatd lins. Discards all but on o succssiv idntical lins rom INPUT (or standard input), writing to OUTPUT (or standard output). u n i q [ O P T I O N ]... [ I N P U T [ O U T P U T ] ] - c, - - c o u n t prix lins by th numbr o occurrncs - d, - - r p a t d only print duplicat lins - D, - - a l l - r p a t d [ = d l i m i t - m t h o d ] d l i m i t print all duplicat lins - m t h o d = { n o n ( d a u l t ), p r p n d, s p a r a t } -, - - s k i p - i l d s = N ilds - i, - - i g n o r - c a s comparing - s, - - s k i p - c h a r s = N charactrs - u, - - u n i q u - w, - - c h c k - c h a r s = N in lins dlimiting is don with blank avoid comparing th irst N ignor dirncs in cas whn avoid comparing th irst N only print uniqu lins compar no mor than N charactrs 12.wc Print nwlin, word, and byt counts or ach FILE, and a total lin i mor than on FILE is spciid. With no FILE, or whn FILE is -, rad standard input. w c c / w / l < i l n a m >
. d Options - c, - - b y t s - m, - - c h a r s - l, - - l i n s - L, - - m a x - l i n - l n g t h - w, - - w o r d s print th byt counts print th charactr counts print th nwlin counts print th lngth o th longst lin print th word counts I I D i r c t o r y M a n a g m n t 1. Crating and Dlting Dirctoris m k d i r d i r c t o r y r m d i r d i r c t o r y l s - F l s - R subdirctoris. c d d i r c t o r y n a m Crats a dirctory. Erass a dirctory. Lists dirctory nam with a prcding slash Lists working dirctory as wll as all Changs to th spciid dirctory, making it th working dirctory. cd without a dirctory nam changs back to th hom dirctory. p w Displays th pathnam o th working dirctory. d i r c t o r y n a m / i l n a m A slash is usd in pathnams to sparat ach dirctory nam. In th cas o pathnams or ils, a slash sparats th prcding dirctory nams rom th ilnam... Rrncs th parnt dirctory. It can b usd as an argumnt or as part o a pathnam ~ / p a t h n a m Rrncs th working dirctory. You can us it l s. as an argumnt or as part o a pathnam: $ Th tild is a spcial charactr that rprsnts th pathnam or th hom dirctory. It is usul whn an absolut pathnam or a il or diirctory is ndd. $ cp monday ~/today 2.ls Displays dirctory contnts
C d L s 3.ls -F To distinguish btwn il and dirctory nams, howvr, ls command is usd with th -F option. A slash is thn placd atr ach dirctory nam in th list. l s F 4.ls -R Th command lists working dirctory as wll as all subdirctoris. l s - R 5.cd Usd to mov through Dirctoris I I I D i r c t o r y O p r a t i o n s 1.ind Sarchs dirctoris or ils according to sarch critria. i n d d i r c t o r y - l i s t o p t i o n c r i t r i a. - n a m p a t t r n - l n a m p a t t r n - g r o u p n a m - g i d n a m group ID. Sarchs or ils with pattrn in th nam. Sarchs or symbolic link ils. Sarchs or ils blonging to th group nam. Sarchs or ils blonging to a group according to
- u s r n a m - u i d n a m usr ID. - s i z n u m c addd atr sarchd or. - m t i m n u m - p r i n t Sarchs or ils blonging to a usr. Sarchs or ils blonging to a usr according to Sarchs or ils with th siz num in blocks. I c is num, th siz in byts (charactrs) is Sarchs or ils last modiid num days ago. Outputs th rsult o th sarch to th standard output. Th rsult is usually a list o ilnams, including thir ull pathnams. - t y p i l t y p Sarchs or ils with th spciid il typ. Fil typ can b b or block dvic, c or charactr dvic, d or dirctory, or il, or l or symbolic link. - p r m p r m i s s i o n Sarchs or ils with crtain prmissions st. Us octal or symbolic ormat or prmissions. I V F i l o p r a t i o n s c p Copis a il. cp taks two argumnts: th original il and th ilnam ilnam nam o th nw copy. Th pathnams can b usd or th ils to copy across dirctoris: $ cp today rports/monday c p - r d i r n a m d i r n a m Copis a subdirctory rom on dirctory to anothr. Th copid dirctory includs all its own subdirctoris: $ cp -r lttrs/thankyou oldlttrs m v i l n a m i l n a m Movs (rnams) a il. Th mv command taks two argumnts: th irst is th il to b movd. Th scond argumnt can b th nw ilnam or th pathnam o a dirctory. I it is th nam o a dirctory, thn th il is litrally movd to that dirctory, changing th il s pathnam: $ mv today /hom/chris/rports m v d i r n a m d i r n a m Movs dirctoris. In this cas, th irst and last argumnts ar dirctoris: $ mv lttrs/thankyou oldlttrs
l n i l n a m i l n a m Crats addd nams or ils rrrd to as links. A link can b cratd in on dirctory that rrncs a il in anothr dirctory: $ ln today rports/monday r m i l n a m s Rmovs (rass) a il. Can tak any numbr o ilnams as its argumnts. Rmovs links to a il. I a il has mor than on link, you nd to rmov all o thm to ras a il: $rm today wathr wknd 3. Symbolic link To st up a symbolic link, th ln command is usd with th -s option and two argumnts: th nam o th original il and th nw, addd ilnam. Th ls opration lists both ilnams, but only on physical il will xist. l n - s o r i g i n a l - i l - n a m a d d d - i l - n a m 4. Hard link To st up a hard link, you us th ln command with no -s option and two argumnts: th nam o th original il and th nw, addd ilnam. Th ls opration lists both ilnams, but only on physical il will xist. l n o r i g i n a l - i l - n a m a d d d - i l - n a m