LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-09-2012, 01:58 PM   #1
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Rep: Reputation: 1
Question What are the files found in /Dev ?


I am currently reading through the below document. I want to learn Linux from the ground level up, I want to know everything there is to know about linux that my mind is capable of comprehending (we'll see how far that gets me lol)

I just have a question regarding the files in the /dev directory. It says in this guy that the files ARE the hardware. For example it says I can use the cat command to send data to the speakers. I'm not sure I understand this concept. Are the files found here akin to device drivers, or config file for those devices? Or are they , for lack of better understanding on my part, linking files or pointers to the devices themselves? Could I go to this directory to actually access the files found on a hard drive or a disk drive? Or could I use the files found in this directory to write a program that sends data to these data drives ? (I'm sure there is probably a better way to do that I'm just trying to understand what exactly these files are) If I deleted a HDA file (which I believe are partitions on the master drive) Would it actually deletet he partition or would it only remove the ability for the kernel to commincate with that file system until that file is recreated VIA the propr MakeDEV script command or mknod command? Am I correct in saying this directory is akin to the registry found in windows computers, just much less complex?

Direct answers are welcome, as are links to other places on the internet that explain this in better detail. Also you oculd just tell me I'm an idiot and to stop posting here all answers are welcome ^_^

<edited to make the title better match the question>

http://tldp.org/LDP/Linux-Filesystem.../html/dev.html

Last edited by Valosar; 08-09-2012 at 02:51 PM. Reason: Title kind of vauge
 
Old 08-09-2012, 02:23 PM   #2
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,311
Blog Entries: 61

Rep: Reputation: Disabled
Have a glance at the entry here for /dev, and the rest:

http://tldp.org/LDP/Linux-Filesystem...tml/index.html
 
1 members found this post helpful.
Old 08-09-2012, 02:51 PM   #3
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
That's actually the file I'm reading through. I forgot to post a link to it in my origonal post (fixed now) Reading that is what gave rise to my question in the first place. Are these files drivers, or what?
 
Old 08-09-2012, 02:59 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
In Linux/Unix everything is accessed as a file, even the hardware. For example, if /dev/sda is your first harddisk you can copy the entire disk onto another (same size or larger) disk /dev/sdb with a single call to the dd command:
Code:
dd if=/dev/sda of=/dev/sdb
If you replace /dev/sdb in that command with a filename you are making an image file of that disk.
This is in fact the easiest way to make an image of a CD/DVD:
Code:
dd if=/dev/sr0 of=~/cd-image.iso
I don't know if this still works, but you can that also play uncompressed audio directly with cat:
Code:
cat audiofile>/dev/dsp
Or you use mplayer to directly display the output of your webcam:
Code:
mplayer tv://dev/video0
There are also some special devices, like /dev/null (which is usually used as dumping place for output of programs) or /dev/zero, which will deliver you an endless stream of zeroes.

So as you can see, the files in /dev are not the drivers or config files, but are used to directly access your hardware.

Last edited by TobiSGD; 08-09-2012 at 03:00 PM. Reason: fixed typo
 
Old 08-09-2012, 03:07 PM   #5
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
Thanks TobiSGD, so does that mean if I were to delete sda I would be deleting the entire partion with no normal way of recovering the data on it?

This is a very interesting concept thanks for the examples that has at the very least cleared up the usage of the files themselves

Could I use this to back up a parition say

dd if=/dev/sda of=/dev/backupsda

then later if I bork the partion I could do the reverse and restore the backup by sayin

dd if=/dev/backupsda of=/dev/sda replacing the borked SDA file with a copy of the backup?

Thanks for humoring me BTW I know this is pretty low level stuff. I'm hoping one day I can be the one answering questions for others.
 
Old 08-09-2012, 03:38 PM   #6
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by Valosar View Post
Thanks TobiSGD, so does that mean if I were to delete sda I would be deleting the entire partion with no normal way of recovering the data on it?

This is a very interesting concept thanks for the examples that has at the very least cleared up the usage of the files themselves

Could I use this to back up a parition say

dd if=/dev/sda of=/dev/backupsda

then later if I bork the partion I could do the reverse and restore the backup by sayin

dd if=/dev/backupsda of=/dev/sda replacing the borked SDA file with a copy of the backup?

Thanks for humoring me BTW I know this is pretty low level stuff. I'm hoping one day I can be the one answering questions for others.
actually, no
first of all, /dev/sda is the drive in it's entirety not an individual partiton, second of all you would not delete the CONTENTS of the drive, as the files in /dev do not work that way, they are merely an abstraction layer that provides an interface that allows programmers to use standard file i/o methods to communicate with hardware, that being said, removing /dev/sda would remove your ability to talk to that drive and chances are your linux install resides on /dev/sda so you would have to boot to a live cd and copy the file back to the borked installation from the live cd, but you wouldn't torch your data.
 
1 members found this post helpful.
Old 08-09-2012, 03:53 PM   #7
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
Okay so rming the file won't actually delete the data, but DDing it WILL copy the files? I'm guessing there is a way to format a hard drive using the file in dev but it would probably be easier to just use provided tools eh? No reason to reinvent the wheel. I think I understand now thank you guys a lot I could see where files in this folder could be very useful for scripts and small programs (Say printing out a log file by using cat to pipe the data directly to the printer then wiping the log file so it is blank, but you'll have a printed copy of whatever was in it waiting for you on the printer when you come home or whatever) Of course there are probably also better ways of printing files. . .
 
Old 08-09-2012, 03:56 PM   #8
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
yes you would format the drive using the files in /dev/, you run mkfs on say.. /dev/sda1 (sda being the first drive, 1 being the first partition on /dev/sda) and dd is reading/writing from the device(s), doing this you could say dd if=/dev/cdrom of=image.iso and make an exact image of a cd, same with a hard drive or hard drive partition
 
1 members found this post helpful.
Old 08-09-2012, 04:05 PM   #9
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
Would an image of a harddrive also be a .iso?

BTW your sig is very true !
 
Old 08-09-2012, 04:10 PM   #10
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
no it would be a .img (.iso refers to the iso9660 file system used on most cds)
as for my sig, which part?
 
1 members found this post helpful.
Old 08-09-2012, 04:16 PM   #11
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
Ah I see ! And if I used DD in the reverse order from .img directly to sda1 for exmaple I would be able to restore a partion to exactly the way it was when I first created the .img file?

The part about a PC With windows being a poorly tuned musical instrument, not the part about gnomes not being food because to be honest that's subjective :P I honestly don't understand the first part of your sig, which I guess is part of my problem ^_^ I know from reading that null is a place to dump unwanted output so I guess it could mean Microsoft should be dumped into the null void, but I don't get the gossip part.

0100011101101110011011110110110101100101011100110010000001101101011000010110101101100101001000000110 0111011100100110010101100001011101000010000001100110011011110110111101110100011000100110000101101100 011011000111001100100001

Last edited by Valosar; 08-09-2012 at 04:18 PM.
 
Old 08-09-2012, 04:21 PM   #12
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
hehe, the first part means ignore the usual output of microsoft, but when they make a mistake gossip about it (1> redirects standard out 2> redirects standard error)
and yes, you are correct about the being able to re-create a partition from the image, just don't try and write the image of the partition to the partition being copied, you might find you recursively copy the contents of the image file into the image file and quickly fill the partition.
 
1 members found this post helpful.
Old 08-09-2012, 04:26 PM   #13
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by Valosar View Post
but DDing it WILL copy the files?
Not really. dd will copy the entire content of the device or partition, it doesn't care if there are files on the partition or not. That means that making a copy of a 20GB partition to a file will always end with a file that has a size of 20GB (provided you don't use any of dd's options for partial copies), regardless if the files occupy 1GB, 10GB or 19GB on that partition.
 
1 members found this post helpful.
Old 08-09-2012, 04:29 PM   #14
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
tobysgd is correct, dd is what is refered to as a 'bit copier', it will copy the partion, bit for bit, including the empty space.
 
1 members found this post helpful.
Old 08-09-2012, 04:35 PM   #15
Valosar
Member
 
Registered: Aug 2012
Location: Kentucky, USA
Distribution: Mint 14 Mate, Knoppix , #!
Posts: 44

Original Poster
Rep: Reputation: 1
That makes sense, so I'm guessing there are better ways to create an img of a parition for back up purposes then. I'm sure I will get to all that ,I'm going to read all these guides work picks up or the ban the website (I can't imagine way they would do that but you never know) I'm hoping by the time I start my linux class next quarter I will be well ahead of the curve. Thanks for all the help guys it has really cleared up this issue for me.

now I'm reading about the /etc directory, and I thought /dev was hard to understand! :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pseudo terminals: /dev/ptmx <-> /dev/pts/ vs. /dev/ptyp <-> /dev/ttyp rtspitz Linux - Software 2 12-02-2011 03:07 PM
The /dev directory tuhin_chatt Linux - General 3 05-04-2010 10:45 AM
/dev directory Dave-Bowskill Programming 0 09-20-2004 12:52 AM
/dev directory nny0000 Slackware 3 02-03-2004 07:37 PM
/dev directory phishman3579 Slackware 3 12-02-2003 05:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration