LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Want to list out using single command (https://www.linuxquestions.org/questions/linux-newbie-8/want-to-list-out-using-single-command-4175568800/)

Joy Stick 01-30-2016 07:45 AM

Want to list out using single command
 
Hi all;

Tried to diplay output just using 1 command.

PHP Code:

# raw -qa
/dev/raw/raw1:  bound to major 8minor 17
/dev/raw/raw2:  bound to major 8minor 33
/dev/raw/raw3:  bound to major 8minor 49
/dev/raw/raw4:  bound to major 8minor 65 

PHP Code:

# ls -l /dev/* | grep '8,  17'
brw-rw----  1 root disk     8,  17 Jan 30 16:16 /dev/sdb1
#  ls -l /dev/* | grep '8,  33'
brw-rw----  1 root disk     8,  33 Jan 30 16:16 /dev/sdc1 

I tried following options - but got error
PHP Code:

# ls -l /dev/* | grep '8,  17','8,  33'
# ls -l /dev/* | grep '8,  17'| grep '8,  33'
# ls -l /dev/* | grep '8,  17', grep '8,  33'
grepgrepNo such file or directory
grep
8,  33No such file or directory 

Thanks in advance

jpollard 01-30-2016 08:42 AM

grep takes a single pattern.... After that everything is treated as a file name.

Also note - what may be output by the ls could have tab characters (or multiple), It looks like the pattern you are using has spaces.

Also using a comma to separate two patterns doesn't work (it looks like you are searching for files with device numbers 8,17 or 8,33).

The second command you give the grep will not work, but you can try:
Code:

grep -e ' 8, *\(17\|\33\) '
This looks for the pattern <space>8,<0 or more spaces>17... or 33... followed by a space. The \ for the grouping and alternatives are required.

grail 01-30-2016 09:31 AM

Maybe it would be more useful if you told us what you are trying to do instead of showing us things which may or may not be what you are looking for?

Joy Stick 01-30-2016 02:47 PM

Hi

Using fdisk operation i have created some partitions.
Using raw utility i bound raw devices with block devices.

Ex : raw /dev/raw/raw1 /dev/sdb1

# raw -qa
/dev/raw/raw1: bound to major 8, minor 17
/dev/raw/raw2: bound to major 8, minor 33
/dev/raw/raw3: bound to major 8, minor 49
/dev/raw/raw4: bound to major 8, minor 65

Here my confusions

What indicates major/minor number for a device ?
I read linux treating each device as a file - Why so ?
Why linux treats /dev/raw/raw1 as a file instead of SCSI disk ?

Actually /dev/sdb1 is bound with /dev/raw/raw1 using raw utility.

Thanks

jpollard 01-30-2016 03:24 PM

Quote:

Originally Posted by Joy Stick (Post 5490451)
Hi

Using fdisk operation i have created some partitions.
Using raw utility i bound raw devices with block devices.

Ex : raw /dev/raw/raw1 /dev/sdb1

# raw -qa
/dev/raw/raw1: bound to major 8, minor 17
/dev/raw/raw2: bound to major 8, minor 33
/dev/raw/raw3: bound to major 8, minor 49
/dev/raw/raw4: bound to major 8, minor 65

Waste of time. Just use the block devices directly. You get identical performance.
Quote:

Here my confusions

What indicates major/minor number for a device ?
Nothing. Linux only provides them for some legacy operations. If you actually look you find that the device name is dynamically generated, but the major/minor numbers are not used. ORIGINALLY, the major number was the index in the driver tables that corresponded to pointers to the driver functions. The minor number was provided to the driver functions to identify which unit to use. Unfortunately (and a LONG time ago) these indexes became useless (too many different kinds of drivers, some with too many units).
Quote:

I read linux treating each device as a file - Why so ?
simplicity. All the file name entry does is identify which driver to use for various functions. Current linux design has the /dev directory as a pseudo filesystem - it doesn't really exist. The in memory data structures are being interpreted as a filesystem, and the device structure (a collection of pointers to the driver functions) are assigned to a name during the initial hardware scan. That is why the filesystem type is "devtmpfs". It isn't a real filesystem. As each driver initializes it registers itself to the kernel devtmpfs filesystem which records the appropriate entry.
Quote:

Why linux treats /dev/raw/raw1 as a file instead of SCSI disk ?
Everything is a file... There is no difference between /dev/raw/raw1 and using the /dev names.
Quote:


Actually /dev/sdb1 is bound with /dev/raw/raw1 using raw utility.
So what. Both names are linked to the same device driver. This was one of the reasons the raw interface was considered to be redundant and could be dropped.

If you actually look, the /dev/disk directory entries (by-id, by-label, by-partuuid, by-path, and by-uuid) just supply symbolic links the base /dev/<name> for the disk. I believe the /dev/raw entries are the same.

If you use the raw entries, you have additional restrictions - you have to use block aligned data transfers (and use page aligned memory buffers)... and that slows down and makes things more complicated for the application. Letting the kernel handling the buffers makes for a faster and more flexible operation by letting the page cache handle the I/O scheduling.
Quote:

Thanks
No problem.


All times are GMT -5. The time now is 02:48 PM.