s.m s.m - 5 months ago 8
Linux Question

Together cut and sort

I cant understand the code below.I know what it does sort ,but when it is alone i mean it hasnt after something,i have no idea nor i find something in any book not even in google.Can someone give a good explanation to this line because i cant understand it.What i know to help cut is read the entrance and give the result to exit. After it refers to direcory to a file line 1 until 6 and read the archive etc passwd.Translate the empty.Thanks a lot

cut -d: -f1,6 /etc/passwd | tr : ' ' | sort

Answer

cut remove sections from each line of files.

-d: use ':' instead of TAB for field delimiter.

-f1,6 select 1 and 6 fields.

/etc/password read file,with no file or when file is '-', read standard input.

cut -d: -f1,6 /etc/passwd output example:

root:/root
bin:/bin
daemon:/sbin
adm:/var/adm
lp:/var/spool/lpd
sync:/sbin
shutdown:/sbin
halt:/sbin
mail:/var/spool/mail
uucp:/var/spool/uucp
operator:/root
games:/usr/games
gopher:/var/gopher
ftp:/var/ftp
nobody:/
dbus:/
vcsa:/dev
abrt:/etc/abrt
haldaemon:/
ntp:/etc/ntp

| pipeline,a sequence of one or more commands separated by one of the control operators | or |&.

The standard output of command "cut -d: -f1,6 /etc/passwd" is connected via pipe to the standard input of command "tr -d : ' ' " .

tr translate or delete characters

Translation occurs if -d is not given and both SET1 and SET2 appear.(man tr)

so the output

root /root
bin /bin
daemon /sbin
adm /var/adm
lp /var/spool/lpd
sync /sbin
shutdown /sbin
halt /sbin
mail /var/spool/mail
uucp /var/spool/uucp
operator /root
games /usr/games
gopher /var/gopher
ftp /var/ftp
nobody /
dbus /
vcsa /dev
abrt /etc/abrt

The standard output of command "tr : ' '" is also connected via pipe to the standard input of command 'sort'

Comments